0

我想知道是否有可能改变默认图标(蓝色),与应用程序初始化时的另一个自定义图标,我阅读有关如何更改,但我想为整个应用程序的自定义图标。如何更改传单指令上的默认图标引脚?

HTML

<div ng-controller="CustomizedMarkersController"> 
    <button type="button" class="btn btn-primary padright" ng-click="markers.m1.icon=icon" ng-repeat="(key, icon) in icons">{{ key }}</button> 
    <leaflet markers="markers" center="lisbon"></leaflet> 
</div> 

JS

app.controller("CustomizedMarkersController", [ '$scope', function($scope) { 
    var local_icons = { 
     default_icon: {}, 
     leaf_icon: { 
      iconUrl: 'examples/img/leaf-green.png', 
      shadowUrl: 'examples/img/leaf-shadow.png', 
      iconSize:  [38, 95], // size of the icon 
      shadowSize: [50, 64], // size of the shadow 
      iconAnchor: [22, 94], // point of the icon which will correspond to marker's location 
      shadowAnchor: [4, 62], // the same for the shadow 
      popupAnchor: [-3, -76] // point from which the popup should open   relative to the iconAnchor 
     }, 
     div_icon: { 
      type: 'div', 
      iconSize: [230, 0], 
      html: 'Using <strong>Bold text as an icon</strong>: Lisbon', 
      popupAnchor: [0, 0] 
     }, 
     orange_leaf_icon: { 
      iconUrl: 'examples/img/leaf-orange.png', 
      shadowUrl: 'examples/img/leaf-shadow.png', 
      iconSize:  [38, 95], 
      shadowSize: [50, 64], 
      iconAnchor: [22, 94], 
      shadowAnchor: [4, 62] 
     } 
}; 

angular.extend($scope, { 
    icons: local_icons 
}); 

angular.extend($scope, { 
    lisbon: { 
     lat: 38.716, 
     lng: -9.13, 
     zoom: 8 
    }, 
    markers: { 
     m1: { 
      lat: 38.716, 
      lng: -9.13, 
      message: "I'm a static marker", 
      icon: local_icons.default_icon, 
     }, 
    }, 
    defaults: { 
     scrollWheelZoom: false 
    } 
}); 
}]); 

Based on this example.

回答

0

Leaflet documentation, see Icon.Default

为了改变默认的图标,只是改变属性(这是一组Icon options)。

例如,包括在你的代码行是:

L.Icon.Default.prototype.options.iconUrl = 'myNewDefaultImage.png'; 

你可能也想改变阴影和Retina显示屏,其设置的选项shadowUrliconRetinaUrl 2X图标。