【问题标题】:Openlayer clustering with different color of image不同颜色图像的Openlayer聚类
【发布时间】:2018-06-19 10:24:43
【问题描述】:

所以基本上我有数百个包含几何的特征。我希望地图能够聚集不同颜色的点。

这是特征和颜色:

//so both features and color contain several hundred of value
features.push(new ol.Feature(new ol.geom.Point([random_x, random_y])));
color.push(random_color)

然后对于每个特征[i],它应该以颜色[i] 显示在地图中。 这是目前正在工作的代码,它只显示一种颜色,我应该如何改变让每个点显示自己的颜色并且它仍然可以保持聚类功能?请帮忙。

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

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

var styleCache = {};
var clusters = new ol.layer.Vector({
    name: 'clusterlayer',
    source: clusterSource,
    style: function(feature) {
        var size = feature.get('features').length;
        var style = styleCache[size];
        if (!style) {
            style = [new ol.style.Style({
                image: new ol.style.Circle({
                    radius: 10,
                    fill: new ol.style.Fill({
                        color: '#000000'
                    })
                }),

                text: new ol.style.Text({
                    font: 'bolder',
                    text: size.toString(),
                    fill: new ol.style.Fill({
                        color: '#000000',
                    })
                })
            })];
            styleCache[size] = style;
        }
        return style;
    }
});
this.state.map.addLayer(clusters);

对于更高级的工作,我应该怎么做,像一个红蓝圆圈点,当聚类时,它会显示一个像绿色圆圈这样的东西。

【问题讨论】:

    标签: colors openlayers openlayers-3 layer markerclusterer


    【解决方案1】:

    你可以看看这个例子http://viglino.github.io/ol-ext/examples/map/map.clustering.html

    根据包含的内容切割圆圈以反映颜色。

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      • 2020-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      相关资源
      最近更新 更多