I am trying to highlight a marker using a different icon when clicked. There are many posts about it but I am getting different error:
.setIcon is not a function.
This is my point data and the click event on it:
var schoolP = new L.GeoJSON.AJAX('data/schools.json', {pointToLayer:function(feature,latlng){
var str= "<h6><b>"+feature.properties.sch_name+", "+feature.properties.sch_loc+"</b><br>Primary Schools</h6>";
return L.marker(latlng,{icon: primaryIcon}).bindPopup(str);
}});
schoolP.addTo(mymap);
// When click
schoolP.on('click', function(e) {
schoolP.setIcon(highlightIcon);
});
Below is how I defined the marker icons:
//primary school icon
var primaryIcon = new L.Icon({
iconUrl: '/webmap101/img/schoolP.png',
iconSize: [40, 61],
iconAnchor: [12, 41],
popupAnchor: [120, 30]
});
//icon when highlight
var highlightIcon = new L.Icon({
iconUrl: '/webmap101/img/SchoolHighlight.png',
iconSize: [60, 81],
iconAnchor: [12, 41],
popupAnchor: [120, 30]
});