小编stv*_*tvn的帖子

ol.interaction.Select 在 ol.source.VectorTile 上给出错误

选择 VectorTile 图层后,我正在尝试更改该要素的样式。但是第一次触发选择交互时控制台报错:

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)
Run Code Online (Sandbox Code Playgroud)

我研究了代码并意识到罪魁祸首可能是select事件下的功能不是 ol.Feature 而是 ol.render.Feature。后者没有 getId() 函数。然而,在第一次之后,modifyingCollection设置为 true 并且选择功能有效,但从未设置新的选择样式。

是否有不同的方法可以从 ol.source.VectorTile 中选择不会产生此错误的特征?

相关代码:

var select = new ol.interaction.Select({
    condition: ol.events.condition.click,
    multi: false,
    style: new ol.style.Style({
        fill: new ol.style.Fill({
            color: 'rgba(200,255,255,0.5)'
        })
    })
});

map.addInteraction(select);
    select.on('select', function(e) { …
Run Code Online (Sandbox Code Playgroud)

openlayers-3

2
推荐指数
1
解决办法
656
查看次数

标签 统计

openlayers-3 ×1