Esri/esri-leaflet-vector

Add a public method to expose the underlying MaplibreGL map object

gowin20 opened this issue · 1 comments

Describe the problem

I want to customize and set the opacity of individual objects within a VectorBasemapLayer. These vector basemap styles are actually composed of many individual layers that get loaded into a MapLibreGLLayer object separately.

If I could access the underlying maplibregl map object in my code, I could write the following maplibre style code to set the opacity of my basemap:

const layers = map.getStyle().layers;
layers.forEach((layer) => {
  if (layer.type === "fill" && !layer.id.match(/(Water area|Marine area|Bathymetry|Building)/)) {
    map.setPaintProperty(layer.id, "fill-opacity", 0.5);
  }
});

Describe the proposed solution

I propose a new public member function to VectorBasemapLayer called getMaplibreStyle that returns the underlying maplibre style object.

  getMaplibreMap: function () {
    return this._maplibreGL.getMaplibreMap();
  }

This would allow me to write const map = basemap.getMaplibreMap() and successfully execute the code above.

Alternatives considered

Instead of simply returning the entire maplibre map, we could also return a subset of that information - such as only the map style.

Additional Information

No response

After researching this more, the use case that this would enable will be met by implementing #150. VectorTileLayer already has a style parameter that allows you to customize the style, so basemap styles will also become customizable if the inheritance of that class is changed.