[OpenLayers-Users] Re: Synchronize position and zoom of two maps

Meine Toonen meinetoonen at b3partners.nl
Tue Dec 20 09:28:38 EST 2011


Hi,

I suspect that when map1 moves, it updates map2, which in turn updates map1, which updates map2...etc..

Add something like this:
var c1, c2, z1, z2;
var updatingMap1 = false,updatingMap2 = false;
map1.events.register("moveend", map1, function() {
        if(!updatingMap2){
            c1 = this.getCenter();
            z1 = this.getZoom();
            updatingMap1 = true;
            map2.panTo(c1);
            map2.zoomTo(z1);
            updatingMap1 = false;
        }
});
map2.events.register("moveend", map2, function() {
        if(!updatingMap2){
            c2 = this.getCenter();
            z2 = this.getZoom();
            updatingMap2 = true;
            map1.panTo(c2);
            map1.zoomTo(z2);
            updatingMap2 = false;
        }
}); 

What I try to do (haven't tested it) is to prevent to update map2 when moving in map2.

Good luck!

Met vriendelijke groet,

Meine Toonen
B3Partners BV
Tel: 030 214 2083
  _____  

From: canduc17 [mailto:candini at meeo.it]
To: users at openlayers.org
Sent: Tue, 20 Dec 2011 15:07:31 +0100
Subject: [OpenLayers-Users] Re: Synchronize position and zoom of two maps

I have tryed with the following:
  
  var c1, c2, z1, z2;
  map1.events.register("moveend", map1, function() { 
   c1 = this.getCenter();
   z1 = this.getZoom();
   map2.panTo(c1);
   map2.zoomTo(z1);
  });
  map2.events.register("moveend", map2, function() { 
   c2 = this.getCenter();
   z2 = this.getZoom();
   map1.panTo(c2);
   map1.zoomTo(z2);
  });
  
  It seems to work but from time to time maps get frozen and firebug (firefox
  plugin) reports me the error "too much recursion".
  If I comment out map2 related event I have no problems, but the
  synchronization is only if I pan/zoom map1 and I would like to make it
  possible also for map2.
  
  Any ideas on how to solve this?
  
  --
  View this message in context: http://osgeo-org.1803224.n2.nabble.com/Synchronize-position-and-zoom-of-two-maps-tp7107428p7111860.html
  Sent from the OpenLayers Users mailing list archive at Nabble.com.
  _______________________________________________
  Users mailing list
  Users at lists.osgeo.org
  http://lists.osgeo.org/mailman/listinfo/openlayers-users
    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20111220/cad8299c/attachment-0001.html


More information about the Users mailing list