How a custom react component which outputs Marker on map should be written? I need to have smth like this working:
import MyMarker from './MyMarker.js';
const builtMarker = (function() {
const position = [51.520, -0.11];
return (
<MyMarker position={position}/>
);
})();
render(
<div>
<h1>Hello, world!</h1>
<div className="map">
<Map center={center} zoom={13}>
<TileLayer
url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
/>
{builtMarker}
</Map>
</div>
</div>
,
document.getElementById('example')
);
I made MyMarker
component like that https://github.com/varya/react-leaftlet-test/blob/master/src/MyMarker.js but this gets error:
Uncaught TypeError: Cannot read property 'addLayer' of undefined
I guess the component should not only extend MapLayer
but also provide special interface. What is missing? I could not find similar example in the docs.
Also, what should I do to output several Markers? I mean, in React it's required to be in a single wrapper. But it cannot be just <div>
for the map. How this wrapper should be written?
PS: This is the repo where I demonstrate my case https://github.com/varya/react-leaftlet-test