Skip to content

Commit 28ba4e3

Browse files
committed
better reactivity
1 parent 37c5662 commit 28ba4e3

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

dev/App.vue

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
@map:zoomend="isZooming = false"
1515
>
1616
<mgl-draw-control
17+
v-if="useDrawPlugin"
1718
position="top-left"
1819
v-model:mode="drawMode"
1920
:model="drawModel"
20-
zoom-on-update
21+
auto-zoom
2122
:min-area-size="800000000"
2223
min-area-label="TOO SMALL"
2324
@update:model="onDrawModelUpdate"
@@ -44,11 +45,11 @@
4445
/>
4546
</mgl-geo-json-source>
4647

47-
<!-- Test source not working anymore: CORS ERRORS -->
48-
<!-- <mgl-vector-source source-id="libraries" :tiles="librariesSourceTiles">-->
49-
<!-- <mgl-circle-layer layer-id="libraries" source-layer="libraries" :paint="librariesLayerCirclesPaint"-->
50-
<!-- :filter="librariesLayerCirclesFilter"/>-->
51-
<!-- </mgl-vector-source>-->
48+
<!-- Test source not working anymore: CORS ERRORS -->
49+
<!-- <mgl-vector-source source-id="libraries" :tiles="librariesSourceTiles">-->
50+
<!-- <mgl-circle-layer layer-id="libraries" source-layer="libraries" :paint="librariesLayerCirclesPaint"-->
51+
<!-- :filter="librariesLayerCirclesFilter"/>-->
52+
<!-- </mgl-vector-source>-->
5253

5354
</mgl-map>
5455
</div>
@@ -70,6 +71,10 @@
7071
<br/>
7172
<span>Attribution Position: {{ controlPosition }}</span>
7273
</div>
74+
<div>
75+
<input type="checkbox" v-model="useDrawPlugin" id="use-draw">
76+
<label for="use-draw">Use Draw Plugin</label>
77+
</div>
7378
<div>
7479
<input type="checkbox" v-model="useClasses" id="noclasses">
7580
<label for="noclasses">Use Custom Control Classes</label>
@@ -163,6 +168,7 @@
163168
const map = useMap(),
164169
mapVersion = ref<string>(),
165170
showCustomControl = ref(true),
171+
useDrawPlugin = ref(true),
166172
loaded = ref(0),
167173
markerCoordinates = ref<LngLatLike>([ 13.377507, 52.516267 ]),
168174
bounds = ref<LngLatBoundsLike>(),
@@ -265,7 +271,7 @@
265271
// setTimeout(() => drawModel.value = drawCircleExample2, 5000);
266272
267273
return {
268-
showCustomControl, loaded, map, mapVersion, markerCoordinates, geojsonSource, bounds, onLoad, onMouseenter, setLanguage,
274+
showCustomControl, useDrawPlugin, loaded, map, mapVersion, markerCoordinates, geojsonSource, bounds, onLoad, onMouseenter, setLanguage,
269275
geojsonSourceData : geojsonSource.data,
270276
isZooming : ref(false),
271277
controlPosition : ref(Position.TOP_LEFT),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-maplibre-gl",
3-
"version": "5.4.6",
3+
"version": "5.4.7",
44
"description": "Vue 3 plugin for maplibre-gl",
55
"keywords": [
66
"vue",

src/plugins/draw/plugin.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ export class DrawPlugin {
3838

3939
this.setup = this.setup.bind(this);
4040
this.zoomToModel = this.zoomToModel.bind(this);
41-
this.map.once('load', this.setup);
41+
if (this.map.isStyleLoaded()) {
42+
this.setup();
43+
} else {
44+
this.map.once('load', this.setup);
45+
}
4246
}
4347

4448
get mode(): DrawMode {
@@ -215,10 +219,14 @@ export class DrawPlugin {
215219
for (let i = 0, len = this.options.styles.length; i < len; i++) {
216220
if (this.map.getLayer(this.options.styles[ i ].id)) {
217221
this.map.removeLayer(this.options.styles[ i ].id);
222+
} else {
223+
console.log('NO LAYER', this.options.styles[ i ].id);
218224
}
219225
}
220226
if (this.map.getSource(DrawPlugin.SOURCE_ID)) {
221227
this.map.removeSource(DrawPlugin.SOURCE_ID);
228+
} else {
229+
console.log('NO SOURCE', DrawPlugin.SOURCE_ID);
222230
}
223231
}
224232
} catch (e) {

0 commit comments

Comments
 (0)