2015-02-09 78 views
0

我創建了一個文本框,我可以放置座標X,Y,然後將該圖釘移動到該位置並查找哪些道路在那裏。Openlayers 3:爲什麼forEachFeatureAtPixel只返回一個特徵

引腳移動,但forEachFeatureAtPixel只返回一個功能,而不是四個。此外,我得到的功能沒有NOMBRE屬性

我使用的是Openlayer 3和我的WMS服務器映射。
正如您在MapInfo中所看到的(圖片右側),我獲得了所有4個功能。
水平2x「Calle 6」和垂直2x「Calle 1 Norte」,並具有NOMBRE屬性。
我在mapinfo中使用了所有4個特徵相同的x,y。

新的信息:我的層ol.layer.Tile代替ol.layer.Vector,或許這就是(檢查)

wmsLyr09 = new ol.layer.Tile({ 
    source: wmsSource 
}); 

enter image description here

// move the pin to new position 
geometry.translate(deltaX, deltaY); 

var coordinate = geometry.getCoordinates(); 
var pixel = map.getPixelFromCoordinate(coordinate); 
console.log('pixel: ' + pixel); 

var allFeaturesAtPixel = []; 
map.forEachFeatureAtPixel(pixel, function (feature) { 
    allFeaturesAtPixel.push(feature); 
}); 

// feature[len]:1 
console.log("feature[len]:" + allFeaturesAtPixel.length); 

//feature[Name]: undefined 
feature= allFeaturesAtPixel[0]; 
console.log("feature[Name]: " + feature.get('NOMBRE')); 

回答

1

在你的問題地圖你可能有兩層,WMS瓦片層和引腳的矢量層。所以,OpenLayers不知道道路特徵。如果您打電話給forEachFeatureAtPixel,您將獲得OpenLayers知道的唯一功能:引腳。

你想要做的是使WFS GetFeature請求獲取當前引腳位置的功能。看看這個例子:http://openlayers.org/en/master/examples/getfeatureinfo-tile.html

+0

WFS GetFeature,不帶幾何或允許選擇,是嗎?我更新我的工具,使該地區的幾條道路鏈接,並創建另一個時間矢量圖層,因此用戶可以選擇道路鏈接。 – 2015-02-10 18:38:32

+0

你也可以得到幾何。創建GetFeature請求並用'ol.format.GML'解析返回的GML:http://openlayers.org/en/master/apidoc/ol.format.GML.html?unstable=true – tsauerwein 2015-02-12 08:10:24

相關問題