I have a react/redux application that I've added a leaflet map to. The leaflet map is being populated through geoJSON. Is there a way I can call a redux action through a user click on a map feature? I'd really like to be able to run an action when the user clicks on a popup. I'd like to store the id number of the feature that the user clicked, so that I can run the action to fetch data and put it in the store, then open another page which has the details for that feature.
This is what I have in leaflet:
myLayer = L.geoJSON(features, {
//only points here
filter: function(feature, layer) {
return (feature.geometry.type == "Point");
},
//make each point a circle
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, geojsonMarkerOptions);
},
onEachFeature: function(feature, layer) {
//popup contents
var customPopup = `<div class='popuplink' > <-----user clicks
<p>${feature.properties.title}</p></div>`;
//popup options
var customOptions =
{
width: '72', //about 1 inch
className: 'custom'
};
//create layer
layer.bindPopup(customPopup, customOptions);
}
});
myLayer.addTo(map);
I tried to put in a link in the popup that when clicked goes to the page I want. (I use react-router in the app). Like this:
var customPopup = `<a href='/details/${feature.properties.id} >
<p>${feature.properties.title}</p></a>`;
But when I do that the whole redux store INIT is called and I lose everything. Can someone explain to me why this is happening? I understand that leaflet and react each maintain their own state. But is there a way to form a bridge between them so I can call actions from the map without losing my store?