Javascript 使用here贴图的不同颜色到噪波标记
在使用here maps api进行聚类时,是否可以对不同的噪声标记应用不同的颜色Javascript 使用here贴图的不同颜色到噪波标记,javascript,maps,here-api,Javascript,Maps,Here Api,在使用here maps api进行聚类时,是否可以对不同的噪声标记应用不同的颜色 有一个可用的标记,但这适用于所有标记。我想根据特定条件将特定颜色设置为特定点。这当然可以使用自定义主题。H.clustering.DataPoint对象的定义包括一个可以保存任意数据的data() 准备数据集时,可以按如下所示添加数据集: var dataPoints = []; dataPoints.push(new H.clustering.DataPoint(lat, lng, null, {color
有一个可用的标记,但这适用于所有标记。我想根据特定条件将特定颜色设置为特定点。这当然可以使用自定义主题。
H.clustering.DataPoint
对象的定义包括一个可以保存任意数据的data()
准备数据集时,可以按如下所示添加数据集:
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 });
}
};
};
您可以按常规方式将主题添加到地图中:
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);
非常感谢。这对我有很大的帮助只有一件事:聚类似乎正在工作(显示点的数量),但我也看到了所有的噪声标记,就像它们没有被聚类一样。你可能正在将
标记直接添加到地图中
-不需要这样做,聚类会为你做,只需创建数据点
。或者设置minZoom
,如本“是”中所示!最小缩放是缺少的选项。再次感谢大家!!如果有人遇到“颜色未定义”的问题,您可以使用下面的代码。noisePoint.data.color=>noisePoint.getData().color