how to change the marker icon when click on it here map

时间:2017-08-05 12:00:06

标签: here-api

After loading The heremap i set markers with custom image on it. Then After click in the marker i'm getting the bubble popup. I want to change the marker icon when click on it. How can i change the marker icon when click on it?

Code for showing bubble after click the marker as given below.

    map.addObject(group);

  // add 'tap' event listener, that opens info bubble, to the group
  group.addEventListener('tap', function (evt) {
    // event target is the marker itself, group is a parent event target
    // for all objects that it contains

    var bubble =  new H.ui.InfoBubble(evt.target.getPosition(), {
      // read custom data
      content: evt.target.getData()
    });


    // show info bubble
    ui.addBubble(bubble);
  }, false);

1 个答案:

答案 0 :(得分:0)

在我的应用程序中,我在单击时更改标记的原始颜色。您是否尝试过使用markerTemplate,这意味着您将标记的svg存储为字符串的变量?

 var markerTemplate = '<svg xmlns="http://www.w3.org/2000/svg" width="28px" height="36px">... fill="${COLOR}"/></svg>'

然后您可以使用例如此字符串和EventListner中的fill="${COLOR}"将此占位符替换为新颜色markerTemplate.replace('${COLOR}', 'rgba(231, 0, 0, 0.7)');

希望这有帮助