使用此处映射的不同颜色到噪声标记 [英] Different color to noise marker using here maps

查看:96
本文介绍了使用此处映射的不同颜色到噪声标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to apply different color to different noise markers while clustering using here maps api?

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

There's a theming option available, but that applies to all markers. I would like to set a specific color to specific point based on certain conditions.

推荐答案

使用自定义主题当然可以实现. H.clustering.DataPoint对象的定义包括data()

This is certainly possible using a custom theme. The definition of the H.clustering.DataPoint object includes a data() method which can hold arbitrary data.

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

When you prepare your dataset you can add it as shown:

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 ...

如果使用自定义主题,则可以从噪点读取数据并根据需要显示它:

If you use a custom theme, you can read the data from the noise point and display it as you see fit:

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 });
       }
    };
  };

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

You can add the theme to the map in the usual manner:

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);

这篇关于使用此处映射的不同颜色到噪声标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