我在做什么: -在地图上添加多边形, -使它可编辑 __我想做的事: -防止相交的线, -获取drawError.timeout进行工作 __这是怎么回事: -即使我没有设置'allowIntersection:false',也可以防止相交线 -Poly drawError'color'正常工作,但'timeout'无效。尝试绘制相交折线后,多边形会永久保持紫色。
var map = new L.Map("map", {
attributionControl: false,
minZoom: 3,
maxZoom: 18,
zoom: 4,
center: [40.439718, -101.096488],
})
L.control.fullscreen({
position: 'topleft',
content: '<a class="fa fa-arrows-alt"></a>'
}).addTo(map)
L.control.layers({
'Dark': L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/dark-v9/tiles/{z}/{x}/{y}?access_token=<token>'),
"Satellite": L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/satellite-v9/tiles/{z}/{x}/{y}?access_token=<token>'),
"Satellite with streets": L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v10/tiles/{z}/{x}/{y}?access_token=<token>').addTo(map)
}).addTo(map)
var bound = this.boundary.geojson.geometry.coordinates[0].map(coor => {
return coor.reverse()
})
var polygon = L.polygon(bound, {
color: '#45aaff',
editable: true,
poly: {
icon: new L.DivIcon({
iconSize: new L.Point(9, 9),
className: 'leaflet-div-icon leaflet-editing-icon'
}),
drawError: {
color: 'purple',
timeout: 2000
}
},
})
polygon.addTo(map);
map.fitBounds(polygon.getBounds());