Hi Jean,<div><br></div><div>Thanks a lot for your input. I'll be looking into this and try to fix my zoom problem since all the rest is working properly.</div><div><br></div><div>Cheers,</div><div><br></div><div>Hugo<br>
<br><div class="gmail_quote">On Fri, Aug 12, 2011 at 4:06 PM, Jean-François Gigand <span dir="ltr"><<a href="mailto:jf@geonef.fr">jf@geonef.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Hugo,<br>
<br>
I can't answer your question straightforwardly, but can give some hints.<br>
<br>
- map.projection is only used as the default for new added layers<br>
The reference is map.getProjectionObject() which returns cloned baseLayer's.<br>
<br>
- same for maxResolution and minResolution: they matter for the layers,<br>
not for the map. The baseLayer is the master.<br>
<br>
- the 'changebaselayer' event is triggered after the change was made effective,<br>
so the map.getCenter() in your function would return the new center<br>
(within the projection of the new baseLayer's projection)<br>
<br>
- the OpenLayers.Map's setBaseLayer() function does not seem,<br>
indeed, to take care of reprojecting the map center.<br>
As a workaround, you may either :<br>
- reproject the current center *before* calling setBaseLayer()<br>
and affect it to map.center<br>
- make your own Map class extending OpenLayers.Map<br>
and overload setBaseLayer to handle the reprojection<br>
(either replacing the implementation, or just reproject this.center<br>
before calling OpenLayers.Map.prototype.setBaseLayer)<br>
<br>
I recommend your to dive into OpenLayers' source code, which is the<br>
best way to really understand how it behaves, for complex problems<br>
like this one.<br>
<br>
Best regards,<br>
<br>
Jean-François Gigand - Geonef<br>
Paris, France - <a href="http://geonef.fr/" target="_blank">http://geonef.fr/</a><br>
<br>
<br>
<br>
<br>
2011/8/12 Hugo <<a href="mailto:hfpmartins@gmail.com">hfpmartins@gmail.com</a>>:<br>
<div><div></div><div class="h5">> Hello all,<br>
> I'm trying to reproject openlayers map according to the selected base layer.<br>
> So, when the app is loaded my map has the EPSG:900913 projection (so that i<br>
> can use OSM, google, etc). I have other base layers that are in the EPSG:<br>
> 3763 projection and, when the user activate this layers the map will<br>
> automatically reproject itself to this new definition. I was able to<br>
> accomplish this however i have a small bug that i've not been able to<br>
> correct until the moment. After reprojecting i can't pan and if i make a<br>
> zoom it will go to a strange location (i think the zoom is still assuming<br>
> the old coordinates). After making the zoom i'm able to pan and zoom<br>
> normally.<br>
> The code i'm using:<br>
> function onBaseLayerChange(evtObj){<br>
> var mapProj, baseProj, map, newBase, reproject;<br>
> map = this;<br>
> newBase = evtObj.layer;<br>
> mapProj = (map.projection && map.projection instanceof<br>
> OpenLayers.Projection) ? map.projection : new<br>
> OpenLayers.Projection(map.projection);<br>
> baseProj = newBase.projection;<br>
> reproject = !(baseProj.equals(mapProj));<br>
> if (reproject) {<br>
> var center, maxExt;<br>
> center = map.getCenter().transform(mapProj, baseProj);<br>
> maxExt = newBase.maxExtent;<br>
> map.projection = baseProj;<br>
> map.resolutions = newBase.resolutions;<br>
> map.maxResolution = newBase.maxResolution;<br>
> map.minResolution = newBase.minResolution;<br>
> map.maxExtent = maxExt;<br>
> map.restrictedExtent = newBase.restrictedExtent;<br>
> map.setCenter(center);<br>
> }<br>
> }<br>
> I suppose i'm not setting some property... but which one?<br>
> Thanks in advance.<br>
> Cheers,<br>
> Hugo<br>
><br>
> --<br>
> Hugo Martins<br>
> LabNT - ISEGI UNL<br>
> Campus de Campolide<br>
> 1070-312 Lisboa<br>
> N 38°43'56.84", W 9°9'35.74"<br>
><br>
</div></div>> _______________________________________________<br>
> Users mailing list<br>
> <a href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
><br>
><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Hugo Martins<br>LabNT - ISEGI UNL<br>Campus de Campolide<br>1070-312 Lisboa<br>N 38°43'56.84", W 9°9'35.74"<br>
</div>