首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Openlayer 3集群放大后重叠

Openlayer 3集群放大后重叠
EN

Stack Overflow用户
提问于 2018-02-22 18:51:41
回答 1查看 374关注 0票数 0

我得到1000个点(大约),并显示在地图上与自定义图标以及聚类,但虽然聚类有时它是重叠的。如果我将集群的距离增加到70,则没有集群重叠。我想要实现这一点,因为距离30或40的集群this.abc是数据源

代码语言:javascript
复制
    var vectorSource = new ol.source.Vector({});
    var i = 0;


this.abc.forEach(element => {
        i++;
        var latitude = element[0];
        var longitude = element[0];
        var iconFeature = new ol.Feature({
            geometry: new 
            ol.geom.Point(ol.proj.transform([parseFloat(latitude), 
            parseFloat(longitude)], 'EPSG:4326', 'EPSG:3857')),
            data: element,
            name: layerselection + i
        });
        vectorSource.addFeature(iconFeature);
    });



var clusterSource = new ol.source.Cluster({
        distance: 30,
        source: vectorSource
    });
    var styleCache = {};

     //create the style
    var iconSuccessStyle = new ol.style.Style({
        image: new ol.style.Icon(/** @type {olx.style.IconOptions} */({
            anchor: [0.5, 46],
            anchorXUnits: 'fraction',
            anchorYUnits: 'pixels',
            opacity: 0.75,
            src: './assets/img/xyz.svg'

        }))
    });

    this.vectorLayer1 = new ol.layer.Vector({
        source: clusterSource,
        style: function (feature) {
            var size = feature.get('features').length;
            var style = styleCache[size];

            if (size == 1) {
                style = iconSuccessStyle;
                if (!styleCache[size]) {
                    styleCache[size] = {};
                }
                styleCache[size]['Green'] = style;
            }


else if (!style) {
                style = new ol.style.Style({
                    image: new ol.style.Circle({
                        radius: 16,
                        stroke: new ol.style.Stroke({
                            color: '#84B1A1',
                            width: 4
                        }),
                        fill: new ol.style.Fill({
                            color: '#00584D'
                        })
                    }),
                    text: new ol.style.Text({
                        text: size.toString(),
                        fill: new ol.style.Fill({
                            color: '#fff'
                        })
                    })
                });
                styleCache[size] = style;
            }
            return style;
        }
    });
self.map = new ol.Map({
    layers: [new ol.layer.Tile({ source: new ol.source.OSM({ "url":
         "https://mmmm.../World_Street_Map/MapServer/tile/{z}/{y}/{x}" 
        }) }), this.vectorLayer],
    target: document.getElementById('map'),
    controls: [],
    view: new ol.View({
        center: ol.proj.transform([10.4515, 51.1657], 
        'EPSG:4326','EPSG:3857'),
        zoom: 5
    })
});

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2019-02-07 05:31:37

我在Openlayers 5中也遇到过同样的问题。不幸的是,我找不到一个完全解决这个问题的解决方案。但是,您可以通过增加"distance“属性的值来缓解它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48925554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档