@@ -37,26 +37,33 @@ export default function ContextMenu({ map, route, queryPoints }: ContextMenuProp
3737 map . addOverlay ( overlay )
3838
3939 const longTouchHandler = new LongTouchHandler ( e => openContextMenu ( e ) )
40-
40+ const handleTouchStart = ( e : any ) => longTouchHandler . onTouchStart ( e )
41+ const handleTouchMove = ( ) => longTouchHandler . onTouchEnd ( )
42+ const handleTouchEnd = ( ) => longTouchHandler . onTouchEnd ( )
4143 function onMapTargetChange ( ) {
42- // it is important to setup new listeners whenever the map target changes, like when we switch between the
44+ // it is important to set up new listeners whenever the map target changes, like when we switch between the
4345 // small and large screen layout, see #203
4446
4547 // we cannot listen to right-click simply using map.on('contextmenu') and need to add the listener to
4648 // the map container instead
4749 // https://github.com/openlayers/openlayers/issues/12512#issuecomment-879403189
4850 map . getTargetElement ( ) . addEventListener ( 'contextmenu' , openContextMenu )
4951
50- map . getTargetElement ( ) . addEventListener ( 'touchstart' , e => longTouchHandler . onTouchStart ( e ) )
51- map . getTargetElement ( ) . addEventListener ( 'touchmove' , ( ) => longTouchHandler . onTouchEnd ( ) )
52- map . getTargetElement ( ) . addEventListener ( 'touchend' , ( ) => longTouchHandler . onTouchEnd ( ) )
52+ map . getTargetElement ( ) . addEventListener ( 'touchstart' , handleTouchStart )
53+ map . getTargetElement ( ) . addEventListener ( 'touchmove' , handleTouchMove )
54+ map . getTargetElement ( ) . addEventListener ( 'touchend' , handleTouchEnd )
5355
5456 map . getTargetElement ( ) . addEventListener ( 'click' , closeContextMenu )
5557 }
5658 map . on ( 'change:target' , onMapTargetChange )
5759
5860 return ( ) => {
5961 map . getTargetElement ( ) . removeEventListener ( 'contextmenu' , openContextMenu )
62+
63+ map . getTargetElement ( ) . removeEventListener ( 'touchstart' , handleTouchStart )
64+ map . getTargetElement ( ) . removeEventListener ( 'touchmove' , handleTouchMove )
65+ map . getTargetElement ( ) . removeEventListener ( 'touchend' , handleTouchEnd )
66+
6067 map . getTargetElement ( ) . removeEventListener ( 'click' , closeContextMenu )
6168 map . removeOverlay ( overlay )
6269 map . un ( 'change:target' , onMapTargetChange )
0 commit comments