Skip to content

GeoJSONVectorTileLayer

GeoJSONVectorTileLayer is a vector tile layer for rendering GeoJSON data on the map.

The layer is based on the open-source geojson-vt library. It slices the GeoJSON data into tiles in a worker in real time and returns the result to the main thread for rendering.

Advantages of loading GeoJSON data with the vector tile mechanism:

  • High performance: easily parses and renders GeoJSON files of hundreds of megabytes
  • Good experience: all data processing runs in the worker and does not block the main thread

It is a subclass of VectorTileLayer and inherits the methods and options of VectorTileLayer.

Likewise, styles written for VectorTileLayer can be applied to GeoJSONVectorTileLayer without modification, unifying server-side vector tile data and local GeoJSON data.

NOTE

A * on a parameter or option name means the parameter or option is required. For example, the * after id below means the parameter id is required:

  • id* String the layer id

Style

Vector tiles support styles for vector features (points, lines and polygons), and also have the ability to build lines and polygons into 3D lines and 3D faces and render them with 3D PBR materials.

Vector tiles integrate feature-filter and function-type to support data filtering and dynamic styling, making it easy to categorize the data in vector tiles and render them with different styles, levels and material magic for stunning effects.

Vector tiles are therefore well suited to categorized data rendering in large scenes, such as city building clusters. Compared with static data like 3dtiles, vector tiles benefit from a better ecosystem and the separation of style and data, which eliminates data update costs while providing styling capabilities that are hard to achieve with 3dtiles.

The vector tile style adopts a plugin-based design: styles are defined by render plugins. For the details of the render plugins, refer to the style manual. Here is a simple style example:

Style Example
json
{
  "style": [
    {
      "renderPlugin": {
        "type": "fill",
        "dataConfig": {
          "type": "fill",
          "only2D": true
        },
        "sceneConfig": {
          "depthFunc": "always",
          "blendSrc": "one"
        }
      },
      "symbol": {
        "visible": true,
        "polygonFill": "rgba(0,0,0,1)",
        "polygonOpacity": 1
      },
      "filter": {
        "title": "desert",
        "value": [
          "all",
          [
            "==",
            "$layer",
            "desert"
          ],
          [
            "==",
            "$type",
            "Polygon"
          ]
        ]
      }
    },
    {
      "renderPlugin": {
        "type": "line",
        "dataConfig": {
          "type": "line",
          "only2D": true
        },
        "sceneConfig": {
          "blendSrc": "one"
        }
      },
      "symbol": {
        "visible": true,
        "lineOpacity": 1,
        "lineWidth": 1,
        "lineColor": "rgba(0,0,0,1)",
        "lineJoin": "miter",
        "lineCap": "butt",
        "lineDx": 0,
        "lineDy": 0,
        "lineDasharray": [
          0,
          0,
          0,
          0
        ],
        "lineDashColor": "rgba(0,0,0,1)",
        "lineStrokeWidth": 0,
        "lineStrokeColor": "rgba(0,0,0,1)"
      },
      "detail": {
        "layer": "desert-outline",
        "enable": {
          "lineWidth": false,
          "lineColor": false,
          "lineStrokeWidth": false,
          "lineStrokeColor": false
        }
      },
      "filter": {
        "title": "desert-outline",
        "value": [
          "all",
          [
            "==",
            "$layer",
            "desert"
          ],
          [
            "==",
            "$type",
            "Polygon"
          ]
        ]
      }
    }
  ]
}

Constructor

js
import { GeoJSONVectorTileLayer } from '@maptalks/gl-layers';

new GeoJSONVectorTileLayer('geojson0', {
  data: 'path/to/example.geojson'
});
Details

Parameters:

  • id* String the layer id
  • options* Object options, the available options are as follows:
