简体   繁体   中英

OpenLayers: how can be ol.FeatureOverlay replaced in 3.13v?

Here there is an overlay feature example.

It doesn't work on 3.13 OpenLayers version because of no more supported ol.FeatureOverlay.

How can be it replaced? Could you give me an example?

Copied & Pasted from changelog/v3.7.0.md

Instead of an ol.FeatureOverlay , we now use an ol.layer.Vector with an ol.source.Vector . If you previously had:

var featureOverlay = new ol.FeatureOverlay({
  map: map,
  style: overlayStyle
});
featureOverlay.addFeature(feature);
featureOverlay.removeFeature(feature);
var collection = featureOverlay.getFeatures();

you will have to change this to:

var collection = new ol.Collection();
var featureOverlay = new ol.layer.Vector({
  map: map,
  source: new ol.source.Vector({
    features: collection,
    useSpatialIndex: false // optional, might improve performance
  }),
  style: overlayStyle,
  updateWhileAnimating: true, // optional, for instant visual feedback
  updateWhileInteracting: true // optional, for instant visual feedback
});
featureOverlay.getSource().addFeature(feature);
featureOverlay.getSource().removeFeature(feature);

I had the same issue. There is an updated example on OpenLayers website for the latest version ( Vector Layer - v3.14.2 ) where features are highlighted on mouseover.

对于 OL 6.3.1 Vector Layer演示了鼠标悬停时的突出显示

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM