如何更改小叶路由机标记的默认颜色

时间:2019-10-17 08:49:19

标签: angular leaflet marker leaflet-routing-machine

我正在使用 leaflt-routing-machine 插件,我需要将标记的颜色从蓝色更改为红色,有什么建议吗?

1 个答案:

答案 0 :(得分:3)

我相信这应该很好

var redIcon = new L.Icon({
  iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-red.png',
  shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
  iconSize: [25, 41],
  iconAnchor: [12, 41],
  popupAnchor: [1, -34],
  shadowSize: [41, 41]
});



 L.Routing.control({
      waypoints: [
        L.latLng(57.74, 11.94),
        L.latLng(57.6792, 11.949)
      ],
      collapsible: true, // hide/show panel routing
      autoRoute: true, // possibility to take autoRoute
      language : 'fr', 
     // THIS IS ESPECIALLY WHAT YOU SHOULD ADD (createMarker):
      createMarker: function(i, wp, nWps) {
        return L.marker(wp.latLng, {icon: redIcon });
      },
      // ...
    }).addTo(this.map);