Skip to content

Latest commit

 

History

History
33 lines (27 loc) · 2.5 KB

README.md

File metadata and controls

33 lines (27 loc) · 2.5 KB

mapbox-gl-custom-protocol

Supports custom protocols when using Mapbox GLJS version v1.9.1. It may work with future versions, but it hasn't been tested.

Objective ✨

Maplibre-gl-js, a fork of Mapbox GLJS, has implemented a feature called addProtocol that was not supported in Mapbox GLJS. This approximates that functionality in Mapbox GLJS.

Inspiration 💡

For users of tools like Mapbox Atlas, where Mapbox GLJS support is useful to maintain compatibility. This makes it easier to abstract out links to other services that support the Mapbox Vector Tiles Standard, but may not support the same Tile Mapping Scheme (such as ESRI VTPK).

Usage 🛠️

This code is not needed with Maplibre-gl-js. If it detects that addProtocol is already defined, it will use the existing function.

See information on how to define the protocolLoadFn here: https://github.com/maplibre/maplibre-gl-js/blob/492bec58c5684609af8fba81ef01e5f5a3ef0711/src/index.js#L185

<script src="https://loc8.us/mapbox-gl-custom-protocol/dist/mapbox-gl-custom-protocol.min.js"></script>

map.addSourceType('vector-custom', CustomProtocol(mapboxgl).vector, (e) => {
    if (e) {
      console.error('There was an error', e);
    }
});
// addProtocol is not available before the sourceType is added
mapboxgl.addProtocol('protocol-name', protocolLoadFn);

Examples ⚙️