在mapbox gl中使用getSource或getLayer获取几何(coord)

时间:2017-08-30 14:03:01

标签: mapbox mapbox-gl-js

我有5个geojson图层 - 每个图层都有一行。我想用map.getSource或map.getLayer获取该行的坐标,但我没有看到任何几何属性。 我可以用这个得到坐标:

# BOTH
class RecordNotUnique < WrappedDatabaseException
end
class WrappedDatabaseException < StatementInvalid
end

# 4.2.7.1
class StatementInvalid < ActiveRecordError
  def initialize(message = nil, original_exception = nil)
    if original_exception
      ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \
                                      "Exceptions will automatically capture the original exception.", caller)
    end
    super(message || $!.try(:message))
  end  
  def original_exception
    ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller)
    cause
  end
end
# 5.1.3
class StatementInvalid < ActiveRecordError
  def initialize(message = nil)
    super(message || $!.try(:message))
  end
end

我的geojson是:

var features = map.queryRenderedFeatures({layers:[layerName]});
console.log(features[0].geometry); 

2 个答案:

答案 0 :(得分:2)

getSourcegetLayer并非用于检索源数据;访问源数据的唯一方法是使用queryRenderedFeaturesquerySourceFeatures

答案 1 :(得分:1)

文档对此很模糊,但我找到了一种方法:

var feature = map.getSource('yoursourceid')._options.data;

数据源的 _options.data 属性保存要素的等效数据。