首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Openlayers 3中如何从矢量层中获取特征信息

Openlayers 3中如何从矢量层中获取特征信息
EN

Stack Overflow用户
提问于 2018-05-30 15:33:35
回答 1查看 1.4K关注 0票数 1

Openlayers 2的情况下,我可以获取要素信息,但如何在Openlayers 3中从矢量图层获取要素信息

下面的代码如何提取特征信息?

代码语言:javascript
复制
 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);
EN

回答 1

Stack Overflow用户

发布于 2018-06-01 14:15:13

您可以使用feature.getProperties()获取所有属性,也可以使用feature.get()获取特定属性的特性信息。

编辑:看起来他想通过选择来检索特征信息。以下是OP的解决方案。

我已经通过使用ol.interaction.Select()找到了解决方案

代码语言:javascript
复制
 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'));
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50598847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档