use*_*609 7 javascript dom-events mapbox mapbox-gl mapbox-gl-js
我使用 MapboxGL.js,当点击多边形时我想调用我的函数(例如,打开弹出窗口)。
在移动设备上,事件发生时出现错误touchstart(jsfiddle 脚本中的第 103 行):
“无法阻止被动事件侦听器调用内的默认”。
谁能解释一下为什么这个错误出现在手机上而不是台式电脑上?
map.on('touchstart', 'places', function(e) {
const features_in_point = map.queryRenderedFeatures(
[e.point.x, e.point.y],
{
layers: ['places']
}
);
const selected_ids = features_in_point.map(f => f.id);
const selected_features = PLACES_GEOJSON.features.filter(f => selected_ids.includes(f.id))
draw.deleteAll();
draw.add({
'type': 'FeatureCollection',
'features': selected_features
});
});
Run Code Online (Sandbox Code Playgroud)
这是带有示例的 JSfiddle:
https ://jsfiddle.net/petrovnn/ose40zpL/2/