Vector 单击矢量图层后显示要素名称
我是Openlayers 3的新手。我从geojson文件导入了矢量层。我想在点击vector layer后显示有关我的功能的信息。Vector 单击矢量图层后显示要素名称,vector,geojson,openlayers-3,Vector,Geojson,Openlayers 3,我是Openlayers 3的新手。我从geojson文件导入了矢量层。我想在点击vector layer后显示有关我的功能的信息。 你知道我该怎么做吗?看看这些例子: (一) (二) 不是将矢量信息放在地图旁边,而是将其放在您创建的弹出窗口中。为此,我使用了中的库。示例代码是 var popup = new ol.Overlay.Popup(); map.addOverlay(popup); //handling Onclick popup map.on('click', function(
你知道我该怎么做吗?看看这些例子: (一) (二) 不是将矢量信息放在地图旁边,而是将其放在您创建的弹出窗口中。为此,我使用了中的库。示例代码是
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>');
}
});
var popup=new ol.Overlay.popup();
map.addOverlay(弹出窗口);
//处理Onclick弹出窗口
映射打开('click',函数(evt){
var feature=map.forEachFeatureAtPixel(evt.pixel,
功能(特征、图层){
返回特性;
});
如果(功能){
var coord=event.feature.getGeometry().getCoordinates();
popup.show(坐标,'Tilte'+特性.get('''++'');
}
});
希望这有帮助谢谢,它很有效!我是这样写的:map.on('click',function(e){var feature=map.forEachFeatureAtPixel(e.pixel,function(feature){return feature;});var infoElement=document.getElementById('info');infoElement.innerHTML=feature?feature.get('gml_id')):“”;我只想显示更多的功能,而不仅仅是“gml_id”。我应该如何编写它?我想你可以使用jquery append()和feature.get(“”)一起用于附加功能。get(“”)这里我必须放append()?类似于下面的代码片段
$(“#info”)。append('Title:'+feature.get('gml#id'))+“
Title:”+feature.get('gml_id_2'))
Instend of infoElement.innerHTML=feature?feature.get('gml_id'):”;使用此$('info”).append('Title:“+feature.get('gml_id')+”Title:“+feature.get('gml_id_2'))。