Leaflet – Navigate to URL on Click with GeoJSON

geojsonjavascriptleaflet

I'm using Leaflet API and geojson. I defined a function which zooms to the feature when clicked:

function zoomToFeature(e) {
            map.fitBounds(e.target.getBounds());
        }




 function onEachFeature(feature, layer) {
                layer.on({
                    mouseover: highlightFeature,
                    mouseout: resetHighlight,
                    click: zoomToFeature
                });
            }

But, I don't need to zoom on the feature, but to go to the URL. So, when user click on polygon on the map, it takes him to some url.

Is that possible and how? I thought I can maybe define some function which will lead to the url, and then pass it to layer.on click event, but not sure how.

Thank you for any help.

Best Answer

Keep the code the same just replace the map.fitBounds(e.target.getBounds()); with window.open('http://www.google.com','_blank');