我使用的OpenLayers顯示一大堆烏拉圭層,即來自WMS的..我想補充一點,你可以使用兩種不同的基礎層的選項。 其中之一是谷歌的衛星層,其球形墨卡託900913 ..然後,我有地圖烏拉圭的這是UTM21S 32721 .. 我的問題似乎是,當我試圖改變基層。我在顯示Google衛星時添加到地圖上的wms圖層(例如烏拉圭的路線)似乎消失了。同樣的事情發生時,我嘗試其他方式,對UTM21S加載圖層並改變谷歌的衛星.. 爲了解決這個問題,我試圖傾聽改變基層的事件..下面的代碼:的OpenLayers重投影
function mapBaseLayerChanged(event) {
var pseudo = new OpenLayers.Projection('EPSG:900913');
var utm21s = new OpenLayers.Projection('EPSG:32721');
var baseLayer = "EPSG:900913";
if(event.layer.name == "Google Satellite"){
map.projection = pseudo;
map.maxExtent = new OpenLayers.Bounds(-6522200,-4170000,-5890000,-3510000);
}else{
baseLayer = "EPSG:32721";
map.projection = utm21s;
map.maxExtent = new OpenLayers.Bounds(300000, 6100000, 900000, 6750000);
}
for(i = 0 ; i < map.layers.length; i++){
if (map.layers[i].visibility && !map.layers[i].isBaseLayer && !map.layers[i].isVector) { // Refresh visible non base
if(baseLayer == "EPSG:900913"){
map.layers[i].projection = pseudo;
}else{
map.layers[i].projection = utm21s;
}
map.layers[i].redraw(true); // Other layer
}
alert(map.layers[i].projection);
}
//alert(map.getProjection());
map.zoomToMaxExtent();
}
當我運行此代碼時,圖層的投影似乎改變,但同樣的問題發生.. 在此先感謝!
更新:
試圖使它與此,但沒有工作:
if(baseLayer == "EPSG:900913"){
map.layers[i].addOptions({
srs: 'EPSG:900913',
format:'png',
trnsparent: true,
},true);
//map.layers[i].projection = pseudo;
}else{
map.layers[i].addOptions({
srs: 'EPSG:32721',
format:'png',
trnsparent: true,
},true);
//map.layers[i].projection = utm21s;
}
改變的參數SRS投影和那樣的伎倆..該函數的代碼是現在:
function mapBaseLayerChanged(event) {
var pseudo = new OpenLayers.Projection('EPSG:900913');
var utm21s = new OpenLayers.Projection('EPSG:32721');
var baseLayer = "EPSG:900913";
if(event.layer.name == "Google Satellite"){
map.projection = pseudo;
map.maxExtent = new OpenLayers.Bounds(-6522200,-4170000,-5890000,-3510000);
}else{
baseLayer = "EPSG:32721";
map.projection = utm21s;
map.maxExtent = new OpenLayers.Bounds(300000, 6100000, 900000, 6750000);
}
for(i = 0 ; i < map.layers.length; i++){
if (map.layers[i].visibility && !map.layers[i].isBaseLayer && !map.layers[i].isVector) { // Refresh visible non base
if(baseLayer == "EPSG:900913"){
map.layers[i].addOptions({
projection: pseudo,
format:'png',
trnsparent: true,
},true);
}else{
map.layers[i].addOptions({
projection: utm21s,
format:'png',
trnsparent: true,
},true);
}
}
}
map.zoomToMaxExtent();
}
您是否包含Proj4JS?如果我正確地記住了這一點,OpenLayers只支持EPSG:900913和WGS:84,如果您使用其他投影,則必須包含Proj4JS。 – 2012-08-06 14:35:08
感謝您的回答!是的,投影已經被添加,否則我的烏拉圭層無法顯示.. – 2012-08-06 14:37:57
請問,如果你使用[addOptions(http://dev.openlayers.org/docs/files/OpenLayers/Layer-js它的工作。 HTML#OpenLayers.Layer.addOptions)?也許這會初始化所需的一切。 – 2012-08-06 14:45:49