1 在webpack中使用leaflet添加marker 时,使用默认marker报错
转码后的base64图标 后会多出来默认 marker 名称
webpack.config.js 中的相关配置
resolve: {
alias: {
'@':path.resolve(__dirname, './src'),
leaflet_css: __dirname + "/node_modules/leaflet/dist/leaflet.css",
leaflet_marker: __dirname + "/node_modules/leaflet/dist/images/marker-icon.png",
leaflet_marker_2x: __dirname + "/node_modules/leaflet/dist/images/marker-icon-2x.png",
leaflet_marker_shadow: __dirname + "/node_modules/leaflet/dist/images/marker-shadow.png",
}
},
代码部分
import "leaflet_css";
import L from "leaflet";
(function(){
var map = L.map('map-osm-leaflet').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([51.5, -0.09]).addTo(map)
.bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
.openPopup();
})();
目前是自己传入图标,不使用默认图标时可以正常使用