Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

52
Vistas
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
Responde la pregunta
Encuentra empleos remotos