OptionTypeDescriptionDefault
data*Object/StringA GeoJSON data object or a URLnull
featuresBooleanWhether tiles return feature data; for a GeoJSON layer, only the feature id is returnedtrue
tileBufferNumberThe tile buffer size64
extentNumberThe tile coordinate extent (the encoding precision of geometries)8192
simplifyToleranceNumberThe tile simplification tolerance (a larger value means more simplification)3
generateOMBBBooleanWhether to generate the oriented minimum bounding box (OMBB, to speed up picking)true
convertFnStringThe data conversion function string (executed as convert(data) in the worker)null
fetchOptionsObjectfetch optionsnull
styleObjectThe style object of the layernull
subdomainsString[]subdomains, used to replace {s} in the URL templatenull
tileSizeNumber[]The tile width and height, in pixels[512, 512]
offsetNumber[]/FunctionThe tile offset in pixels. A two-element array or a function; the function takes zoom (the tile zoom level) as its argument, offset(zoom) {}[0, 0]
featuresBooleanWhether tiles return feature datatrue
schemaBooleanWhether tiles return the attribute schema of the datafalse
collisionBooleanWhether to enable collision detection for points and texttrue
pickingBooleanWhether the layer is allowed to query data with the identify or identifyAtPoint methodstrue
pickingPointBooleanWhether the query results of identify or identifyAtPoint include the 3D spatial coordinates of the query pointtrue
pickingGeometryBooleanWhether the query results of identify or identifyAtPoint include Geometryfalse
iconErrorUrlStringThe fallback image URL for failed icon requestsnull
collisionFrameLimitNumberThe time limit for collision computation per frame, in ms1.5
defaultRenderingBooleanWhether to enable default style rendering when there is no styletrue
textGammaNumberThe gamma value of text, which can be used to adjust text sharpness1
maxIconSizeNumberThe maximum icon size limit254
styleScaleNumberThe overall scale factor of the layer's icons and text1
spatialReferenceString / ObjectThe spatial reference of the layer"preset-vt-3857"
tileSystemNumber[]A four-element array describing the TileSystem. The TileSystem defines the origin coordinate of tiles and the numbering rule on the X/Y axes. See this link for detailsnull
maxAvailableZoomNumberThe maximum available zoom level. When the map zoom level exceeds maxAvailableZoom, tiles of the maxAvailableZoom level are displayed.null
repeatWorldBooleanWhether to repeat the world when the whole world does not fill the screen at low zoom levelstrue
crossOriginStringThe cross origin setting of the tile datanull
debugBooleanWhether to enable debug info; when enabled, tile indices and extents are drawn on the mapfalse
maxCacheSizeNumberThe maximum number of cached tiles256
zoomOffsetNumberThe offset between the tile zoom level and the map zoom level0
errorUrlStringThe fallback URL for failed tile requestsnull
tokenStringUsed to replace {token} in the URL template, e.g. http://foo/bar/{z}/{x}/{y}?token={token}null

|attribution | String | The attribution of the layer | null | |minZoom | Number | The minimum zoom level at which the layer is displayed | null | |maxZoom | Number | The maximum zoom level at which the layer is displayed | null | |visible | Boolean | Whether the layer is visible | true | |opacity | Number | The opacity of the layer | 1 | |hitDetect | Boolean | Whether to enable layer drawing detection (dynamic mouse cursor styles); disabling it can improve performance | true | |collisionScope | String | The scope of the collision detection index: "map" or "layer" | "layer" |

Methods

getData()

Gets the GeoJSON data.

js
const layer = new GeoJSONVectorTileLayer('vt0', {
  data: 'path/to/example.geojson'
});
const data = layer.getData();

Returns:

  • String | Object
setData(data)

Updates the layer data.

js
const layer = new GeoJSONVectorTileLayer('vt0', {
  data: 'path/to/example.geojson'
});
layer.setData('path/to/another.geojson');

Parameters:

  • data String | Object GeoJSON data or a remote URL of the data.

Returns:

  • this
getExtent()

Gets the extent of the GeoJSON data.

js
const layer = new GeoJSONVectorTileLayer('vt0', {
  data: 'path/to/example.geojson'
});
const extent = layer.getExtent();

Returns:

  • maptalks.Extent
getFeature(id)

Gets the feature with the given id.

js
const layer = new GeoJSONVectorTileLayer('vt0', {
  data: 'path/to/example.geojson'
});
const feature = layer.getFeature(id);

Returns:

  • Object
getGeometryById(id)

Gets the feature by id (an alias of getFeature).

js
const layer = new GeoJSONVectorTileLayer('vt0', {
  data: 'path/to/example.geojson'
});
const feature = layer.getGeometryById(id);

Parameters:

  • id Number | String the feature id

Returns:

  • Object

Methods Inherited from VectorTileLayer

setStyle(layerStyle)

Sets the style of the layer. See this link for the style documentation.

js
const style = {
  style: [
    {
      filter : true,            // 数据的过滤条件
      renderPlugin: {           // 渲染插件
        type : 'native-point',
        dataConfig : {
          type : 'native-point'
        }
      },
      symbol: {                 // 样式定义
        markerSize: 6,
        markerType: 'circle',
        markerFill: '#0f0'
      }
    }
  ]
};
layer.setStyle(style);

Parameters:

  • style Object the layer style object, with the following optional properties:
