I would like to extend the funtionality of OpenLayers that appends, on-the-fly as the user zooms and pans the map, the longitude/latitude parameters as a anchor to the URL in the browser's address bar, e.g.


I would like certain other links on the same page, outside of the map, to have the the anchor #zoom=12&lat=50.90306&lon=-1.38329&layers=BT appended to them.

The reason is so that when these links are clicked on, the map will be loaded at the same pan and zoom position. These links contain other 'arguments' that determine what data appears in the overlay. The site runs on the Drupal 7 content management system, with the OpenLayers module and these other arguments control a Drupal View to control what is displayed in the overlay.

So my approach is to implement some self-contained javascript/jquery that doesn't change openlayers javascript (to avoid overheads of burdening the authors with testing, commits to the source etc) but instead is loaded after openlayers javascript, this self-contained code would at run time 'register'/'bind' as necessary to be able to listen to pan and zoom events and obtain the longitude and latitude anchor data and add these to the certain other links. I would identify those certain other links with a class attribute in the html <a /> element and use the JQuery DOM functions to search for the class and prepend the anchor.

What I need is to know how the OpenLayers code is updating the location field/address bar with the # anchor in order to figure out how to write some separate code to listen for the pan zoom events.

Please share your thoughts. Thanks.

1 Answer 1


try something like this, where #plink is where ever you want it on the page

$("#plink").append("Link to this map"); map.addControl(new OpenLayers.Control.Permalink("permalink",null,
{ "createParams": myCreateArgs, title: "right click for link options" }));

// check if we were called with permalink args

var args = OpenLayers.Util.getParameters(); if (args["xyz"]) { do whatever }

//and the myCreateArgs function

function myCreateArgs() { var args = OpenLayers.Control.Permalink.prototype.createParams.apply( this, arguments ); // process arguments return args; }

I do not think I have forgotten anything, I can post a live link if necessary

  • +1 thank you very much Ralph for your input Ralph! :) I will check this out and report back Jul 16, 2013 at 14:25

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.