Hi Matt,<br><br>That works like a charm ;)<br>Really, thanks a lot for this suggestion and code!<br><br>Cheers,<br><br>Hugo<br><br><br><div class="gmail_quote">On Mon, Jun 20, 2011 at 8:29 PM, Matt Priour <span dir="ltr"><<a href="mailto:mpriour@kestrelcomputer.com">mpriour@kestrelcomputer.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><u></u>
<div style="padding-right:10px;padding-left:10px;padding-top:15px" name="Compose message area">
<div><font size="2" face="Arial">I've had similar problems and I've solved it by
adding an event listener to the map's baselayerchange event.</font></div>
<div>you would put mapOptionsEtrs properties on the Etrs base layer rather than
on the map. Map options are most ignored and overwritten by base layer
options.</div>
<div><font size="2" face="Arial"></font> </div>
<div><font size="2" face="Arial">here is my baselayerchange event handler, which is
called with the map as scope.</font></div>
<div><font size="2" face="Arial"></font> </div>
<div><font size="2" face="Arial">function onBaseLayerChange(evtObj){<br>
var mapProj, baseProj, map, newBase, reproject;<br> map =
this;<br> newBase = evtObj.layer;<br> mapProj =
(map.projection && map.projection instanceof OpenLayers.Projection) ?
map.projection : new OpenLayers.Projection(map.projection);<br>
baseProj = newBase.projection;<br> reproject =
!(baseProj.equals(mapProj));<br> if (reproject)
{<br> var center,
maxExt;<br> //calc proper reporojected
center<br> center =
map.getCenter().transform(mapProj, baseProj);<br>
//calc correct reprojected extents<br> maxExt =
newBase.maxExtent;<br> //set map projection,
extent, & center of map to proper values<br>
map.projection = baseProj;<br> map.maxExtent =
maxExt;<br> map.setCenter(center);<br>
}<br>}</font></div>
<div><font size="2" face="Arial"></font> </div>
<div><font size="2" face="Arial">Matt Priour</font></div>
<div><font size="2" face="Arial">Kestrel Computer Consulting</font></div>
<div style="font:10pt Tahoma">
<div><br></div>
<div style="background:#f5f5f5">
<div><b>From:</b> <a title="hfpmartins@gmail.com" href="mailto:hfpmartins@gmail.com" target="_blank">Hugo</a> </div>
<div><b>Sent:</b> Monday, June 20, 2011 12:45 PM</div>
<div><b>To:</b> <a title="users@geoext.org" href="mailto:users@geoext.org" target="_blank">users@geoext.org</a> </div>
<div><b>Subject:</b> [Users] Programmatically changing the base map
projection</div></div></div><div><div></div><div class="h5">
<div><br></div>Dear Geoext users,<br><br>I'm trying to develop a functionality
that will allow the user to change the base map projection. The initial map is
using the spherical mercator projection so that OSM and Google/Yahoo/Bing layers
can be displayed. Because the users will need to edit features at specific
scales (1:25.000; 1:10.000) i need to develop a function that will change the
projection from spherical mercator to ETRS PTM06 (EPSG:3763). I think i'm almost
there but somehow, after reprojection the base map i get my map full extent much
higher in latitude (so, more to the north) and much smaller in longitude (more
to the west).<br><br>My steps are:<br>1. Remove all OSM/Google/Yahoo/Bing layers
from the map.<br>2. Add new options to the map<br>3. Merge new options
(projection) to a blank layer and set it as basellayer<br>4. Loop the remaining
layers and add new options.<br><br>The relevant part of the code is
below:<br><br>//Map options<br>var mapOptions = {<br>
maxExtent: bBox,<br> maxResolution:
305.74811309814453,<br> minResolution:
0.29858214169740677,<br> resolutions:
mapResolutions,<br> units: 'm',<br>
projection: baseMercator,<br> displayProjection:
wgs,<br> restrictedExtent: bBox,<br>
panMethod: OpenLayers.Easing.Quad.easeOut,<br> numZoomLevels:
20,<br> controls: []<br>};<br><br>var mapOptionsEtrs =
{<br> maxExtent: bBoxEtrs,<br>
maxResolution: 282.2220698223045,<br> minResolution:
0.35277758727788067,<br> resolutions:
mapResolutionsEtrs,<br> units: 'm',<br>
projection: etrs,<br> displayProjection:
etrs,<br> restrictedExtent: bBoxEtrs,<br>
panMethod: OpenLayers.Easing.Quad.easeOut,<br> numZoomLevels:
10,<br>};<br><br><br>//Reprojection logic<br>var radioValue =
Ext.getCmp('srsradiogroup').getValue().getGroupValue();<br>var mapProj =
map.getProjection();<br>var baseCart =
treePanel.getNodeById('basecartography');<br>if (radioValue != mapProj
&& radioValue == 'EPSG:3763') {<br>
baseCart.cascade(function () {<br> var
childNodes = this.childNodes;<br> for
(i = 0; i < childNodes.length; i++)
{<br> switch
(childNodes[i].text)
{<br> case
'OpenStreetMap':<br>
childNodes[i].disable();<br>
map.removeLayer(osm);<br>
break;<br>
case 'Google
Streets':<br>
childNodes[i].disable();<br>
map.removeLayer(gstreets);<br>
break;<br>
// and so
on...<br>
}<br> }<br>
});<br><br>
map.setOptions(mapOptionsEtrs);<br>
map.layerContainerOrigin.transform(baseMercator,
etrs);<br><br>
blankLayer.addOptions({<br>
projection: etrs<br> });<br>
map.setBaseLayer(blankLayer);<br><br> for (i = 0; i <
mapPanel.map.layers.length; i++) {<br>
var className =
mapPanel.map.layers[i].CLASS_NAME;<br>
if (className == 'OpenLayers.Layer.WMS')
{<br>
mapPanel.map.layers[i].addOptions({<br>
srs: etrs<br>
});<br> } else if (className ==
'OpenLayers.Layer.Vector')
{<br>
mapPanel.map.layers[i].projection =
etrs;<br> } else
{<br> //here i
will control other types of layers like
tilecache<br> }<br>
}<br>}<br><br>Checking the map and layers projection through firebug, it seems
everything is correct.<br>I've also tried to get the initial extent of the map,
reproject it and zoom to it after the reprojection but the it still goes to the
same place.<br><br>What might be the issues here?? Am i doing something
completely wrong?<br>Cheers,<br><br>Hugo<br>
<br><br clear="all"><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>
</div></div><p>
</p><hr>
<p></p>_______________________________________________<br>Users mailing
list<br><a href="mailto:Users@geoext.org" target="_blank">Users@geoext.org</a><br><a href="http://www.geoext.org/cgi-bin/mailman/listinfo/users" target="_blank">http://www.geoext.org/cgi-bin/mailman/listinfo/users</a><br>
<p></p></div>
</blockquote></div><br><br clear="all"><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>