[OpenLayers-Users] Map reprojection issue
Jean-François Gigand
jf at geonef.fr
Fri Aug 12 11:06:58 EDT 2011
Hi Hugo,
I can't answer your question straightforwardly, but can give some hints.
- map.projection is only used as the default for new added layers
The reference is map.getProjectionObject() which returns cloned baseLayer's.
- same for maxResolution and minResolution: they matter for the layers,
not for the map. The baseLayer is the master.
- the 'changebaselayer' event is triggered after the change was made effective,
so the map.getCenter() in your function would return the new center
(within the projection of the new baseLayer's projection)
- the OpenLayers.Map's setBaseLayer() function does not seem,
indeed, to take care of reprojecting the map center.
As a workaround, you may either :
- reproject the current center *before* calling setBaseLayer()
and affect it to map.center
- make your own Map class extending OpenLayers.Map
and overload setBaseLayer to handle the reprojection
(either replacing the implementation, or just reproject this.center
before calling OpenLayers.Map.prototype.setBaseLayer)
I recommend your to dive into OpenLayers' source code, which is the
best way to really understand how it behaves, for complex problems
like this one.
Best regards,
Jean-François Gigand - Geonef
Paris, France - http://geonef.fr/
2011/8/12 Hugo <hfpmartins at gmail.com>:
> 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"
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>
More information about the Users
mailing list