在Openlayers 2中更改功能悬停光标

在Openlayers 2中更改功能悬停光标,openlayers,Openlayers,如何在openlayers 2中更改光标悬停功能?默认为“移动” 谢谢。您可以根据光标下方的功能,监听指针移动并更改样式 : map.on('pointermove', (evt) => { if (evt.dragging) { // the event is a drag gesture, this is handled by openlayers (map move) return; } const pixel = this.map.getEventPix

如何在openlayers 2中更改光标悬停功能?默认为“移动”


谢谢。

您可以根据光标下方的功能,监听指针移动并更改样式 :

map.on('pointermove', (evt) => {
  if (evt.dragging) {
    // the event is a drag gesture, this is handled by openlayers (map move)
    return;
  }
  const pixel = this.map.getEventPixel(evt.originalEvent);
  const feature = this.map.forEachFeatureAtPixel(
    pixel,
    someFeature => someFeature // returns first element,
    {
        // optional: only look at specific layers
        layerFilter: function(layer) { return true; }
    }
  );

  // change the cursor style
  this.map.getTarget().style.cursor = feature ? 'pointer' : '';
});