[OpenLayers-Users] Map reprojection issue

Hugo hfpmartins at gmail.com
Fri Aug 12 07:33:41 EDT 2011


Hello all,

I'm trying to reproject openlayers map according to the selected base layer.
So, when the app is loaded my map has the EPSG:900913 projection (so that i
can use OSM, google, etc). I have other base layers that are in the EPSG:
3763 projection and, when the user activate this layers the map will
automatically reproject itself to this new definition. I was able to
accomplish this however i have a small bug that i've not been able to
correct until the moment. After reprojecting i can't pan and if i make a
zoom it will go to a strange location (i think the zoom is still assuming
the old coordinates). After making the zoom i'm able to pan and zoom
normally.

The code i'm using:

function onBaseLayerChange(evtObj){
   var mapProj, baseProj, map, newBase, reproject;
   map = this;
   newBase = evtObj.layer;
   mapProj = (map.projection && map.projection instanceof
OpenLayers.Projection) ? map.projection : new
OpenLayers.Projection(map.projection);
   baseProj = newBase.projection;
   reproject = !(baseProj.equals(mapProj));
   if (reproject) {
      var center, maxExt;
      center = map.getCenter().transform(mapProj, baseProj);
      maxExt = newBase.maxExtent;
      map.projection = baseProj;
      map.resolutions = newBase.resolutions;
      map.maxResolution = newBase.maxResolution;
      map.minResolution = newBase.minResolution;
      map.maxExtent = maxExt;
      map.restrictedExtent = newBase.restrictedExtent;
      map.setCenter(center);
   }
}

I suppose i'm not setting some property... but which one?

Thanks in advance.
Cheers,
Hugo


-- 
Hugo Martins
LabNT - ISEGI UNL
Campus de Campolide
1070-312 Lisboa
N 38°43'56.84", W 9°9'35.74"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110812/578516a3/attachment.html


More information about the Users mailing list