我看到可以通过点击或单击或指针移动来完成ol交互 - 但是,是否可以使用mousedown / mouseup完成?简而言之,我们希望用户只要单击鼠标按钮就可以编辑功能,但在鼠标按钮释放时保存/停止。
featureRotateDown = new ol.interaction.Select({
condition: ol.events.condition.pointerdown
});
featureRotateUp = new ol.interaction.Select({
condition: ol.events.condition.pointerup
});
map.addInteraction(featureRotateDown);
map.addInteraction(featureRotateUp);
featureRotateDown.on('select', function(event) {
$.each(event.selected, function (index, feature) {
console.log(feature);
console.log('1');
});
});
featureRotateUp.on('select', function(event) {
$.each(event.selected, function (index, feature) {
console.log(feature);
console.log('3');
});
});
换句话说,想象一下放置在地图上的标记是箭头。当光标在标记上并按下鼠标按钮时,我希望能够根据需要旋转它。
答案 0 :(得分:1)
尝试pointerdown
和pointerup
:
map.on('pointerdown', function (event) {
// doStuff...
// ALTERNATIVE 1: get a feature at click position (with very small tolerance)
map.forEachFeatureAtPixel(event.pixel, function(feature, layer){
// doStuff with your feature at click position
});
// ALTERNATIVE 2: get the closest feature
closestFeature = yourVectorSource.getClosestFeatureToCoordinate(event.coordinate);
})
map.on('pointerup', function (event) {
// doStuff...
})
在这些功能中,您可以使用forEachFeatureAtPixel
或getClosestFeatureToCoordinate
来访问这些功能。
另请参阅此JSFiddle