gpt4 book ai didi

javascript - 使用此处的 map 对噪声标记使用不同的颜色

转载 作者:行者123 更新时间:2023-12-03 10:33:43 25 4
gpt4 key购买 nike

使用此处的 map API 进行聚类时是否可以对不同的噪声标记应用不同的颜色?

有一个theming option可用,但这适用于所有标记。我想根据某些条件为特定点设置特定颜色。

最佳答案

使用自定义主题当然可以实现这一点。 H.clustering.DataPoint 对象的定义包括 data() method它可以保存任意数据。

准备数据集时,您可以按如下所示添加它:

var dataPoints = [];

dataPoints.push(new H.clustering.DataPoint(lat, lng, null, {color :'red'}));
dataPoints.push(new H.clustering.DataPoint(lat, lng, null, {color :'green'}));
dataPoints.push(new H.clustering.DataPoint(lat, lng, null, {color :'blue'}));
// etc ...

如果您使用自定义主题,您可以从噪声点读取数据并按您认为合适的方式显示:

function colorfulClusteringTheme() {
var baseTheme = new H.clustering.DefaultTheme();
this.getClusterPresentation = function (cluster) {

var clusterIcon = baseTheme.getClusterPresentation(cluster).getIcon();
return new H.map.Marker(cluster.getPosition(), {
icon: clusterIcon,
min: cluster.getMinZoom(),
max: cluster.getMaxZoom()
});

};
this.getNoisePresentation = function (noisePoint) {
if (noisePoint.data.color === 'red'){
// add red noise point
return new H.map.Marker(noisePoint.getPosition(), { icon: redIcon });
}
if (noisePoint.data.color === 'green'){
// add red marker
return new H.map.Marker(noisePoint.getPosition(), { icon: greenIcon });
}
if (noisePoint.data.color === 'blue'){
// add blue noise point
return new H.map.Marker(noisePoint.getPosition(), { icon: blueIcon });
}
};
};

您可以按照通常的方式将主题添加到 map :

var clusteredDataProvider = new H.clustering.Provider(dataPoints, {
clusteringOptions: {
eps: 16,
minWeight: 5
},
theme: new colorfulClusteringTheme()
});

var clusteringLayer = new H.map.layer.ObjectLayer(clusteredDataProvider);
map.addLayer(clusteringLayer);

关于javascript - 使用此处的 map 对噪声标记使用不同的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29100832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com