1

I have been on Leaflet maps for a few weeks. We are switching from Google maps to Leaflet. I work with a non-profit organization providing support for citizen water quality samplers.

I do not mind research while learning Leaflet (not asking for specific code per se), only a potential path to obtain the results I am trying to achieve (a suggestion or two).

What I have:

A geojson file with sampling sites (points) that are either (1) Active, or (2) Inactive. I have successfully introduced custom icons (Active=green, Inactive=red). I have well behaved tooltips working as well as informative popup windows.

My problem is this:

I would like to split the geoJson file into two (Groups?) or apply (filtering?) such that in the end I have a checkbox for both "Active" and "Inactive" points that can be turned on or off in the Leaflet Control Menu.

So my question is general: What might be the best route for researching this? I have seen and tested dozens of examples on the web but I am still learning and not sure what the best approach might be.

There appears to be three general approaches, q.v.,

  1. 2 independent *.json files, one active, on inactive.
  2. Try filetering the data such that the Layer Menu Control recognizes the filter data as a "layer" (i.e., can be placed in the Leaflet Control Menu).
  3. Create two Groups and remove one of the 2 layers from the Leaflet Control Menu as required.

*** My current workaround ***

Right now I have a workaround where I include a 1x1 100% transparent icon image that is not detectable on the map while the Active icons are visible, and then v.v. when Inactive Sites are selected from the Control Menu. If both Active and Inactive Sites are selected on the Leaflet control menu both Green and Red icons appear.

My workaround:

Select "Active" in Control menu: Active Sites (green icon,30x30), Inactive Sites (transp., icon 1x1) Select "Inactive" in Control menu: Active Sites (transp., 1x1), Inactive Sites (red icon 10x10)

One nice feature for this workaround is that when I use the Search Control I can locate all sites, active or inactive, since they originate in 1 geojson file.

Thanks if advance. Just a thought on what direction to pursue would be great.

New contributor
Louis Lemire is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Please provide enough code so others can better understand or reproduce the problem.
    – Community Bot
    Commented Jul 5 at 14:02

0

Browse other questions tagged or ask your own question.