Search

GeoJSON Layer

The GeoJSON layer allows you to draw geometric objects over the map using the GeoJSON data format.

These geometric objects, such as polygons, can be used to:

  • Highlight areas of the map.
  • Geofence the nodes defined in the network layer to an area of the map.
  • Filter the trajectories defined in the observations layer to an area of the map.

Data Format

An example of a GeoJsonLayerData object is:

const vancouverDowntown = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      id: 'vancouver-downtown',
      geometry: {
        type: 'Polygon',
        coordinates: [
          [
            [-123.112266, 49.290164],
            [-123.10424, 49.288166],
            [-123.099288, 49.289272],
            [-123.099998, 49.27275],
            [-123.101699, 49.272972],
            [-123.111076, 49.272926],
            [-123.114448, 49.271774],
            [-123.121162, 49.269538],
            [-123.12928, 49.269531],
            [-123.13768, 49.275318],
            [-123.132331, 49.276931],
            [-123.121093, 49.284366],
            [-123.13668, 49.294456],
            [-123.134689, 49.29581],
            [-123.122711, 49.2915],
            [-123.112266, 49.290164],
          ],
        ],
      },
      properties: { name: 'Vancouver Downtown' },
    },
  ],
};

Assigning the optional id property to a GeoJSON feature allows it to be identified when using event handlers for interactions.

A full definition of the GeoJSON data format can be found at geojson.org.

Geometry Types

GeoJSON provides the following geometry types, illustrated below using data from the City of Vancouver Open Data Portal.

Points

The following map shows city voting stations as points. One voting station is a Point feature in red and other voting stations are a MultiPoint feature in blue.

Set the border, color and radius of the points in the feature properties.

"properties": {
    "name": "Carnegie Community Centre",
    "color": "rgb(148, 54, 81)",
    "radius": 5
  }

Lines

The map below shows cycle lanes as lines. There is a LineString - drawn in red along Pacific Boulevard - and a MultiLineString - drawn in blue as two segments along Expo Boulevard.

Set the color and width of the lines in the feature properties.

"properties": {
    "color": "rgb(148, 54, 81)",
    "width": 4
  }

Polygons

The map below shows two parks in Vancouver as polygons. Sunset Beach park is shown in red as a Polygon and Vanier Park is shown in blue as a MultiPolygon.

Set the border and color properties of the polygons in the feature properties.

"properties": {
    "name": "Sunset Beach Park",
    "color": "rgba(148, 54, 81, 0.5)",
    "border": {
      "color": "rgb(148, 54, 81)",
      "width": 1
    }
  }

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.