Here Maps JavaScript API 3.0 Explorer How to set marker color

后端 未结 2 784
南笙
南笙 2020-12-21 22:29

I can\'t find any documentation or examples for setting a markers colour in version 3.0 API. you could do this with the 2.5, do any one know if marker colour is supported an

2条回答
  •  攒了一身酷
    2020-12-21 22:44

    As stated in the example in the API Explorer, creating an H.map.Marker without specifying an icon results in a default image. If you need to have different colored icons, you will need to create them using SVG Graphics.

    function addSVGMarkers(map){
      var svgMarkup = '' +
          '' +
          '' +
          '' +
          '${TEXT}'
    
      // Add the first marker
      var parisIcon = new H.map.Icon(
        svgMarkup.replace('${COLOR}', 'blue').replace('${TEXT}', 'P')),
        parisMarker = new H.map.Marker({lat: 55.5607, lng: 12.9811 },
          {icon: parisIcon});
    
      map.addObject(parisMarker);
    }
    

    To update the color, just create a new H.map.Icon replace the icon attribute of the marker.

提交回复
热议问题