<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content=text/html;charset=iso-8859-1>
<META content="MSHTML 6.00.6002.18457" name=GENERATOR></HEAD>
<BODY id=MailContainerBody
style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; PADDING-TOP: 15px" leftMargin=0
topMargin=0 CanvasTabStop="true" name="Compose message area">
<DIV><FONT face=Arial size=2>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 face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>here is my baselayerchange event handler, which is
called with the map as scope.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>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 face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Matt Priour</FONT></DIV>
<DIV><FONT face=Arial size=2>Kestrel Computer Consulting</FONT></DIV>
<DIV style="FONT: 10pt Tahoma">
<DIV><BR></DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=hfpmartins@gmail.com
href="mailto:hfpmartins@gmail.com">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">users@geoext.org</A> </DIV>
<DIV><B>Subject:</B> [Users] Programmatically changing the base map
projection</DIV></DIV></DIV>
<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>
<P>
<HR>
<P></P>_______________________________________________<BR>Users mailing
list<BR>Users@geoext.org<BR>http://www.geoext.org/cgi-bin/mailman/listinfo/users<BR></BODY></HTML>