Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to create filters based on attributes of markers. I have markers defined this way:

var locations = [    
['AB11 5HW','17','A',57.147701,-2.085442 ] ,
['AB11 8DG','3','B',57.129372,-2.090916 ] ,
];

If the user selects for 'A' or 'B' all markers containing attribute A or B should become visible on the map. Something like

var markersA =  a[2] contains 'A' 

I thought it is maybe possible with Leaflet Marker groups or something similar.

I'm new to Javascript so I'm interested if it's even possible.

share|improve this question

1 Answer 1

If you know the amount of attributes ahead of time, you can use Layers to get the job done. Leaflet has a good tutorial on that.

Basically, you loop through the initial array and split them into two separate arrays based on the specified variable. Then you add each array to it's own LayerGroup which gives you an easy way to turn the Markers on and off en-masse.

Here's a working jsfiddle showing how it works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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