Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
add comment

Quick answer to your message, It seems you basically want to redirect the user right ? 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";
                window.location.href=url;
            }
            // then call it on the click event :
            click: redirect

my two cents ..

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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