Skip to content

Commit 6e9f876

Browse files
committed
Leaflet Draw Production test
1 parent 6f27bb8 commit 6e9f876

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

docs/guide/leaflet-draw.md

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,28 @@ import { ref, onMounted } from 'vue';
1515

1616
const map = ref(null);
1717

18-
let wasLeafletDrawLoaded = false;
19-
2018
onMounted(() => {
19+
// Load Leaflet script
2120
import('leaflet').then(() => {
22-
console.log('Leaflet loaded');
23-
setTimeout(() => {
24-
// Load the Leaflet Draw script
25-
const script = document.createElement('script');
26-
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js';
27-
script.async = true;
28-
// When it is loaded
29-
script.onload = () => {
30-
console.log('Leaflet Draw loaded');
31-
wasLeafletDrawLoaded = true;
32-
if (map.value.leafletObject) {
33-
setupLeafletDraw();
34-
}
35-
};
36-
// Append the script element to the DOM
37-
document.head.appendChild(script);
38-
}, 2000);
21+
// Load Leaflet Draw script
22+
import('https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js').then(() => {
23+
// Setup Leaflet Draw
24+
setTimeout(() => {
25+
setupLeafletDraw();
26+
}, 1000);
27+
});
3928
});
4029
})
4130

42-
// When the map is ready
43-
const mapInitialized = () => {
44-
if (!wasLeafletDrawLoaded) {
45-
console.log('Leaflet Draw not loaded yet');
46-
return;
47-
}
48-
setTimeout(() => {
49-
setupLeafletDraw();
50-
}, 2000);
51-
}
52-
5331
const setupLeafletDraw = () => {
54-
console.log('Setting up Leaflet Draw');
5532
// Init the draw control
5633
// See https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html#l-draw-feature
5734
const drawnItems = new L.FeatureGroup();
5835
map.value.leafletObject.addLayer(drawnItems);
5936
const drawControl = new L.Control.Draw({
60-
edit: {
61-
featureGroup: drawnItems
62-
}
37+
edit: {
38+
featureGroup: drawnItems
39+
}
6340
});
6441
map.value.leafletObject.addControl(drawControl);
6542
}
@@ -76,7 +53,6 @@ const setupLeafletDraw = () => {
7653
:zoom="6"
7754
:max-zoom="18"
7855
:center="[47.21322, -1.559482]"
79-
@ready="mapInitialized"
8056
>
8157
<LTileLayer
8258
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"

0 commit comments

Comments
 (0)