11import { Modify , Interaction } from 'ol/interaction' ;
22import { singleClick } from 'ol/events/condition' ;
3+ // eslint-disable-next-line import/no-extraneous-dependencies
34import throttle from 'lodash.throttle' ;
5+ import { unByKey } from 'ol/Observable' ;
46import Control from './control' ;
57import image from '../../img/modify_geometry2.svg' ;
68import SelectMove from '../interaction/selectmove' ;
@@ -69,7 +71,7 @@ class ModifyControl extends Control {
6971 /* Cursor management */
7072 this . previousCursor = null ;
7173 this . cursorTimeout = null ;
72- this . cursorHandler = throttle ( this . cursorHandler . bind ( this ) , 150 , {
74+ this . cursorHandlerThrottled = throttle ( this . cursorHandler . bind ( this ) , 150 , {
7375 leading : true ,
7476 } ) ;
7577 this . cursorStyleHandler =
@@ -377,8 +379,12 @@ class ModifyControl extends Control {
377379 this . map . removeInteraction ( this . selectModify ) ;
378380 this . map . removeInteraction ( this . deleteInteraction ) ;
379381 this . map . removeInteraction ( this . deselectInteraction ) ;
382+ this . removeListeners ( ) ;
380383 }
381384 super . setMap ( map ) ;
385+ if ( this . getActive ( ) ) {
386+ this . addListeners ( ) ;
387+ }
382388 this . map ?. addInteraction ( this . deselectInteraction ) ;
383389 this . map ?. addInteraction ( this . deleteInteraction ) ;
384390 this . map ?. addInteraction ( this . selectModify ) ;
@@ -396,9 +402,21 @@ class ModifyControl extends Control {
396402 */
397403 addListeners ( ) {
398404 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+ ] ;
402420 }
403421
404422 /**
@@ -407,9 +425,7 @@ class ModifyControl extends Control {
407425 * @private
408426 */
409427 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 ) ;
413429 }
414430
415431 /**
0 commit comments