Map layers and basemaps

Layers and basemaps that make up the project summary and project edit maps

Sources, Layers, and Source Types

The two layer source types in Moped are vector tile layers and GeoJSON layers. The pattern for adding a source and layer to a react-map-gl map is to use the Source and Layer components. These two components are abstraction of Mapbox GL sources and layers. The Source component is responsible for the data and the Layer component is used to style the data of the source. An example of JSX for a vector tile layer is below.

<Source
  key={config.layerIdName}
  type="vector"
  tiles={[config.layerUrl]
>
  <Layer
    key={config.layerIdName}
    {...theOtherlayerProps}
  />
</Source>

Vector tile layers are used to display streets and points that a user can interact with to add and remove GeoJSON features associated with a project. These vector tile layers are maintained in ArcGIS Online (AGOL).

GeoJSON layers are generated from user input like those stored from the drawing UI exposed by the useMapDrawTools custom hook.

A good way to differentiate source types in the code is to look for whether a layerUrl is set in the layerConfigs of the mapConfig object. A vector tile layer source requires a url in order to present features to a user. A GeoJSON layer source will use GeoJSON data stored in the Moped database.

Vector tile layers

The two vector tile layers used in Moped are for street lines and intersection points. They are located at the following ArcGIS endpoints:

To add vector tile layers sourced from ArcGIS or other endpoints, the layer can be added by using the Mapbox Layer Style Spec and adding source and source-layer keys and values to the spec as shown below. This object defines props that are passed to the Layer component from react-map-gl.

Note that the geometry type (circle, line, etc.) in a vector layer determines the style properties from the Mapbox spec that are required to customize the layer.

{
  id: <some layer id string>,
  type: <a rendering type>,
  source: {
    type: "vector",
    tiles: <vector tile layer endpoint>,
  },
  "source-layer": <source layer name from the endpoint>,
  paint: {
    "fill-color": <a color or further logic using Mapbox spec>
  },
}

ArcGIS vector tile layer metadata and tiles links user the following patterns (using the CTN layer as an example).

Vector tile .pbf endpoint (used to render tiles on map) https://tiles.arcgis.com/tiles/0L95CJ0VTaxqcmED/arcgis/rest/services/CTN_Project_Extent_Vector_Tiles_with_Street_Name/VectorTileServer/tile/{z}/{y}/{x}.pbf

Vector tile styles metadata (helpful for finding the source layer name and type of geometry in layer) https://tiles.arcgis.com/tiles/0L95CJ0VTaxqcmED/arcgis/rest/services/CTN_Project_Extent_Vector_Tiles_with_Street_Name/VectorTileServer/resources/styles/root.json?f=pjson

Vector tile server metadata https://tiles.arcgis.com/tiles/0L95CJ0VTaxqcmED/arcgis/rest/services/CTN_Project_Extent_Vector_Tiles_with_Street_Name/VectorTileServer

Vector tile layer level of detail

When adding a vector tile layer, it is important to consider the maxLOD of the vector tile layer that is shown in the server metadata (see example link above) and pass that value as the maxzoom of the Mapbox source along with the endpoint. A good example of this in a react-map-gl component can be found in the NewProjectMap component in Moped.

If this data is not passed, it can lead to issue with rendering and capturing geometries with Mapbox GL. Here is one example where lines were split along the vector tiles beyond a certain level of zoom.

GeoJSON layers

Layers that are created from user input (like drawn points) require a source with type geojson and, in Moped, the geojson is formatted as a GeoJSON feature collection.

Base Maps

Default basemap

In Moped, the default basemap style is Mapbox Light and the streets layer for the mapStyle prop in react-map-gl is mapbox://styles/mapbox/light-v8.

Aerial Imagery basemap

To add aerial imagery, a Nearmap layer is added as a raster tile set. Nearmap access and the API key is managed by CTM and can be inquired about through the COA ServiceNow Portal. The API key is stored in the DTS 1Password Developers vault and is titled Moped Nearmap API Key.

The aerial basemap is added by providing a raster tile configuration that uses the Nearmap API endpoint along with the API key to provide aerial tiles. A sample configuration is shown below. A Mapbox example of using a custom tile set is here. This configuration is passed to the mapStyle prop of a react-map-gl map much like the default streets basemap above. This time, an object is passed instead of the string source of a Mapbox style.

{
  version: 8,
  sources: {
  "raster-tiles": {
      type: "raster",
      tiles: [
        `https://api.nearmap.com/tiles/v3/Vert/{z}/{x}/{y}.jpg?apikey=${NEARMAP_KEY}`,
      ],
      tileSize: 256,
    },
  },
  layers: [
    {
      id: "simple-tiles",
      type: "raster",
      source: "raster-tiles",
      minzoom: 0,
      maxzoom: 22,
    },
  ],
}

Last updated