Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

76
Vistas
leaflet filtering by layer id categories

I've adapted this code to create category tag arrays - I want to take each tagCategory group and if it's label reference slice matches some feature - add it as a variable by its label name to a list (to be used for filtering markers)

Here is my code - adapted from here

let ind00ss00test = new L.layerGroup();
console.log(ind00ss00test)
let LR1test = new L.layerGroup()
const subGroups1 = [];


  d3.json(mapsData, function(data){
    industry = L.geoJSON(data, {

    pointToLayer: function (feature){
        return new L.circleMarker([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], {
        className: feature.properties.HASHcodePM,
        radius: getRadius(feature.properties.size),
        fillOpacity:0.8,
        color: getColor(feature.properties.type),
        fillColor: getColor(feature.properties.type),
        weight: getRadius(feature.properties.size)/3,
    }) 
  },
    onEachFeature: function(feature, layer) {
      layer.bindPopup("Name: " + feature.properties.Name + "<br>Type: "+ feature.properties.type)
      var HASHcode = feature.properties["HASHcodePM"];
 
      var INDSShash = feature.properties.HASHcodePM.slice(0,9);  //INDSS
      var LRhash = feature.properties.HASHcodePM.slice(9,12); //LR
      var tagCategories = subGroups1[HASHcode];
 
    if (!tagCategories) {
      tagCategories = subGroups1[HASHcode] = L.geoJson();
    } tagCategories.addLayer(layer); 

    if (INDSShash == "IND00SS00") tagCategories.addTo(ind00ss00test);
    if (LRhash == "LR1") tagCategories.addTo(LR1test); 
          },
        })
      });

So I want to take thelabels referencing label slices -

And I want to filter the markers from layers with property LR1 on 'overlayremove' :

const content = L.layerGroup().addTo(myMap);
         myMap.on('overlayadd overlayremove', () => {
            if (myMap.hasLayer(ind00group)) {
              ind00ss00test.addTo(content))
            }
            if (myMap.hasLayer(ind99group)) {
              ind00ss99test.addTo(content))
            }
            if (!myMap.hasLayer(LR1Group)) {
              LR1test.forEach(marker => content.removeLayer(marker))
            }
          })

The ind00ss00test can be added/removed, but the markers do not filter using the LR1test.forEach (I just need to filter markers from the added layer groups if the LR1 is deselected. ) So essentially - I'd like to be able to take these layer groups and dynamically add them as variables to a list based on like features - such as this - without having to manually add each layer group by name.

Any suggestions would be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Well, I figured it out if anyone is curious. Keeping the same code as above and replacing these variables/options:

          let lr1group = L.layerGroup()
          let ind00ss00group = L.layerGroup()
    
          let lr1List = [];
          let ind00ss00List = [];
    
          if (INDSShash =='IND00SS00' ) ind00ss00List.push(tagCategories);
          if (LRhash == "LR1") lr1List.push(tagCategories); 
    
    
          const content = L.layerGroup().addTo(myMap);
            // filter selection
          myMap.on('overlayadd overlayremove', () => {
            if (myMap.hasLayer(ind00ss00group)) {ind00ss00List.forEach(marker=> marker.addTo(content))
              }
            if (!myMap.hasLayer(ind00ss00group)) {ind00ss00List.forEach(marker => content.removeLayer(marker))
              }
            if (!myMap.hasLayer(lr1group)) {
                lr1List.forEach(marker => content.removeLayer(marker))
             }
    })
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda