Glossary: treetracker-tile-server
Generated by .github/scripts/build-glossary.mjs from domain-graph.json (source commit b619c05). Do not edit by hand.
This glossary lists the business terms of treetracker-tile-server. Each term links to its domain, which says what the domain does, its rules, and its flows. The estate glossary shows which other repos use the same terms.
Terms
- active_tree_region: Tree Query Selection
- Ambassador Mapping: Release and Deployment
- Base image greenstand/tile-server-base:first: Release and Deployment
- clusters: Tree Query Selection
- Config: Map Tile Serving, Tile Stylesheet Composition
- DB_URL: Tile Stylesheet Composition
- DigitalOcean cluster: Release and Deployment
- Docker image greenstand/treetracker-map-tile-server: Release and Deployment
- entity and entity_relationship: Tree Query Selection
- GeoJSON FeatureCollection: Tile Stylesheet Composition
- Icon set (o, ptk-b, ptk-s): Tile Stylesheet Composition
- Kubernetes Service and Deployment: Release and Deployment
- Kustomize base and overlays (development, test, production, beta): Release and Deployment
- Layer l1: Tile Stylesheet Composition
- Map (query planner): Tree Query Selection
- Mapnik XML templates (xml, xmlTree, xmlJson, xml2, xmlTree2, xmlTree3, xmlJson2, xmlJson3): Tile Stylesheet Composition
- mapnik.Grid: Map Tile Serving
- mapnik.Image: Map Tile Serving
- mapnik.Map: Map Tile Serving
- pg Pool: Map Tile Serving
- PGPool: Tile Stylesheet Composition
- planter: Tree Query Selection
- region: Tree Query Selection
- SealedSecret database-connection: Release and Deployment
- semantic-release version: Release and Deployment
- SQLCase1 and SQLCase1WithZoomTarget (active_tree_region counts): Tree Query Selection
- SQLCase2 and SQLCase2Wallet (tree points): Tree Query Selection
- SQLCase3 (ST_ClusterWithin): Tree Query Selection
- SQLCase4 (clusters table): Tree Query Selection
- Tile (z/x/y): Map Tile Serving
- Timeline builders (SQLCase1Timeline, SQLCase2Timeline, SQLCase3Timeline): Tree Query Selection
- trees: Tree Query Selection
- UTF grid fields (id, latlon, count, type, zoom_to): Map Tile Serving
- wallet.token and wallet.wallet: Tree Query Selection
Domains
Map Tile Serving
The Express service in greenstand/ answers slippy-map tile requests for the Treetracker web map. Each request gets a new 256x256 mapnik.Map that loads the per-tile Mapnik XML style and renders a PNG image or a UTF grid JSON for click and hover details. Every other path returns a version banner.
Terms: Tile (z/x/y), mapnik.Map, mapnik.Image, mapnik.Grid, UTF grid fields (id, latlon, count, type, zoom_to), pg Pool, Config
Rules:
- The server does not start unless MAXIMUM_ZOOM_LEVEL_USING_GLOBAL_DATASET and MAXIMUM_ZOOM_LEVEL_HANDLING_ZOOM_TARGET are defined.
- Each tile request builds its own 256x256 mapnik.Map; the native Map.render rejects a Map that another render already uses.
- The SQL bounds of a tile are the tile area plus a 100-pixel buffer, clipped to longitude +/-180 and latitude +/-85.0511.
- Grid tiles render only layer l1 at resolution 4 and add the zoom_to field only at zoom 9 and below.
- The query parameters userid, wallet, timeline, map_name, and icon go unchanged to the style builder.
- The /new routes add newIcons: true, but Config.getXMLString ignores it, so they return the same tiles as the root routes.
- A style or render error returns HTTP 500 with a JSON message.
Flows:
- Start Tile Server (
npm start (node --max-old-space-size=1024 greenstand/server.js)): npm start runs greenstand/server.js, which loads .env, loads app.js (pg Pool, Config, Mapnik fonts and plugins, CORS, and the static viewer), checks the two zoom thresholds, and listens on PORT. - Render PNG Map Tile (
GET /:z/:x/:y.png (also GET /new/:z/:x/:y.png)): A GET request for /:z/:x/:y.png builds a Mapnik map for the tile from the per-tile XML style, renders it with AGG into a 256x256 image, and returns the PNG bytes. The /new/:z/:x/:y.png route runs the same steps. - Render UTF Grid Tile (
GET /:z/:x/:y.grid.json (also GET /new/:z/:x/:y.grid.json)): A GET request for /:z/:x/:y.grid.json builds the same Mapnik map as the PNG route, renders layer l1 into a UTF grid of feature ids, and returns the grid, keys, and feature data as JSON, so that the web map can show tree and cluster details. The /new/:z/:x/:y.grid.json route runs the same steps. - Report Server Version (
ALL * (any path that no earlier handler answers)): Any request that the tile routes and the viewer do not answer, including GET /, gets HTTP 200 with a welcome text that contains the package.json version. Clients can use it to see which release runs.
Tile Stylesheet Composition
Config.getXMLString in greenstand/config.js turns each tile request into a complete Mapnik XML document. For zoom 1 to 15 it inlines the tree clusters as GeoJSON that it gets through the cached PGPool. For other zoom levels it fills a PostGIS layer template with the DB_URL credentials and the tile SQL, so that Mapnik queries the trees at render time.
Terms: Config, PGPool, Mapnik XML templates (xml, xmlTree, xmlJson, xml2, xmlTree2, xmlTree3, xmlJson2, xmlJson3), GeoJSON FeatureCollection, DB_URL, Layer l1, Icon set (o, ptk-b, ptk-s)
Rules:
- Zoom levels 1 to 15 use an inline GeoJSON datasource; other zoom levels use a PostGIS datasource.
- The tile SQL gets bounds never above zoom 15, always for map_name maps, never for wallet or userid maps, and otherwise only above MAXIMUM_ZOOM_LEVEL_USING_GLOBAL_DATASET.
- The icon parameter picks the template: ptk-b gives the green icons, ptk-s gives the small green icons (GeoJSON clusters and PostGIS trees only), and o or no value gives the orange icons.
- An empty query result becomes one placeholder cluster feature at [85,0] with id 99999.
- An inline GeoJSON style larger than 5 MB fails with 'The data is too big'.
- PGPool caches the finished XML by SQL text only, in an LRU cache of CACHE_SIZE entries that expire after CACHE_EXPIRE milliseconds (defaults 10000 entries and 4 minutes).
- DB_URL must have the form postgresql://user:password@host:port/database.
Flows:
- Compose GeoJSON Cluster Style (
Config.getXMLString({zoomLevel, bounds, userid, wallet, timeline, map_name, icon}), called by buildMapInstance for zoom 1 to 15): For zoom 1 to 15, getXMLString gets the tile SQL, runs it through the cached PGPool, converts the rows to an inline GeoJSON FeatureCollection, and puts it into the cluster template of the chosen icon set. - Compose PostGIS Tree Style (
Config.getXMLString, called by buildMapInstance for zoom levels outside 1 to 15): For zoom levels outside 1 to 15 (single trees above zoom 15), getXMLString fills a PostGIS layer template with the database credentials from DB_URL and the tile SQL. Mapnik then runs the query through its PostGIS input plugin at render time. - Cache And Coalesce Tile Queries (
PGPool.getQuery(sql, handleResult), called by Config.getXMLString in GeoJSON mode): PGPool puts an LRU cache in front of the pg Pool. Concurrent requests with the same SQL share one database query, and PGPool caches the post-processed result (the finished Mapnik XML) by SQL text.
Tree Query Selection
The Map class in greenstand/Map.js selects one SQL builder from greenstand/sqls for each tile by map mode and zoom band. The builders write PostGIS SQL that returns region clusters, clusters made on the fly with ST_ClusterWithin, precomputed clusters, or single tree points. Each row has the type, id, latlon, count, and zoom_to values that the styles and UTF grids use, and the cluster rows also have a count_text label.
Terms: Map (query planner), SQLCase1 and SQLCase1WithZoomTarget (active_tree_region counts), SQLCase2 and SQLCase2Wallet (tree points), SQLCase3 (ST_ClusterWithin), SQLCase4 (clusters table), Timeline builders (SQLCase1Timeline, SQLCase2Timeline, SQLCase3Timeline), trees, active_tree_region, region, clusters, planter, entity and entity_relationship, wallet.token and wallet.wallet
Rules:
- The map mode follows this order: userid, then wallet, then map_name, then timeline, then the default map.
- Config.getXMLString does not pass treeid, flavor, or token to Map.init, so the single tree mode and the flavor and token filters do not run from the tile routes.
- Above zoom 15 every mode returns single active tree points.
- From zoom 12 to 15 the default map reads precomputed clusters at zoom_level 14, and organization maps (except freetown and ffcphase1) and timeline maps cluster trees with ST_ClusterWithin.
- Planter and wallet maps count the trees first: more than 2000 gives region clusters, and 2000 or fewer gives ST_ClusterWithin clusters.
- A region cluster gets a zoom_to centroid only at zoom levels up to MAXIMUM_ZOOM_LEVEL_HANDLING_ZOOM_TARGET; the centroid is the most populated subregion two zoom levels deeper.
- An organization map includes the trees of planters in up to 20 organizations of the entity_relationship hierarchy and the trees whose planting organization has that map_name.
- The point and on-the-fly cluster queries read only active trees, the region counts read active_tree_region, and SQLCase4 reads the precomputed clusters table. Counts above 1000 show as thousands with a K suffix.
- The builders put the filter values into the SQL text directly; they do not use bound parameters.
Flows:
- Select Default Map Query (
Map.init with no userid, wallet, map_name, or timeline (plain tile request)): Without userid, wallet, map_name, or timeline, Map.init picks the query by zoom: tree points above zoom 15, precomputed clusters from zoom 12 to 15, and region clusters with zoom targets below zoom 12. - Select Planter Map Query (
Map.init with userid (tile query parameter userid)): For a userid map, Map.init counts the trees of that planter first and then picks tree points, region clusters, or on-the-fly clusters by zoom and tree count. Planter maps always use the global dataset, without bounds. - Select Wallet Map Query (
Map.init with wallet (tile query parameter wallet)): For a wallet map, Map.init counts the tokens of the named wallet first and then picks wallet tree points, region clusters, or on-the-fly clusters. Wallet maps always use the global dataset, without bounds. - Select Organization Map Query (
Map.init with map_name (tile query parameter map_name)): For a map_name (organization) map, Map.init picks tree points, on-the-fly clusters, or region clusters by zoom, and every builder limits the trees to the organization hierarchy. Up to zoom 15, organization maps always use the tile bounds. - Select Timeline Map Query (
Map.init with timeline (tile query parameter timeline)): For a timeline map, Map.init picks a timeline builder by zoom. Each builder keeps only the trees whose time_created is between the two dates of a 'YYYY-MM-DD_YYYY-MM-DD' value.
Release and Deployment
GitHub Actions workflows, the Dockerfile, and the kustomize manifests in deployment/ release and run the tile server. A push to master or next cuts a semantic-release version, pushes the greenstand/treetracker-map-tile-server image to DockerHub, and applies the development overlay. Manual workflows deploy a chosen git tag to test or production on DigitalOcean Kubernetes, where an Ambassador Mapping exposes the server under /tiles/.
Terms: semantic-release version, Docker image greenstand/treetracker-map-tile-server, Base image greenstand/tile-server-base:first, Kustomize base and overlays (development, test, production, beta), SealedSecret database-connection, Ambassador Mapping, Kubernetes Service and Deployment, DigitalOcean cluster
Rules:
- Only pushes to master (release) or next (prerelease) of Greenstand/treetracker-tile-server, without 'skip-ci' in the head commit message, release and deploy.
- The image tag is the package.json version.
- A push deploys only to development; test and production get a chosen git tag through a manual workflow_dispatch.
- DB_URL comes only from the database-connection SealedSecret, and each overlay supplies its own encrypted value.
- The base runs 1 replica; the test overlay runs 6 replicas and uses the global dataset up to zoom 8; production runs 2 replicas with a 768Mi memory request, a 1536Mi memory limit, no CPU limit, and the global dataset up to zoom 15.
- The gateway allows 60000 ms per request in the base and has no timeout in production.
- The image build needs mapnik-config from the base image, because make release_base compiles the binding against the installed Mapnik.
- The beta overlay (namespace tile-server-beta, prefix /tiles-next/) exists, but no workflow applies it.
Flows:
- Release And Deploy To Development (
push to master or next (.github/workflows/build-deploy.yml)): On a push to master or next, build-deploy.yml cuts a semantic-release version, builds the Docker image, pushes it to DockerHub with the package.json version as the tag, and applies the development overlay to the DigitalOcean cluster. - Deploy Tag To Test (
workflow_dispatch with input git-tag (.github/workflows/deploy-test.yml)): A manual run of deploy-test.yml checks out a chosen git tag and applies the test overlay with the package.json version of that tag as the image tag. The workflow does not build an image, so the image for that version must already be in DockerHub. - Promote Tag To Production (
workflow_dispatch with input git-tag (.github/workflows/deploy-prod.yml)): A manual run of deploy-prod.yml checks out a chosen git tag and applies the production overlay to the production cluster with the package.json version of that tag as the image tag. - Redeploy Tag To Development (
workflow_dispatch with input git-tag (.github/workflows/deploy-dev.yml)): A manual run of deploy-dev.yml applies the development overlay again for a chosen git tag. deploy-dev-next.yml is a similar workflow for the tile-server-next namespace, but the deployment-next/ directory that it uses is not in the repo. - Route Gateway Tile Traffic (
HTTP request to /tiles/{z}/{x}/{y}.png or /tiles/{z}/{x}/{y}.grid.json on the cluster gateway): In the cluster, the Ambassador Mapping sends requests under /tiles/ to the treetracker-tile-server Service, which forwards them to the Express server on container port 3000.