Pop Up On React Leaflet Map Library
I'm using react-leaftlet map library https://react-leaflet.js.org/en/ in my react app and i have rendered some markers on the map and when a user clicks on a marker, a pop up appea
Solution 1:
Use onEachFeature
prop on react-leaflet
's GeoJSON
wrapper to pass an arrow function similarly to native's leaflet onEachFeature
function to be able to generate a popup when clicking on each district.
<GeoJSON
data={geo}
style={this.hospital_style}
onEachFeature={onEachFeature}
/>
const onEachFeature = (feature, layer) => {
const popupContent = `District Code: ${feature.properties.electoralDistrictCode} <br> District: ${feature.properties.electoralDistrict}`;
if (feature.properties && feature.properties.popupContent) {
popupContent += feature.properties.popupContent;
}
layer.bindPopup(popupContent);
};
Post a Comment for "Pop Up On React Leaflet Map Library"