作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
mounted() {
this.initMap();
},
methods: {
initMap() {
this.map = L.map('mapContainer').setView([48.856663, 2.351556], 12);
this.tileLayer = L.tileLayer(
"https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}",
{
attribution: '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery (c) <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: "mapbox/satellite-streets-v11",
accessToken: "token",
}
);
this.tileLayer.addTo(this.map);
var drawnItems = new L.FeatureGroup();
this.map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
edit: {
featureGroup: drawnItems
}
});
this.map.addControl(drawControl);
this.map.on(L.Draw.Event.CREATED, function(event){
let layer = event.layer;
console.log(`start ${layer}`);
drawnItems.addLayer((layer))
})
},
},
}
leaflet.draw.js?20d6:8 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
第一次与 map 交互后,控制台出现错误,无法再绘制形状
更新:切换到mapbox draw
最佳答案
我是这样解决这个问题的。代替 Leaflet,在 Vue 3 中使用 MapBox 和 MapBox 绘图
关于javascript - leaflet和leaflet draw vue leaflet.draw.js的问题?20d6 :8 Uncaught TypeError: Cannot read properties of undefined (reading 'length' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70428824/
我是一名优秀的程序员,十分优秀!