Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

75
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!