PropertyTypeDescriptionDefault
styleObject[]The render plugin array[]
featureStyleObject[]The render plugin list of a single feature[]
$rootStringThe root path of the resource directorynull

Returns:

  • this
getStyle()

Gets the layer style.

Returns:

  • Object
getComputedStyle()

Gets the processed layer style. The main differences from style are:

  • If $root is defined in the style, all resource paths in computedStyle are the merged paths
  • The style definitions in style may be compressed, while those in computedStyle are uncompressed

Returns:

  • Object
outlineAll()

Highlights all data on the layer.

Because highlighting is implemented with post-processing, the layer must be added to a GroupGLLayer with the outline post-processing enabled.

js
layer.addTo(groupGLLayer);
layer.outlineAll();

Returns:

  • this
outlineBatch(idx)

Highlights the data rendered by the render plugin with index idx in the style.

Same as outlineAll: the layer must be added to a GroupGLLayer with the outline post-processing enabled.

js
layer.addTo(groupGLLayer);
layer.outlineBatch(0);

Parameters:

  • idx Number the index in the style

Returns:

  • this
outline(idx, featureIds)

Highlights the specified features among the data rendered by the render plugin with index idx.

js
layer.addTo(groupGLLayer);
layer.outline(0, [0]);

Parameters:

  • idx Number the index in the style
  • featureIds Number[] | String[] an array of feature ids

Returns:

  • this
cancelOutline()

Cancels the highlight.

Returns:

  • this
updateSymbol(idx, symbol)

Updates the symbol of the render plugin with index idx.

js
layer.updateSymbol(0, { polygonFill: '#0f0' });

Parameters:

  • idx Number the render plugin index
  • symbol Object the symbol properties to update

Returns:

  • this
updateFeatureSymbol(idx, styleIdx, symbol)

Updates the symbol of the render plugin with index styleIdx in the feature style with index idx.

js
const style = {
  featureStyle: [
    {
      id: 16,
      style: [
        {
          renderPlugin: {
            dataConfig: {
              type: 'fill'
            },
            sceneConfig: {
              antialias: false
            },
            type: 'fill'
          },
          symbol: {
            polygonFill: '#f00'
          }
        }
      ]
    }
  ]
}
layer.updateFeatureSymbol(0, 0, { polygonFill: '#0f0' });

Parameters:

  • idx Number the index of the feature style in featureStyle
  • styleIdx Number the style index
  • symbol Object the symbol properties to update

Returns:

  • this
updateSceneConfig(idx, sceneConfig)

Updates the sceneConfig of the render plugin with index idx.

js
layer.updateSceneConfig(0, { collision: false });

Parameters:

  • idx Number the render plugin index
  • sceneConfig Object the sceneConfig properties to update

Returns:

  • this
updateFeatureSceneConfig(idx, styleIdx, sceneConfig)

Updates the sceneConfig of the render plugin with index styleIdx in the feature style with index idx.

js
const style = {
  featureStyle: [
    {
      id: 16,
      style: [
        {
          renderPlugin: {
            dataConfig: {
              type: 'fill'
            },
            sceneConfig: {
              antialias: false
            },
            type: 'fill'
          },
          symbol: {
            polygonFill: '#f00'
          }
        }
      ]
    }
  ]
}
layer.updateFeatureSceneConfig(0, 0, { antialias: true });

Parameters:

  • idx Number the index of the feature style in featureStyle
  • styleIdx Number the render plugin index
  • sceneConfig Object the sceneConfig properties to update

Returns:

  • this
updateDataConfig(idx, dataConfig)

Updates the dataConfig of the render plugin with index idx.

js
layer.updateDataConfig(0, { altitudeProperty: 'height' });

Parameters:

  • idx Number the render plugin index
  • dataConfig Object the dataConfig properties to update

Returns:

  • this
updateFeatureDataConfig(idx, styleIdx, dataConfig)

Updates the dataConfig of the render plugin with index styleIdx in the feature style with index idx.

js
const style = {
  featureStyle: [
    {
      id: 16,
      style: [
        {
          renderPlugin: {
            dataConfig: {
              type: 'fill'
            },
            sceneConfig: {
              antialias: false
            },
            type: 'fill'
          },
          symbol: {
            polygonFill: '#f00'
          }
        }
      ]
    }
  ]
}
layer.updateFeatureDataConfig(0, 0, { foo: 1 });

Parameters:

  • idx Number the index of the feature style in featureStyle
  • styleIdx Number the render plugin index
  • dataConfig Object the dataConfig properties to update

Returns:

  • this
identify(coordinates, options)

Queries data at the given coordinate on the layer. Note that only rendered data can be queried.

js
layer.identify([121.23, 39.34], { tolerance: 2 })

Parameters:

  • coordinates Number[] the coordinate value
  • options Object options, the possible properties are: | Property | Type | Description | Default | | ------ | :----: | ---- | :-----------: | | tolerance | Number | The pixel tolerance for the query | 3 |

Returns:

  • Object[]
identifyAtPoint(containerPoint, options)

Queries data at the given container point on the layer.

js
layer.identifyAtPoint([400, 300], { tolerance: 2 })

Parameters:

  • coordinates Number[] the coordinate value
  • options Object options, the possible properties are:
PropertyTypeDescriptionDefault
toleranceNumberThe pixel tolerance for the query3

Returns:

  • Object[]
getDataSchema(zoom)

Gets the layer definition and property definition at the given zoom level.

Note that the schema of a zoom level can only be fetched after tiles of that level have been loaded; the data schema of a zoom level whose tiles have never been loaded cannot be fetched.

js
const schema = layer.getDataSchema(8);

Parameters:

  • zoom Number the tile zoom level

Returns:

  • Object[]

Methods Inherited from TileLayer

See the API documentation of the parent class TileLayer for details.

getTileSize()

Gets the tile width and height.

Returns:

  • Size
getTiles()

Gets the tiles.

Returns:

  • Object
getTileUrl(x, y, z)

Gets the tile URL.

Returns:

  • String
clear()

Clears the layer.

toJSON()

Gets the JSON object of the layer, which can be restored to a layer object with the maptalks.Layer.fromJSON(json) method.

Returns:

  • Object
getSpatialReference()

Gets the spatial reference of the layer.

Returns:

  • SpatialReference

Methods Inherited from Layer

See the API documentation of the parent class Layer for details.

getId()

Gets the layer id.

Returns:

  • Number | String
setId(id)

Sets the layer id.

Returns:

  • this
addTo(map)

Adds the layer to the map.

Returns:

  • this
getMinZoom()

Gets the minimum zoom level.

Returns:

  • Number
getMaxZoom()

Gets the maximum zoom level.

Returns:

  • Number
getMap()

Gets the map object that the layer is added to.

Returns:

  • Map
getProjection()

Gets the projection of the layer.

Returns:

  • Projection
show()

Shows the layer.

Returns:

  • this
hide()

Hides the layer.

Returns:

  • this
isVisible()

Checks whether the layer is visible.

Returns:

  • Boolean
remove()

Removes the layer.

Returns:

  • this
on(events, handler, context)

Registers an event listener on the layer.

Returns:

  • this
addEventListener(events, handler, context)

Same as the on method.

Returns:

  • this
once(events, handler, context)

Registers a one-time event listener on the layer; it is removed after being fired.

Returns:

  • this
off(events, handler, context)

Removes the registered event listener from the layer.

Returns:

  • this
removeEventListener(events, handler, context)

Same as the off method.

Returns:

  • this
listens(events, handler, context)

Checks whether the layer is listening to the given events.

Returns:

  • Boolean
fire(event, params)

Manually fires an event; params is the event parameter.

Returns:

  • this
setOptions(options)

Sets the layer options.

Returns:

  • this
config(key, value)

Updates a layer option.

Returns:

  • this

Static Methods

compressStyleJSON(style)

Compresses the style JSON into a smaller JSON object by merging render plugins with identical definitions.

js
const compressedStyle = GeoJSONVectorTileLayer.compressStyleJSON(style);

Parameters:

  • style Object the style object

Returns:

  • Object
registerPlugin(Plugin)

Registers a new render plugin.

js
GeoJSONVectorTileLayer.registerPlugin(PluginClazz);

Parameters:

  • PluginClazz PainterPlugin the render plugin class to register
getPlugins()

Gets all registered render plugins.

js
const pluginClasses = GeoJSONVectorTileLayer.getPlugins();

Returns:

  • PainterPlugin[]
fromJSON(json)

Creates a GeoJSONVectorTileLayer object from the layer's JSON object.

js
const json = layer.toJSON();

const layerCopied = maptalks.Layer.fromJSON(json);

Returns:

  • GeoJSONVectorTileLayer

Events

Example code for listening to layer events:

js
// 监听workerready事件
layer.once('workerready', e => {
  // e为事件参数
  console.log('worker is ready');
});

// 监听tileload事件
layer.on('tileload', e => {
  // e为事件参数
  console.log('loaded a tile', e.tile);
});

