Openlayers 3 ol.interaction.Select在ol.source.VectorTile上出现错误

Openlayers 3 ol.interaction.Select在ol.source.VectorTile上出现错误,openlayers-3,Openlayers 3,我正在尝试在选择矢量文件层后更改其特征的样式。但是,首次触发选择交互时,控制台会报告一个错误: Uncaught TypeError: feature.getId is not a function at ol.source.Vector.addToIndex_ (ol-debug.js:66819) at ol.source.Vector.addFeatureInternal (ol-debug.js:66772) at ol.source.Vector.addFeature (ol-debu

我正在尝试在选择矢量文件层后更改其特征的样式。但是,首次触发选择交互时,控制台会报告一个错误:

Uncaught TypeError: feature.getId is not a function
at ol.source.Vector.addToIndex_ (ol-debug.js:66819)
at ol.source.Vector.addFeatureInternal (ol-debug.js:66772)
at ol.source.Vector.addFeature (ol-debug.js:66759)
at ol.source.Vector.<anonymous> (ol-debug.js:66919)
at ol.Collection.boundListener (ol-debug.js:3441)
at ol.Collection.ol.events.EventTarget.dispatchEvent (ol-debug.js:3859)
at ol.Collection.insertAt (ol-debug.js:12466)
at ol.Collection.push (ol-debug.js:12490)
at ol.Collection.extend (ol-debug.js:12402)
at ol.interaction.Select.handleEvent (ol-debug.js:70163)

您可以将
ol.format.MVT
配置为创建
ol.Feature
实例,而不是
ol.render.Feature
。这将使解析速度稍慢,但将为您提供具有
getId()
方法的功能:

format: new ol.format.MVT({
  featureClass: ol.Feature
})
还要注意,
ol.interaction.Select
将不允许您突出显示矢量平铺层上的功能。相反,使用
Map#forEachFeatureAtPixel
。您可以维护高亮显示的要素ID的对象文字或数组,并在样式函数中引用该对象或数组以对要素进行不同的样式设置


如果您准备创建拉取请求:将
getId()
方法添加到
ol.render.Feature
将是一个受欢迎的改进。

您可以配置
ol.format.MVT
来创建
ol.Feature
实例,而不是
ol.render.Feature
。这将使解析速度稍慢,但将为您提供具有
getId()
方法的功能:

format: new ol.format.MVT({
  featureClass: ol.Feature
})
还要注意,
ol.interaction.Select
将不允许您突出显示矢量平铺层上的功能。相反,使用
Map#forEachFeatureAtPixel
。您可以维护高亮显示的要素ID的对象文字或数组,并在样式函数中引用该对象或数组以对要素进行不同的样式设置

如果您准备创建拉取请求:将
getId()
方法添加到
ol.render.Feature
将是一个受欢迎的改进