Skip to content

Commit f8cfa85

Browse files
committed
checking min area size while zooming in circle static mode
1 parent d4eb5a6 commit f8cfa85

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

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.3.7",
3+
"version": "5.3.8",
44
"description": "Vue 3 plugin for maplibre-gl",
55
"keywords": [
66
"vue",

src/plugins/draw/circleStatic.mode.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { throttle } from '@/lib/debounce.ts';
12
import { AbstractDrawMode } from '@/plugins/draw/mode.abstract.ts';
23
import type { DrawPlugin } from '@/plugins/draw/plugin.ts';
34
import type { DrawModel } from '@/plugins/draw/types.ts';
@@ -11,7 +12,8 @@ export class CircleStaticMode extends AbstractDrawMode {
1112

1213
constructor(plugin: DrawPlugin, map: Map, source: GeoJSONSource, model: DrawModel | undefined) {
1314
super(plugin, map, source);
14-
this.onViewportChange = this.onViewportChange.bind(this);
15+
this.onViewportChangeEnd = this.onViewportChangeEnd.bind(this);
16+
this.onViewportChange = throttle(this.onViewportChange.bind(this), 100);
1517

1618
this._model = model;
1719
this._container.classList.add('maplibregl-draw-circle-mode');
@@ -30,6 +32,16 @@ export class CircleStaticMode extends AbstractDrawMode {
3032
}
3133

3234
onViewportChange() {
35+
this._model = this.viewportToModel();
36+
if (this._model.properties.tooSmall) {
37+
this._circle.classList.add('maplibregl-draw-circle-too-small');
38+
} else {
39+
this._circle.classList.remove('maplibregl-draw-circle-too-small');
40+
}
41+
}
42+
43+
44+
onViewportChangeEnd() {
3345
this._model = this.viewportToModel();
3446
this.emitOnUpdate(this._model);
3547
if (this._model.properties.tooSmall) {
@@ -52,14 +64,16 @@ export class CircleStaticMode extends AbstractDrawMode {
5264

5365
register(): void {
5466
this.map.getCanvasContainer().appendChild(this._container);
55-
this.map.on('dragend', this.onViewportChange);
56-
this.map.on('zoomend', this.onViewportChange);
67+
this.map.on('dragend', this.onViewportChangeEnd);
68+
this.map.on('zoomend', this.onViewportChangeEnd);
69+
this.map.on('zoom', this.onViewportChange);
5770
}
5871

5972
unregister(): void {
6073
this.map.getCanvasContainer().removeChild(this._container);
61-
this.map.off('dragend', this.onViewportChange);
62-
this.map.off('zoomend', this.onViewportChange);
74+
this.map.off('dragend', this.onViewportChangeEnd);
75+
this.map.off('zoomend', this.onViewportChangeEnd);
76+
this.map.off('zoom', this.onViewportChange);
6377
}
6478

6579
setModel(model: DrawModel | undefined): void {

0 commit comments

Comments
 (0)