错误如下图所示:
正确是如下图:
解决方法如下:注意:require在angular中不能使用,是属于node的语法,所以需要声明一下
declare var require;
let DefaultIcon = L.icon({
iconUrl: require('leaflet/dist/images/marker-icon-2x.png'),
iconRetinaUrl: require('leaflet/dist/images/marker-icon.png'),
shadowUrl: require('leaflet/dist/images/marker-shadow.png'),
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
tooltipAnchor: [16, -28],
shadowSize: [41, 41]
});
L.Marker.prototype.options.icon = DefaultIcon;