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

function zoomToFeature(e) {

 function onEachFeature(feature, layer) {
                    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.

2 Answers 2


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


I am not familiar with LeafLet but perhaps you can try with a function like :

            function redirect(e)
                // assuming you have a url property embeded in your feature
                var url = e.target.some_url_property; 
                // or hardcoded as...
                var url = "http://www.somelink";
            // then call it on the click event :
            click: redirect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.