Skip to content

Commit 3d1ff27

Browse files
committed
better clean up of touchstart/move/end
1 parent 1bdc11b commit 3d1ff27

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/layers/ContextMenu.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/layers/UsePathsLayer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function addAccessNetworkLayer(map: Map, selectedPath: Path, queryPoints: QueryP
133133
})
134134
layer.setStyle(style)
135135
for (let i = 0; i < selectedPath.snapped_waypoints.coordinates.length; i++) {
136-
if(i >= queryPoints.length) break // can happen if deleted too fast
136+
if (i >= queryPoints.length) break // can happen if deleted too fast
137137
const start = fromLonLat([queryPoints[i].coordinate.lng, queryPoints[i].coordinate.lat])
138138
const end = fromLonLat(selectedPath.snapped_waypoints.coordinates[i])
139139
layer.getSource()?.addFeature(new Feature(createBezierLineString(start, end)))

0 commit comments

Comments
 (0)