I'm using react-leaflet and want a custom marker icon. React-leaflet can take a Leaflet.Icon object to display a custom marker icon. So I NPM installed leaflet, and added import { L } from 'leaflet';.
I then added:
const FPIcon = L.Icon.extend({
options: {
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76]
}
});
const purpleIcon = new FPIcon({
iconUrl: '%PUBLIC_URL%/markers/Bar-Marker.png'
});
to my render method.
But I keep getting the following error Cannot read property 'Icon' of undefined.
To achieve a custom marker icon, I've also tried the following:
const purpleIcon = L.icon({
iconUrl: '%PUBLIC_URL%/markers/Bar-Marker.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76]
});
but again got a Cannot read property 'icon' of undefined error.
Any ideas on what I'm doing wrong?
}at the end. And what happend if you use an url like unpkg.com/[email protected]/dist/images/marker-icon.png ? - Baptisteconsole.log(purpleIcon)? - Baptisteconst FPIcon = L.Icon.extend({- JL9