我有用蓝色显示 7 个点的代码。现在我需要显示 7 个不同颜色的点(例如 2 个红色点、2 个绿色点和 3 个蓝色点)。我也需要对这些点进行点聚类工作。
我的代码: https ://codepen.io/quas1k/pen/WgWRNE
var coordinates = ol.proj.fromLonLat([30.5238, 50.45466]);
var coordinates1 = ol.proj.fromLonLat([30.5238, 50.45166]);
var coordinates2 = ol.proj.fromLonLat([30.5538, 50.45466]);
var coordinates3 = ol.proj.fromLonLat([30.5518, 50.45466]);
var coordinates4 = ol.proj.fromLonLat([30.5558, 50.45466]);
var coordinates5 = ol.proj.fromLonLat([30.5598, 50.45466]);
var coordinates6 = ol.proj.fromLonLat([30.5510, 50.45466]);
var coordinates7 = ol.proj.fromLonLat([30.5580, 50.45466]);
var features = [];
features[0] = new ol.Feature(new ol.geom.Point(coordinates));
features[1] = new ol.Feature(new ol.geom.Point(coordinates1));
features[2] = new ol.Feature(new ol.geom.Point(coordinates2));
features[3] = new ol.Feature(new ol.geom.Point(coordinates3));
features[4] = new ol.Feature(new ol.geom.Point(coordinates4));
features[5] = new ol.Feature(new ol.geom.Point(coordinates5));
features[6] = new ol.Feature(new ol.geom.Point(coordinates6));
features[7] = new ol.Feature(new ol.geom.Point(coordinates7));
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({
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: 12,
stroke: new ol.style.Stroke({
color: '#fff'
}),
fill: new ol.style.Fill({
color: '#3399CC'
})
}),
text: new ol.style.Text({
text: size.toString(),
fill: new ol.style.Fill({
color: '#fff'
})
})
});
styleCache[size] = style;
}
return style;
}
});
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
layers: [raster, clusters],
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([30.5238, 50.45466]),
zoom: 11
})
});
如何更改此代码以实现所描述的行为?我在以不同颜色显示点并进一步按颜色对它们进行聚类时遇到问题。