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.

Can anyone give me some pointers (code would be helpful) on how to go back to the extent a user was at after they have navigate away and clicked the back button?

So I'm viewing a map at X extent I click on some link and page changes, on clicking the back browser button I want to be able to get back to the Map Extent I was just before the page changed.

Any help much appreciated.

share|improve this question
    
UPDATE: Thanks for your response guys. Swingley I can't use HTML5 just yet as the browsers this would be used in does not support HTML 5 just yet. PETR K. Tried implementing the jQuery history plugin but I'm getting a jQuery not defined error... Must say not terribly good at jQuery. Could post my embarrassing code if it helps. –  user1986 Feb 22 '11 at 13:30
    
@Michael, I have implemented the cookie approach and it works great! Thanks! It is sort of an interim solution as folks would rather I used the jQuery approach (which I'm still getting errors with). But for now you idea worked great. Thanks. –  user1986 Feb 24 '11 at 10:55
add comment

4 Answers 4

I have had good experience with using the jQuery history plugin. Works great to store state data in the hash part of the URL, which the user can go get back to using the back button. It also makes bookmarking to a particular extent possible.

share|improve this answer
1  
+1. I wouldn't normally be on board with loading an additional library but this looks like the easiest solution to accomplish what OP is requesting. –  Derek Swingley Feb 18 '11 at 5:45
    
Thanks for your response guys. Swingley I can't use HTML5 just yet as the browsers this would be used in does not support HTML 5 just yet. PETR K. Tried implementing the jQuery history plugin but I'm getting a jQuery not defined error... Must say not terribly good at jQuery. Could post my embarrassing code if it helps. –  user1986 Feb 22 '11 at 13:27
    
any chance of getting pointers on how to implement this? –  user1986 Feb 24 '11 at 10:56
    
@blueRace You could post it as a question on stackoverflow.com (since that site is better suited to answer jQuery-specific questions). –  Michael Todd Feb 24 '11 at 15:10
add comment

Probably one of the easiest ways to do this would be to store the extent in a cookie after every map extent change. Then, when the user loads the page for the first time, use the extent you stored to set the map extent.

share|improve this answer
    
Michael, I have implemented the cookie approach and it works great! Thanks! It is sort of an interim solution as folks would rather I used the jQuery approach (which I'm still getting errors with). But for now you idea worked great. Thanks. –  user1986 Feb 24 '11 at 10:54
add comment

Just thought I'd update this post again with my findings.

The solution was to use a textbox in a form. Populate the textbox (this can be hidden) with the current map extent. Since browsers maintain the viewstate of their elements when you navigate away the state and content of the textbox is maintained (added to the browser history) so on clicking browser back it restores the content of the textbox as before and a bit of code to read the restored extent and position map accordingly.

Hope this alternative solution helps anyone else wanting to do something similar.

blueRace

share|improve this answer
add comment

This isn't natively part of the API but it is something you could code. The closest thing in the existing API would be to use a navigation toolbar. One other option would be to use the HTML5 history API. Here's a demo: HTML5 History API.

share|improve this answer
add comment

Your Answer

 
discard

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