[OpenLayers-Users] toggling between WMS base layer and Google base layer causes viewport to drift

Mike Quentel mikequentel at yahoo.com
Wed May 23 19:36:45 EDT 2007


There is a WMS base layer in WGS84 (EPSG: 4326) that is the default base layer (it's visible after the map first launches).

There is a Google base layer as well.  As you probably know, the Google layer is in some kind of Mercator, with zoom resolutions that cannot be modified.

Additionally, there are WMS overlays in WGS84.

When user toggles the radio options back and forth between the WMS and Google, the view port "drifts" eastward.  The WMS overlays look proper on the Google layer (they stretch on to Google correctly), but there is always this shift of the viewport.  It's an annoyance for our users when their viewport extents suddenly shift, and they have to drag the map back to where it was.

I've been trying to find a solution for this issue.  In OpenLayers.Control.LayerSwitcher, I've tried to add a member to store the older extent information of the default (non-Google) base layer, as well as a function to directly tell Google to set its centre to the older centre, like this:

    /** @type Bounds */
    olderCentre: null,

    
    updateGoogle: function() {
      var currentBaseLayer = this.map.baseLayer;
      if (currentBaseLayer != null) {
        if (currentBaseLayer.CLASS_NAME != "OpenLayers.Layer.Google") {
          this.olderCentre = currentBaseLayer.getExtent();
          alert("this.olderCentre: " + this.olderCentre);
        } else {
          var gLatLon = new GLatLng(this.olderCentre.getCenterLonLat().lat, this.olderCentre.getCenterLonLat().lon);
          this.mapObject.setCenter(gLatLon);
        } 
      }    
    },

I'm getting the impression that this is not a good way to enforce the map extents in this user scenario.  Not even sure where to attempt to call the function above.  I am getting nowhere with this approach.

Please, any advice?

Mike Quentel




      ___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/ 



More information about the Users mailing list