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.

All,

Is there a way to set the xy and zoom level of a map using the URL of the site that is calling it?

I'm thinking of a site I'm using now, built on php, which has mapbox maps built in javascript and added to a DIV.

Could there be a way to use something like:

http: //mysite.com/map.php?x=234.534&y=34323.2343&zoom=5

Does that make sense?

-mb

share|improve this question

2 Answers 2

up vote 2 down vote accepted

If you're using mapbox.js directly, you can call map.ui.hash.add() (assuming your map variable is named map), and the page will have a hash like #10.00/45.5342/-73.7457 which encodes the zoom level, latitude, and longitude of the map position, and you can send users to URLs like that to set the initial map position.

share|improve this answer
    
Tom - got this to work, and saw the example under 'toggle map controls'. Thank you again!!! –  mapBaker Dec 12 '12 at 19:57

Here's a code snippet I found online that parses PHP URL variables into JavaScript. You may have to modify it a little to fit your needs, but it's pretty short and simple:

http://papermashup.com/read-url-get-variables-withjavascript/

share|improve this answer

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.