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="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br><br><div class="gmail_quote"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
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="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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="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 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>