我實際上遇到了一個我迄今無法解決的大問題。這是我的問題。我實際上有一個地圖,我在其上顯示標記(WMSGetFeatureInfo),這取決於我想顯示或隱藏的某些類別。OpenLayers:多層彈出問題
但是,事實上,我實際上將這些標記作爲* .map文件,它實際上是一個包含所有標記的PNG文件。
當我點擊一個標記,我得到的點擊位置,然後添加一個彈出。但是我在地圖上顯示的圖層越多,彈出窗口就越遠離相關標記。
這裏是一些代碼:
var layer = new OpenLayers.Layer.WMS(
category.label,
"/mapserv?Map=" + category.url,
{
layers : category.layer,
format : 'image/png',
version : '1.3.0',
srs : 'ESPG:3163'
},
{
isBaseLayer : false,
singleTile : true,
visibility : visibility,
}
);
var info = new OpenLayers.Control.WMSGetFeatureInfo({
title : 'get details by clicking',
layers : [ layer ],
infoFormat : "text/plain",
queryVisible : true,
eventListeners : {
getfeatureinfo : function(event){
document.body.style.cursor = 'auto';
var getId = function(text) {
result = context.settings.pattern.exec(text);
if(result == null) return;
return result[1];
}
var id = getId(event.text);
request = jQuery.ajax({
url : "/cartoweb/FicheTheme",
type : "get",
data : "idGeoEad="+id,
success : function(response, textStatus, jqXHR){
if (response == null || response['data'] == null) {
return;
}
context.generateAndShowPopup(event.xy, response['data']['metaData']);
}
});
},
beforegetfeatureinfo : function(event){
document.body.style.cursor = 'wait';
},
nogetfeatureinfo : function(event){
document.body.style.cursor = 'auto';
}
}
});
this.map.addControl(info);
info.activate();
generateAndShowPopup : function(latlong, text) {
var lonlatfrompx = this.map.getLonLatFromViewPortPx(latlong);
var anchor = {
'size' : new OpenLayers.Size(0,0),
'offset' : new OpenLayers.Pixel(-36, 6),
'keepInMap' : true
};
// Hide by default popup actually open
if(this.popup !== undefined) {
this.popup.hide();
}
// Create a new popup
this.popup = new OpenLayers.Popup.Anchored(
"chicken",
lonlatfrompx,
new OpenLayers.Size(2000, 2000),
'<div class="popupTail"></div><div class="popupContent">' + text + '</div>',
anchor,
false,
function(){}
);
// Popup settings
this.popup.setBackgroundColor('transparent');
this.popup.panMapIfOutOfView = true;
this.popup.calculateRelativePosition = function() { return 'tr'; }
// Add it on the map
this.map.addPopup(this.popup);
var that = this;
setTimeout(function(){
that.popup.updateSize();
}, 50);
this.map.setCenter(lonlatfrompx);
}
不知道如果我做錯了什麼,但如果有人已經面臨着同樣的問題,那將是非常有益的知道我做錯了什麼。
非常感謝
編輯
好了,所以我試圖重新投影層上的經緯度,但它仍然沒有工作。不過,我在進步:
// Layer is the layer associated to each WMSGetFeatureInfo
// this.layer is the base layer used to display the map
lonlatfrompx.transform(layer.projection, this.layer.projection);
this.map.setCenter(lonlatfrompx);
編輯1
好了,所以我在進步。我想我知道問題來自哪裏,但我仍然沒有看到/知道我將如何解決它(還)。
當intanciating info
變量,我做了一個ajax調用裏面將顯示一個彈出,當點擊。問題是,我添加的層越多,這個Ajax請求試圖獲取信息越多。假設我在地圖上顯示5個不同層(IT,設計,啓動,計算機和桌面)。然後,當我點擊標記(WMSGetFeatureInfo)時,它實際上會嘗試製作一個ajax request * [number of layers visible]
,然後在某個位置(有時)更改位置值。
爲了解決這個問題,我需要避免這個ajax請求被多次執行。有任何想法嗎?
感謝您的幫助。那很有意思。不過,既然我是Openlayer的新手,那我能做些什麼呢?我編輯我的帖子後,嘗試另一件事情,但仍然沒有成功:(謝謝 – lkartono
plz看到我的更新 – JSC
嗨,謝謝你的更新我使用ajax,因爲url是不同於WMS服務器'/ cartoweb/FicheTheme?idGeoEad ='。實際的系統不是基於服務器來檢索數據,所以我需要查詢一個包含ID的特定URL以獲取與標記相關的信息。我注意到的一個奇怪的行爲是,如果有例如在地圖上有3層,'eventListeners:getfeatureinfo'被執行3次,有時會返回多個值。在那一刻似乎中斷了。我嘗試使用'drillDown'但仍然不工作:(想想嗎? – lkartono