使用此处贴图的不同颜色到噪波标记

Different color to noise marker using here maps

本文关键字:颜色      更新时间:2023-09-26

在使用here-maps api进行聚类时,是否可以将不同的颜色应用于不同的噪声标记?

有一个主题选项可用,但这适用于所有标记。我想根据特定的条件将特定的颜色设置为特定的点。

使用自定义主题当然可以。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);