Layer Events

dataload

Fired when data is loaded successfully.

Properties:

PropertyTypeValue
typeString"dataload"
targetGeoJSONVectorTileLayerthis
extentNumber[]the extent range of the data
dataerror

Fired when a data loading error occurs.

Properties:

PropertyTypeValue
typeString"dataerror"
targetGeoJSONVectorTileLayerthis
errorStringthe error message

Events Inherited from VectorTileLayer

iblupdated

Fired when the ambient light is updated.

Properties:

PropertyTypeValue
typeString"iblupdated"
targetVectorTileLayerthis
canvasisdirty

Fired when the layer canvas is redrawn.

Properties:

PropertyTypeValue
typeString"canvasisdirty"
targetVectorTileLayerthis
workerready

Fired when the worker is ready.

Properties:

PropertyTypeValue
typeString"workerready"
targetVectorTileLayerthis
datareceived

Fired when tile data is received.

Properties:

PropertyTypeValue
typeString"datareceived"
targetVectorTileLayerthis
urlStringthe URL of the tile data
pluginsinited

Fired when the render plugins finish initialization.

Properties:

PropertyTypeValue
typeString"pluginsinited"
targetVectorTileLayerthis
setstyle

Fired when the style is set.

Properties:

PropertyTypeValue
typeString"setstyle"
targetVectorTileLayerthis
styleObject[]the style object
computedStyleObject[]the processed style object
updatesceneconfig

Fired on updatesceneconfig.

Properties:

PropertyTypeValue
typeString"updatesceneconfig"
targetVectorTileLayerthis
indexNumberthe style index
sceneConfigObjectthe sceneConfig object
updatefeaturesceneconfig

Fired on updatefeaturesceneconfig.

Properties:

PropertyTypeValue
typeString"updatefeaturesceneconfig"
targetVectorTileLayerthis
indexNumberthe feature style index
styleIdxNumberthe feature render plugin index
sceneConfigObjectthe sceneConfig object
updatedataconfig

Fired on updatedataconfig.

Properties:

PropertyTypeValue
typeString"updatedataconfig"
targetVectorTileLayerthis
indexNumberthe style index
dataConfigObjectthe dataConfig object
updatefeaturedataconfig

Fired on updatefeaturedataconfig.

Properties:

PropertyTypeValue
typeString"updatefeaturedataconfig"
targetVectorTileLayerthis
indexNumberthe feature style index
styleIdxNumberthe feature render plugin index
dataConfigObjectthe dataConfig object
updatesymbol

Fired on updatesymbol.

Properties:

PropertyTypeValue
typeString"updatesymbol"
targetVectorTileLayerthis
indexNumberthe style index
symbolObjectthe symbol object
updatefeaturesymbol

Fired on updatefeaturesymbol.

Properties:

PropertyTypeValue
typeString"updatefeaturesymbol"
targetVectorTileLayerthis
indexNumberthe feature style index
featureStyleIndexNumberthe feature render plugin index
symbolObjectthe symbol object

Events Inherited from TileLayer

tileload

Fired when a tile is loaded.

Properties:

PropertyTypeValue
typeString"tileload"
targetVectorTileLayerthis
tileObjectthe tile object
tileImageObjectthe tile image data
tileerror

Fired when a tile fails to load.

Properties:

PropertyTypeValue
typeString"tileerror"
targetVectorTileLayerthis
errorStringthe error message
tileObjectthe tile object

Events Inherited from Layer

clear

Fired when the layer is cleared.

Properties:

PropertyTypeValue
typeString"clear"
targetVectorTileLayerthis
idchange

Fired when the layer id changes.

Properties:

PropertyTypeValue
typeString"idchange"
targetVectorTileLayerthis
oldStringthe old id
newStringthe new id
renderercreate

Fired when the renderer is created.

Properties:

PropertyTypeValue
typeString"renderercreate"
targetVectorTileLayerthis
rendererVectorTileLayerRenderer
canvascreate

Fired when the canvas is created.

Properties:

PropertyTypeValue
typeString"canvascreate"
targetVectorTileLayerthis
glWebGLRenderingContext2D
renderstart

Fired when rendering starts.

Properties:

PropertyTypeValue
typeString"renderstart"
targetVectorTileLayerthis
renderend

Fired when rendering ends.

Properties:

PropertyTypeValue
typeString"renderend"
targetVectorTileLayerthis

This document has been cross-checked against the @maptalks/gl-layers 2026 source code (api-notes-vt-gl.md)