Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am building a web application where I need to compare 2 different maps of the same area, I need for the events on one map to automatically be triggered on the other map. I have so far:,evt.px);

these guys have done a map compare:

but I have no idea bow they achieved this event handling..

please help, I need this functionality As soon as possible, its been a week am fighting with this..I will appreciate all replies.

share|improve this question
up vote 7 down vote accepted

Do you need to synchronize only moving and zooming of map?

In that case, one simple solution is: listen moveend event on map, and then zoom other map to extent of current map.

map1 = new OpenLayers.Map('map1');
map2 = new OpenLayers.Map('map2');{
    moveend: function(evt) {

    moveend: function(evt) {

Here's fiddle:

I did afraid at first, that there will infinite loop, when zoomToExtent triggers new event, but it works. I have to think about it, why :)

share|improve this answer
:-), genious! why did I not think of that..thank you so much!!! it seems to work. – Eli Nov 30 '12 at 11:05

It's also possible to make the feedback instant, at the cost of complicating the code a bit (and causing potential performance problems if there are other events attached to the maps):

(used user1702401's answer and Fiddle as a template - thanks)

var mapFollow = function(mapA, mapB) {
    var syncMapHandler = function() {
        var aCenter = mapA.getCenter();
        var bCenter = mapB.getCenter();

        var coordsChanged = (( !== ||
            (aCenter.lon !== bCenter.lon));

        if (coordsChanged) {
            mapB.moveTo(mapA.getCenter(), mapA.getZoom(), {
                dragging: true
        'move': syncMapHandler,
        'zoomend': syncMapHandler,
        scope: this

map1 = new OpenLayers.Map('map1');
map2 = new OpenLayers.Map('map2');

mapFollow(map1, map2);
mapFollow(map2, map1);

Live example here:

share|improve this answer
Thank you.. very helpful..! – Eli Dec 3 '12 at 11:10

Your Answer


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.