I have one marker on the map in leaflet:
var centerMarker = L.marker(centerPoint, { title: 'unselected' }).bindLabel(schools[i][0]);
centerMarker.on('click', selectMarker);
centerMarker.addTo(map);
I want to change the size of that marker on click.
I know that we can change icons but I just want to change the size of the same icon of the marker.
Marker Custom IconsStep 1 − Create a Map object by passing a <div> element (String or object) and map options (optional). Step 2 − Create a Layer object by passing the URL of the desired tile. Step 3 − Add the layer object to the map using the addLayer() method of the Map class.
If you have the leaflet and react-leaflet npm modules installed, this should work for you. Click on the marker and you will see the popup with a "Change Marker Color" button. That should do the trick.
The Clusterer can handle 10,000 or even 50,000 markers (in chrome).
Use markers to call out points on the map. Marker locations are expressed in latitude/longitude coordinates, and can either appear as icons or as circles.
You can get the old icon from the marker itself, change the size of the icon and then call setIcon
with the changed icon:
var icon = centerMarker.options.icon;
icon.options.iconSize = [newwidth, newheight];
centerMarker.setIcon(icon);
Although it is an old question, but in case someone is looking for another possible option other than the answered ones.
L.marker([coord.latitude, coord.longitude], {
color: 'red',
icon: getIcon(),
data: coord
}).addTo(myMap).on("click", circleClick);
function getIcon(total_dead_and_missing) {
var icon_size = [50, 50]; //for dynamic icon size,
var image_url = '1.png'; //for dynamic images
L.icon({
iconUrl: image_url,
shadowUrl: 'leaf-shadow.png',
iconSize: icon_size , // size of the icon
shadowSize: [50, 64], // size of the shadow
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
}
Resource : https://leafletjs.com/examples/custom-icons/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With