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

时间:2018-05-22 08:35:58

标签: openlayers

如何在openlayers 2中更改悬停功能上的光标?它是"移动"默认情况下。

感谢。

1 个答案:

答案 0 :(得分:0)

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

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' : '';
});