[Users] Programmatically changing the base map projection
Hugo
hfpmartins at gmail.com
Mon Jun 20 19:45:23 CEST 2011
Dear Geoext users,
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).
My steps are:
1. Remove all OSM/Google/Yahoo/Bing layers from the map.
2. Add new options to the map
3. Merge new options (projection) to a blank layer and set it as basellayer
4. Loop the remaining layers and add new options.
The relevant part of the code is below:
//Map options
var mapOptions = {
maxExtent: bBox,
maxResolution: 305.74811309814453,
minResolution: 0.29858214169740677,
resolutions: mapResolutions,
units: 'm',
projection: baseMercator,
displayProjection: wgs,
restrictedExtent: bBox,
panMethod: OpenLayers.Easing.Quad.easeOut,
numZoomLevels: 20,
controls: []
};
var mapOptionsEtrs = {
maxExtent: bBoxEtrs,
maxResolution: 282.2220698223045,
minResolution: 0.35277758727788067,
resolutions: mapResolutionsEtrs,
units: 'm',
projection: etrs,
displayProjection: etrs,
restrictedExtent: bBoxEtrs,
panMethod: OpenLayers.Easing.Quad.easeOut,
numZoomLevels: 10,
};
//Reprojection logic
var radioValue = Ext.getCmp('srsradiogroup').getValue().getGroupValue();
var mapProj = map.getProjection();
var baseCart = treePanel.getNodeById('basecartography');
if (radioValue != mapProj && radioValue == 'EPSG:3763') {
baseCart.cascade(function () {
var childNodes = this.childNodes;
for (i = 0; i < childNodes.length; i++) {
switch (childNodes[i].text) {
case 'OpenStreetMap':
childNodes[i].disable();
map.removeLayer(osm);
break;
case 'Google Streets':
childNodes[i].disable();
map.removeLayer(gstreets);
break;
// and so on...
}
}
});
map.setOptions(mapOptionsEtrs);
map.layerContainerOrigin.transform(baseMercator, etrs);
blankLayer.addOptions({
projection: etrs
});
map.setBaseLayer(blankLayer);
for (i = 0; i < mapPanel.map.layers.length; i++) {
var className = mapPanel.map.layers[i].CLASS_NAME;
if (className == 'OpenLayers.Layer.WMS') {
mapPanel.map.layers[i].addOptions({
srs: etrs
});
} else if (className == 'OpenLayers.Layer.Vector') {
mapPanel.map.layers[i].projection = etrs;
} else {
//here i will control other types of layers like tilecache
}
}
}
Checking the map and layers projection through firebug, it seems everything
is correct.
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.
What might be the issues here?? Am i doing something completely wrong?
Cheers,
Hugo
--
Hugo Martins
LabNT - ISEGI UNL
Campus de Campolide
1070-312 Lisboa
N 38°43'56.84", W 9°9'35.74"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20110620/e8f6dd7f/attachment.htm
More information about the Users
mailing list