显示点击后的功能名称矢量图层
答
这些例子看看:
1)http://openlayers.org/en/v3.14.1/examples/vector-layer.html?q=overlay
2)http://openlayers.org/en/v3.14.1/examples/popup.html?q=overlay
而不是把旁边的矢量信息,以地图的,你把它放在<div>
您创建的弹出窗口。
答
为了这个目的我使用了here这个库。示例代码
var popup = new ol.Overlay.Popup();
map.addOverlay(popup);
//handling Onclick popup
map.on('click', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature, layer) {
return feature;
});
if (feature) {
var coord = event.feature.getGeometry().getCoordinates();
popup.show(coord, '<div><h2>Tilte</h2><p>' +feature.get('<property_in_single_quotes>')+ '</p></div>');
}
});
希望这有助于
谢谢,它的工作原理!我这样写道:map.on( '点击',功能(E){VAR 功能= map.forEachFeatureAtPixel(e.pixel,功能(功能){ 收益特征; }); VAR infoElement = document.getElementById('info'); infoElement.innerHTML = feature?feature.get('gml_id'):'';我只想显示更多的功能,不仅仅是'gml_id'。我应该怎么写? – Agnieszka
I认为你可以使用jquery append()追加为feature.get('') –
KcYoosuf
哪里exacly我必须把append()? – Agnieszka