Skip to content

Commit

Permalink
Merge branch 'main' into omt-support
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Nov 30, 2022
2 parents 7c39286 + c1b6579 commit c1433a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 6 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ curl localhost:3000/points,lines/0/0/0

Function Source is a database function which can be used to query [vector tiles](https://github.com/mapbox/vector-tile-spec). When started, martin will look for the functions with a suitable signature. A function that takes `z integer` (or `zoom integer`), `x integer`, `y integer`, and an optional `query json` and returns `bytea`, can be used as a Function Source. Alternatively the function could return a record with a single `bytea` field, or a record with two fields of types `bytea` and `text`, where the `text` field is a etag key (i.e. md5 hash).

| Argument | Type | Description |
|----------------------------|---------|-------------------------|
| z (or zoom) | integer | Tile zoom parameter |
| x | integer | Tile x parameter |
| y | integer | Tile y parameter |
| query (optional, any name) | json | Query string parameters |
| Argument | Type | Description |
|-------------------------|---------|-------------------------|
| z (or zoom) | integer | Tile zoom parameter |
| x | integer | Tile x parameter |
| y | integer | Tile y parameter |
| `<any name>` (optional) | json | Query string parameters |

For example, if you have a table `table_source` in WGS84 (`4326` SRID), then you can use this function as a Function Source:

Expand All @@ -339,23 +339,6 @@ END
$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;
```

```sql, ignore
CREATE OR REPLACE FUNCTION function_zxy_query(z integer, x integer, y integer, query_params json) RETURNS bytea AS $$
DECLARE
mvt bytea;
BEGIN
SELECT INTO mvt ST_AsMVT(tile, 'function_zxy_query', 4096, 'geom') FROM (
SELECT
ST_AsMVTGeom(ST_Transform(ST_CurveToLine(geom), 3857), ST_TileEnvelope(z, x, y), 4096, 64, true) AS geom
FROM table_source
WHERE geom && ST_Transform(ST_TileEnvelope(z, x, y), 4326)
) as tile WHERE geom IS NOT NULL;
RETURN mvt;
END
$$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;
```

The `query_params` argument is a JSON representation of the tile request query params. For example, if user requested a tile with [urlencoded](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) params:

```shell
Expand Down

0 comments on commit c1433a5

Please sign in to comment.