<!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>Glad to see that worked out for you. I didn't
notice the restrictedExtent property on your base layer before.</FONT></DIV>
<DIV><FONT face=Arial size=2>Matt Priour</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 27, 2011 5:18 AM</DIV>
<DIV><B>To:</B> <A title=users@geoext.org
href="mailto:users@geoext.org">users@geoext.org</A> </DIV>
<DIV><B>Subject:</B> Re: [Users] Programmatically changing the base map
projection</DIV></DIV></DIV>
<DIV><BR></DIV>Hello again,<BR><BR>Just to give some feedback on this. I've
manged to correctly reproject the map using the code suggestions that Matt
pointed out. My problem was related with the restrictedExtent of the base map
that was bot being reprojected. So, the only thing i've added to the code that
Matt shared was the following:<BR><BR>map.restrictedExtent =
newBase.restrictedExtent;<BR><BR>After this, evryhting works fine.<BR><BR>Once
again, thanks for pointing me in the right
direction.<BR>Cheers,<BR><BR>Hugo<BR><BR>
<DIV class=gmail_quote>On Fri, Jun 24, 2011 at 3:45 PM, Hugo <SPAN
dir=ltr><<A
href="mailto:hfpmartins@gmail.com">hfpmartins@gmail.com</A>></SPAN>
wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><BR><BR>
<DIV class=gmail_quote>
<DIV class=im>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<DIV>
<DIV>
<DIV class=gmail_quote>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi
again,<BR><BR>I think i've spoken to early. Matt, after digging a little
bit more, your code suggestions are givinig me the same results as my
initial approach. The strange thing is that, using your code and firbug, i
see that the Center coordinates and bounding box for maxExtent are being
correctly reprojected. Nevertheless, the map is going to a different place
on earth (see attached images: mercator is ok but etrs is completely out).
</BLOCKQUOTE></DIV></DIV></DIV></BLOCKQUOTE></DIV>
<DIV><BR><A href="http://dl.dropbox.com/u/10817385/mercator.png"
target=_blank>http://dl.dropbox.com/u/10817385/mercator.png</A><BR><A
href="http://dl.dropbox.com/u/10817385/etrs.png"
target=_blank>http://dl.dropbox.com/u/10817385/etrs.png</A><BR> </DIV>
<DIV>
<DIV></DIV>
<DIV class=h5>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV>
<DIV>
<DIV class=gmail_quote>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">No
errors are shown in firebug and i'm a little bit lost. I have defined the
etrs layer like the following:<BR><BR>var ortos = new
OpenLayers.Layer.TileCache(<BR>
'Ortofotomapas ARH',<BR> '<A
href="http://localhost/tilecache"
target=_blank>http://localhost/tilecache</A>',<BR>
'Ortos',<BR>
{<BR> isBaseLayer:
true,<BR>
maxExtent: bBoxEtrs,<BR>
serverResolutions:
mapResolutionsEtrs,<BR>
visibility: false,<BR>
transparent:
true,<BR> scales:
[800000, 500000, 250000, 100000, 50000, 25000, 10000, 5000, 2500,
1000],<BR>
maxResolution:282.2220733500804,<BR>
minResolution:
0.35277758727788067,<BR>
units: 'm',<BR>
projection: etrs,<BR>
restrictedExtent:
bBoxEtrs<BR> }<BR>
);<BR><BR>I'm sure that this tilecache layer is working properly because
i've tested it on a simple openlayers app configured with the same
options.<BR><BR>Any hints on what might be happening??? Unfortunately, i
can't see what is going wrong and have no more alternative
ideas.<BR>Cheers,<BR><FONT color=#888888><BR>Hugo</FONT>
<DIV>
<DIV></DIV>
<DIV><BR><BR><BR>
<DIV class=gmail_quote>On Tue, Jun 21, 2011 at 2:42 PM, Hugo <SPAN
dir=ltr><<A href="mailto:hfpmartins@gmail.com"
target=_blank>hfpmartins@gmail.com</A>></SPAN> wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi
Matt,<BR><BR>That works like a charm ;)<BR>Really, thanks a lot for this
suggestion and code!<BR><BR>Cheers,<BR><FONT
color=#888888><BR>Hugo</FONT>
<DIV>
<DIV></DIV>
<DIV><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"
target=_blank>mpriour@kestrelcomputer.com</A>></SPAN> wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><U></U>
<DIV
style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; PADDING-TOP: 15px"
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><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>
<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></DIV></DIV></DIV></BLOCKQUOTE></DIV></DIV></DIV></BLOCKQUOTE></DIV></DIV></DIV></BLOCKQUOTE></DIV></DIV></DIV></BLOCKQUOTE></DIV></DIV></DIV>
<DIV>
<DIV></DIV>
<DIV class=h5><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></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>
<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>