在这里映射指针不工作与折线组,但tap工作



我尝试做箭头折线(像这里https://developer.here.com/documentation/maps/3.1.30.17/dev_guide/topics/routing.html ->显示路线方向箭头)。我想添加到这个routeLine pointerenter事件,让它保持和拖动来添加端点并重新计算道路。然后我添加了pointinterevents,什么也没发生。点击是工作的,但指针没有。我发现只有一个解决方案是使用使用MapEvents,但我有它导入https://js.api.here.com/v3/3.1/mapsjs-mapevents.js,所以,据我所知,它应该工作。

现在我的代码很简单:

displayOnMap(result) {
if (result.routes.length) {
result.routes[0].sections.forEach((section) => {
let linestring = H.geo.LineString.fromFlexiblePolyline(section.polyline)
let routeOutline = new H.map.Polyline(linestring, {
style: {
lineWidth: 10,
strokeColor: 'rgba(0, 128, 255, 0.7)',
lineTailCap: 'arrow-tail',
lineHeadCap: 'arrow-head'
}
});
let routeArrows = new H.map.Polyline(linestring, {
style: {
lineWidth: 10,
fillColor: 'white',
strokeColor: 'rgba(255, 255, 255, 1)',
lineDash: [0, 2],
lineTailCap: 'arrow-tail',
lineHeadCap: 'arrow-head'
}
}
);
let routeLine = new H.map.Group({
volatility: true,
objects: [routeOutline, routeArrows]
})
//why pointerenter is not working?
routeLine.addEventListener('pointerenter', function(evt) {
console.log('test 123', evt) 
})
let startMarker = new H.map.Marker(section.departure.place.location)
let endMarker = new H.map.Marker(section.arrival.place.location)
this.routeObjects = [routeLine, startMarker, endMarker]
this.map.addObjects(this.routeObjects)
this.map.setCenter(section.departure.place.location)
})
}
};

好的,我找到了一个解决方案。在这种情况下,addEventListener需要第三个参数(opt_capture)设置为"true"。感谢这个组范围监听事件监听器。

routeLine.addEventListener('pointerenter', function(evt) {
console.log('test 123', evt) 
}, true) //<- this true is a key

最新更新