簡體   English   中英

openlayers從要素獲取圖層

[英]openlayers get layer from feature

我有一個選擇交互-選擇與矢量層關聯的要素。 我的目標是編輯要素屬性並將其保存回數據庫。

  import Map from 'ol/Map'; 
  import View from 'ol/View';
  import Select from 'ol/interaction/Select.js';

  ...

  this.map = new Map({
    target: 'map',
    view: new View({
      center: this.$root.mapState.center,
      zoom: this.$root.mapState.zoom
    })
  });
  AddLayers(this.map, this.$root.map.layers, this.$root.register);
  this.select = new Select();
  this.map.addInteraction(this.select);
  this.select.on('select', function(e) {
    e.target.getFeatures().forEach(function(feature) {
      alert('Selected ' + feature.getId());
    });
  });

如何從要素中獲取圖層?

從2015年開始, 這個問題的答案似乎奏效了。

我真的必須經歷所有這些嗎? 在OpenLayers 2中,我將引用feature.layer-此功能似乎已消失。

感謝@Mike,我在me.select.getLayer(feature)中的循環中添加了me.select.getLayer(feature)

完整的解決方案是:

  import Map from 'ol/Map'; 
  import View from 'ol/View';
  import Select from 'ol/interaction/Select.js';

  ...

  this.map = new Map({
    target: 'map',
    view: new View({
      center: this.$root.mapState.center,
      zoom: this.$root.mapState.zoom
    })
  });
  AddLayers(this.map, this.$root.map.layers, this.$root.register);
  this.select = new Select();
  this.map.addInteraction(this.select);
  var me = this;
  this.select.on('select', function(e) {
    e.target.getFeatures().forEach(function(feature) {
      var layer = me.select.getLayer(feature);
      alert('Selected ' + feature.getId());
    });
  });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM