Posted by kartagis on February 14, 2014 at 2:37pm
Hi,
I was at last able to create and display a map with leaflet. I now have a question though. How can I create multiple layers with different markers? EDIT: So far, I've tried adding another block display to the view and filtering it with a term.
Regards,
K.

Comments
Unfortunately...
The Leaflet JS library can do this, but the Drupal module does not provide a UI for creating different data layers on the same map view.
The latest version of the Leaflet module allows you to use tokens to define a custom marker. I haven't done this, but it seems you should be able to use a token that varies based on a field in your result, and name your markers to match that.
You might also check out IP Geolocation Views & Maps. With that, you can define one field as a differentiator, and assign a different marker for each possible value.
In each of these cases, you can't turn on and off different results using a map control, because they're not really layers. You could expose some filters for your view though.
And finally, there's a sandbox module that provides an API to combine multiple views or displays into one Leaflet map.
yeah might want to go Openlayers
If you're familiar with leaflet it's pretty easy. I just use the API from the leaflet module to get the map on the page then add all my layers dynamically with JavaScript with a little help from D3.js like this
d3.json(Drupal.settings.geoJSON.boundariesgeojson, function(collection) {
barriers = L.geoJson(collection, {
style: function(feature) {
return {
color: 'none'
};
}
});
thisLeafletMap.addLayer(barriers);
});
You can add multiple layers and add layer controls etc this way. It's pretty powerful, but takes some time to become familiar with it. If you need a way to control layers in a UI I think OpenLayers does a good job and gives you lots of control though the UI of that module takes some getting used to as well.
Use Openlayers
If you want different markers for different layers then you should choose Openlayers. This is one of the use cases were there is a clear difference in what you can do with Openlayers and Leaflet.
In Openlayers: create several OpenLayers Data Overlays in Views, filtered by your criteria. Then in OpenLayers display all of them on the same map with different markers.
In case you want to cluster them, be aware that they will be clustered by layer.
You can also asign individual markers per entity by assigning an image field as source for the markers.
And in case you come to DrupalDev Days: I'll present a session on that and other use cases where either Leaflet or OpenLayers can be the better option. http://szeged2014.drupaldays.org/program/sessions/openlayers-vs-leaflet
Site builder and Documentation WG member
There are two reasons I am
There are two reasons I am using Leaflet:
1- The latest version of geocoder module spits out this error about projections with openlayers.
2- I wanted to challenge myself and learn about Leaflet.