如何在Openlayers 3中从矢量层获取特征信息
在如何在Openlayers 3中从矢量层获取特征信息,openlayers,Openlayers,在Openlayers 2的情况下,我能够获取特征信息,但如何从Openlayers 3中的向量层获取特征信息 下面的代码如何提取功能的信息 var layerWFS = new ol.layer.Vector({ source: new ol.source.Vector({ loader: function(extent) { $.ajax('http://localhost:8080/geoserver/wfs', { type: 'GET',
Openlayers 2
的情况下,我能够获取特征信息,但如何从Openlayers 3
中的向量层获取特征信息
下面的代码如何提取功能的信息
var layerWFS = new ol.layer.Vector({
source: new ol.source.Vector({
loader: function(extent) {
$.ajax('http://localhost:8080/geoserver/wfs', {
type: 'GET',
data: {
service: 'WFS',
version: '1.1.0',
request: 'GetFeature',
typename: 'dgm:all_block_boundary_point',
srsname: 'EPSG:3857',
bbox: extent.join(',') + ',EPSG:3857'
}
}).done(function(response) {
layerWFS
.getSource()
.addFeatures(new ol.format.WFS()
.readFeatures(response));
// console.log(response);
});
},
strategy: ol.loadingstrategy.bbox,
projection: 'EPSG:3857'
})
});
map.addLayer(layerWFS);
您可以使用获取所有特性或特定特性的特征信息 编辑:看起来他想通过选择检索特征信息。下面是OP的解决方案 我通过使用
ol.interaction.Select()
欢迎来到StackOverflow。如果不看看你做了什么,别人就很难知道你到底有什么问题。请看一下如何添加一些代码。您的解决方案是当用户单击图层时。如果我们想在层加载属性。我做了类似于var att=sourceWFS.getProperties()的事情;var attStr=att.state;警报(ATTSR);但它不返回属性
var selectSingleClick = new ol.interaction.Select();
map.addInteraction(selectSingleClick);
map.on('singleclick', function(event){
layerWFS.getProperties();
layerWFS.once('precompose',function(event){
var selectedFeatures = selectSingleClick.getFeatures();
readFeature(selectedFeatures);
});
});
function readFeature(features){
var myfeature = features.item(0);
console.log(myfeature.get('block_name'));
console.log(myfeature.get('latitude'));
console.log(myfeature.get('longitude'));
}