Leaflet绘制多边形
<div id="map"></div> var map = L.map('map').setView([51.505, -0.09], 13); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{ attribution: '© <a href="#">OpenStreetMap</a>' }).addTo(map); let points = []; const polygon = new L.Polygon(points); map.addLayer(polygon); map.on('mousedown', e => { points.push([e.latlng.lat, e.latlng.lng]); map.on('mousemove', event => { polygon.setLatLngs([...points,[event.latlng.lat, event.latlng.lng]]) }); }); map.on('dblclick', () => { if (points.length) { map.off('mousemove'); points = []; } }); };