0

I am creating a map with leaflet layer. Right now, each marker has three different attributes and I would like to create layers base on these three attributes (Model, group, and status). I am able to show only all the models, only all the groups, or only all of the status.

THE NEED : I was wondering if anyone knows how to create layer that can do AND filter? So I can filter something like show all the Model A in group 2 and status is active? Or show all the model B and status are active?

1

The easiest way would probably be to implement the AND filter yourself using JavaScript.

Probably something in the lines of:

function applyAndFilter(val1, val2, val3) {
  layerGroupOnMap.clearLayers();

  layerGroupReference.eachLayer(function (layer) {
    if (layer.prop1 === val1 && layer.prop2 === val2 && layer.prop3 === val3) {
      layerGroupOnMap.addLayer(layer);
    }
  });
}

layerGroupReference would hold all of your layers / markers, but it should not be on map.

layerGroupOnMap would be the container group that will receive the filtered layers / markers. It should be on map, even if empty.

Then you would trigger the applyAndFilter after map initialization, and whenever your selection changes for any of the 3 attributes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.