ol.interaction.Draw 鼠标移动的条件?

ol.interaction.Draw condition on mouse move?

我正在使用 ol.interaction.Draw 在地图上绘制新要素,但地图上也已经存在要素。我希望用户在鼠标悬停在现有功能上时无法放置新功能。

现在我在 Draw 交互上使用 condition,当它设置在已经存在特征的像素上时 returns false。但是当只是将鼠标移到这些像素上时,它的样式仍然像用户能够在那里放置标记一样。是否有类似 condition 的东西在每次鼠标移动时检查,而不仅仅是在单击时检查?

更新:我目前的情况是:

condition: function(e) {
  var isFirstOne = true;
  var feature = map.forEachFeatureAtPixel(e.pixel, function(feature) {
    var n = feature.get('name');
    // if n is undefined, feature is the current drawing one
    if (!!n) return feature;
  });
  return (!feature);
}

Is there something like condition which is checked at every mouse move not just at a click?

是的,您可以使用 pointermove,并更改光标(通过 CSS):

map.on('pointermove', function(e) {
  if (e.dragging) return;
  var hit = map.hasFeatureAtPixel(map.getEventPixel(e.originalEvent));
  map.getTargetElement().style.cursor = hit ? 'pointer' : '';
});