I am reposting a question that i asked in stackoverflow about leaflet and custom renderers.
Basically what i want to achieve is create a custom renderer that alters the shape of CircleMarker or extend the Path constructor to create custom shaped (vector) Markers.
What i've done so far is this:
import {
CircleMarker as LeafletCircleMarker,
Canvas as LeafletCanvas,
} from "leaflet";
import { withLeaflet, Path } from "react-leaflet";
const myRenderer = (layer) => LeafletCanvas({ padding: 0.5 });
class CustomMarker extends Path {
createLeafletElement(props) {
const enhancedProps = {
...props,
renderer: myRenderer
};
const el = new LeafletCircleMarker(
props.center,
this.getOptions(enhancedProps)
);
this.contextValue = { ...props.leaflet, popupContainer: el };
debugger;
return el;
}
updateLeafletElement(fromProps, toProps) {
if (toProps.center !== fromProps.center) {
this.leafletElement.setLatLng(toProps.center);
}
if (toProps.radius !== fromProps.radius) {
this.leafletElement.setRadius(toProps.radius);
}
}
}
export default withLeaflet(CustomMarker);
I am just setting the Canvas constructor as a renderer like the examples in the Leaflet docs but i am getting an Error: The provided object is not a Layer
in layer/Layer.js:159
addLayer
function.
Can someone please instruct me in how to implement a renderer?