Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PostgreSQL 表源

表源是可用于查询矢量瓦片的数据库表。如果提供了 PostgreSQL 连接字符串,Martin 将发布所有至少有一个几何列的表作为数据源。如果几何列的 SRID 为 0,则必须设置默认 SRID,否则该几何列/表将被忽略。所有非几何表列将作为矢量瓦片要素标签(属性)发布。

修改 TileJSON

Martin 将自动为每个表源生成 TileJSON 清单。它将包含 name、description、minzoom、maxzoom、bounds 和 vector_layer 信息。 例如,如果有一个表 public.table_source: 默认的 TileJSON 可能如下所示(注意 URL 将自动调整以匹配请求主机):

表:

CREATE TABLE "public"."table_source" ( "gid" int4 NOT NULL, "geom" "public"."geometry" );

TileJSON:

{
    "tilejson": "3.0.0",
    "tiles": [
        "http://localhost:3000/table_source/{z}/{x}/{y}"
    ],
    "vector_layers": [
        {
            "id": "table_source",
            "fields": {
                "gid": "int4"
            }
        }
    ],
    "bounds": [
        -2.0,
        -1.0,
        142.84131509869133,
        45.0
    ],
    "description": "public.table_source.geom",
    "name": "table_source"
}

默认情况下,description 和 name 是关于此表的数据库标识符,边界从数据库查询。您可以通过调整配置文件中的 auto_publish 部分来微调这些。

SQL 注释中的 TileJSON

除了在配置文件中调整 auto_publish 部分外,您还可以直接在数据库端微调 TileJSON:在表上添加有效的 JSON 作为 SQL 注释。

Martin 将使用 JSON 合并补丁将表注释合并到生成的 TileJSON 中。以下示例更新描述并向 TileJSON 添加 attribution、version、foo(甚至嵌套的 DIY 字段)字段。

DO $do$ BEGIN
    EXECUTE 'COMMENT ON TABLE table_source IS $tj$' || $$
    {
        "version": "1.2.3",
        "attribution": "osm",
        "description": "a description from table comment",
        "foo": {"bar": "foo"}
    }
    $$::json || '$tj$';
END $do$;