Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

53
Views
Leaflet LayerGroup - Mapbox GL JS Equivalent

Does anybody know of an equivalent to the Leaflet L.layerGroup in Mapbox GL JS? I can do this in leaflet:

var layerGroup = L.layerGroup().addTo(map);

And then if I want to add, say, a marker to the layer group, I can do

L.marker([50.5, 30.5]).addTo(layerGroup);

The functionality I am really trying to get is the ability to remove and add back these layers. In leaflet you can do

// remove the layer from the map
map.removeLayer(layerGroup)

// re-add the layer to the map
layerGroup.addTo(map)

// clear all layers without removing from the map
layerGroup.clearLayers()

However in Mapbox GL JS I haven't found a functionality or a plugin that does something similar to this. When you want to add something to the map in Mapbox, you can do .addTo(map), so it seems to me there is probably a feature where you can create a layer group and do .addTo(layerGroup).

It might not be exactly how I envision it here, but right now I have nothing.

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs