1+ import { throttle } from '@/lib/debounce.ts' ;
12import { AbstractDrawMode } from '@/plugins/draw/mode.abstract.ts' ;
23import type { DrawPlugin } from '@/plugins/draw/plugin.ts' ;
34import 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