simplemap
simplemap copied to clipboard
Allow custom marker icon
It would be helpful to easily allow custom marker icons. (ie. change the svg to one I specify) I hacked it for now by by adding the following to line 138 of ether/simplemap/src/services/EmbedService.php 'icon' => '/myPath/myMarker.svg',
I'm really keen for this feature too. Any plans to get this functionality integrated?
Hey, This is definitely something we want to add. Hopefully early in the new year. Thanks!
At the moment, the cleanest way I found to do this is by looking through the code, I noticed that the ID of the map is also used as a global variable. Since I use OpenStreetMap and there's a method to update the icon programmatically through leaflet js, I do this:
{{
craft.maps.embed({
center: 'Hamburg, Germany',
markers: mapLocations,
width: '1800',
height: '500',
id: 'locations_map',
options: {
disableDefaultUI: true
}
})
}}
{% js %}
locations_map.whenReady(function() {
let the_icon = L.icon({
iconUrl: '/dist/icons/marker.svg',
iconSize: [80, 80],
iconAnchor: [40, 40]
});
for (let layerId in locations_map._layers) {
let layer = locations_map._layers[layerId];
if(layer instanceof L.Marker) {
layer.setIcon(the_icon);
}
}
});
{% endjs %}