1
1
import { Modify , Interaction } from 'ol/interaction' ;
2
2
import { singleClick } from 'ol/events/condition' ;
3
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
4
import throttle from 'lodash.throttle' ;
5
+ import { unByKey } from 'ol/Observable' ;
4
6
import Control from './control' ;
5
7
import image from '../../img/modify_geometry2.svg' ;
6
8
import SelectMove from '../interaction/selectmove' ;
@@ -69,7 +71,7 @@ class ModifyControl extends Control {
69
71
/* Cursor management */
70
72
this . previousCursor = null ;
71
73
this . cursorTimeout = null ;
72
- this . cursorHandler = throttle ( this . cursorHandler . bind ( this ) , 150 , {
74
+ this . cursorHandlerThrottled = throttle ( this . cursorHandler . bind ( this ) , 150 , {
73
75
leading : true ,
74
76
} ) ;
75
77
this . cursorStyleHandler =
@@ -377,8 +379,12 @@ class ModifyControl extends Control {
377
379
this . map . removeInteraction ( this . selectModify ) ;
378
380
this . map . removeInteraction ( this . deleteInteraction ) ;
379
381
this . map . removeInteraction ( this . deselectInteraction ) ;
382
+ this . removeListeners ( ) ;
380
383
}
381
384
super . setMap ( map ) ;
385
+ if ( this . getActive ( ) ) {
386
+ this . addListeners ( ) ;
387
+ }
382
388
this . map ?. addInteraction ( this . deselectInteraction ) ;
383
389
this . map ?. addInteraction ( this . deleteInteraction ) ;
384
390
this . map ?. addInteraction ( this . selectModify ) ;
@@ -396,9 +402,21 @@ class ModifyControl extends Control {
396
402
*/
397
403
addListeners ( ) {
398
404
this . removeListeners ( ) ;
399
- this . map ?. on ( 'pointerdown' , this . cursorHandler ) ;
400
- this . map ?. on ( 'pointermove' , this . cursorHandler ) ;
401
- this . map ?. on ( 'pointerup' , this . cursorHandler ) ;
405
+ this . cursorListenerKeys = [
406
+ this . map ?. on ( 'pointerdown' , ( ) => {
407
+ const element = this . map . getTargetElement ( ) ;
408
+ if ( element ?. style ?. cursor === 'grab' ) {
409
+ this . changeCursor ( 'grabbing' ) ;
410
+ }
411
+ } ) ,
412
+ this . map ?. on ( 'pointermove' , this . cursorHandlerThrottled ) ,
413
+ this . map ?. on ( 'pointerup' , ( ) => {
414
+ const element = this . map . getTargetElement ( ) ;
415
+ if ( element ?. style ?. cursor === 'grabbing' ) {
416
+ this . changeCursor ( 'grab' ) ;
417
+ }
418
+ } ) ,
419
+ ] ;
402
420
}
403
421
404
422
/**
@@ -407,9 +425,7 @@ class ModifyControl extends Control {
407
425
* @private
408
426
*/
409
427
removeListeners ( ) {
410
- this . map ?. un ( 'pointerdown' , this . cursorHandler ) ;
411
- this . map ?. un ( 'pointermove' , this . cursorHandler ) ;
412
- this . map ?. un ( 'pointerup' , this . cursorHandler ) ;
428
+ unByKey ( this . cursorListenerKeys ) ;
413
429
}
414
430
415
431
/**
0 commit comments