Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

Openlayers 4.5 ImageVector points automatically clustering

OL Version 4.5: https://jsfiddle.net/70kd51gh/1/ OL Version 4.0.1: https://jsfiddle.net/7zs5dqcm/2/

The code in both jfiddles is exactly the same, the only difference is the OL version being used. For some reason, Version 4.5 is not allowing features to overlap each other, you can zoom in and out and watch them disappear. Version 4.0.1 everything works as expected. However, I cannot downgrade to 4.0.1 because of an unrelated bug that was fixed.

The issue is specific to ol.layer.Image, as ol.layer.Vector allows overlapping. However, I need to use ol.source.ImageVector for performance reasons.

Is there a workaround to allow the features to overlap each other?

var pointstyle = new ol.style.Style({
    image: new ol.style.Circle({
        radius: 7,
        fill: new ol.style.Fill({
            color: '#00ff00'
        }),
        stroke: new ol.style.Stroke({
            color: '#000',
            width: 1
        })
    })
});


var styleKeys = ['x', 'cross', 'star', 'triangle', 'square'];
var count = 250;
var features = new Array(count);
var e = 4500000;
for (var i = 0; i < count; ++i) {
  var coordinates = [2 * e * Math.random() - e, 2 * e * Math.random() - e];
  features[i] = new ol.Feature(new ol.geom.Point(coordinates));
}

var source = new ol.source.Vector({
  features: features
});

var vectorLayer = new ol.layer.Image({
  source: new ol.source.ImageVector({source: source, style: pointstyle})
});

var map = new ol.Map({
  layers: [
    vectorLayer
  ],
  target: 'map',
  view: new ol.View({
    center: [0, 0],
    zoom: 2
  })
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

ol.source.ImageVector is deprecated from v4.5.0
check upgrade note

fix your code to:

var vectorLayer = new ol.layer.Vector({
  renderMode: 'image',
  source: source,
  style: pointstyle
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...