@@ -15,51 +15,28 @@ import { ref, onMounted } from 'vue';
15
15
16
16
const map = ref (null );
17
17
18
- let wasLeafletDrawLoaded = false ;
19
-
20
18
onMounted (() => {
19
+ // Load Leaflet script
21
20
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
+ });
39
28
});
40
29
})
41
30
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
-
53
31
const setupLeafletDraw = () => {
54
- console .log (' Setting up Leaflet Draw' );
55
32
// Init the draw control
56
33
// See https://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html#l-draw-feature
57
34
const drawnItems = new L.FeatureGroup ();
58
35
map .value .leafletObject .addLayer (drawnItems);
59
36
const drawControl = new L.Control.Draw ({
60
- edit: {
61
- featureGroup: drawnItems
62
- }
37
+ edit: {
38
+ featureGroup: drawnItems
39
+ }
63
40
});
64
41
map .value .leafletObject .addControl (drawControl);
65
42
}
@@ -76,7 +53,6 @@ const setupLeafletDraw = () => {
76
53
: zoom ="6"
77
54
: max-zoom ="18"
78
55
: center ="[ 47.21322, -1.559482] "
79
- @ready ="mapInitialized"
80
56
>
81
57
<LTileLayer
82
58
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
0 commit comments