Skip to content

Commit 26d947c

Browse files
committed
format
1 parent 9c22019 commit 26d947c

File tree

4 files changed

+67
-59
lines changed

4 files changed

+67
-59
lines changed

src/layers/ContextMenu.tsx

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {Map, Overlay} from 'ol'
2-
import {ContextMenuContent} from '@/map/ContextMenuContent'
3-
import {useCallback, useContext, useEffect, useRef, useState} from 'react'
4-
import {QueryPoint} from '@/stores/QueryStore'
5-
import {fromLonLat, toLonLat} from 'ol/proj'
1+
import { Map, Overlay } from 'ol'
2+
import { ContextMenuContent } from '@/map/ContextMenuContent'
3+
import { useCallback, useContext, useEffect, useRef, useState } from 'react'
4+
import { QueryPoint } from '@/stores/QueryStore'
5+
import { fromLonLat, toLonLat } from 'ol/proj'
66
import styles from '@/layers/ContextMenu.module.css'
7-
import {RouteStoreState} from '@/stores/RouteStore'
8-
import {Coordinate} from '@/utils'
9-
import Dispatcher from "@/stores/Dispatcher";
10-
import {AddPoint, SetPoint} from "@/actions/Actions";
11-
import {coordinateToText} from "@/Converters";
12-
import {SettingsContext} from "@/contexts/SettingsContext";
7+
import { RouteStoreState } from '@/stores/RouteStore'
8+
import { Coordinate } from '@/utils'
9+
import Dispatcher from '@/stores/Dispatcher'
10+
import { AddPoint, SetPoint } from '@/actions/Actions'
11+
import { coordinateToText } from '@/Converters'
12+
import { SettingsContext } from '@/contexts/SettingsContext'
1313

1414
interface ContextMenuProps {
1515
map: Map
@@ -21,56 +21,64 @@ const overlay = new Overlay({
2121
autoPan: true,
2222
})
2323

24-
export default function ContextMenu({map, route, queryPoints}: ContextMenuProps) {
24+
export default function ContextMenu({ map, route, queryPoints }: ContextMenuProps) {
2525
const [menuCoordinate, setMenuCoordinate] = useState<Coordinate | null>(null)
2626
const container = useRef<HTMLDivElement | null>(null)
2727
const settings = useContext(SettingsContext)
2828

29-
const openContextMenu = useCallback((e: any) => {
30-
e.preventDefault()
31-
const coordinate = map.getEventCoordinate(e)
32-
const lonLat = toLonLat(coordinate)
33-
setMenuCoordinate({lng: lonLat[0], lat: lonLat[1]})
34-
}, [map])
29+
const openContextMenu = useCallback(
30+
(e: any) => {
31+
e.preventDefault()
32+
const coordinate = map.getEventCoordinate(e)
33+
const lonLat = toLonLat(coordinate)
34+
setMenuCoordinate({ lng: lonLat[0], lat: lonLat[1] })
35+
},
36+
[map]
37+
)
3538

36-
const handleClick = useCallback((e: any) => {
37-
if (e.dragging) return
39+
const handleClick = useCallback(
40+
(e: any) => {
41+
if (e.dragging) return
3842

39-
// If click is inside the context menu, do nothing
40-
const clickedElement = document.elementFromPoint(e.pixel[0], e.pixel[1])
41-
if (container.current?.contains(clickedElement)) {
42-
return
43-
}
43+
// If click is inside the context menu, do nothing
44+
const clickedElement = document.elementFromPoint(e.pixel[0], e.pixel[1])
45+
if (container.current?.contains(clickedElement)) {
46+
return
47+
}
4448

45-
if (menuCoordinate) {
46-
// Context menu is open -> close it and skip adding a point
47-
setMenuCoordinate(null)
48-
return
49-
}
49+
if (menuCoordinate) {
50+
// Context menu is open -> close it and skip adding a point
51+
setMenuCoordinate(null)
52+
return
53+
}
5054

51-
if (!settings.addPointOnClick) return
55+
if (!settings.addPointOnClick) return
5256

53-
const lonLat = toLonLat(e.coordinate)
54-
const myCoord = {lng: lonLat[0], lat: lonLat[1]}
57+
const lonLat = toLonLat(e.coordinate)
58+
const myCoord = { lng: lonLat[0], lat: lonLat[1] }
5559

56-
let idx = queryPoints.length
57-
if (idx == 2) {
58-
if (!queryPoints[1].isInitialized) idx--;
59-
}
60-
if (idx == 1) {
61-
if (!queryPoints[0].isInitialized) idx--;
62-
}
63-
if (idx < 2) {
64-
const setPoint = new SetPoint({
65-
...queryPoints[idx],
66-
coordinate: myCoord,
67-
queryText: coordinateToText(myCoord),
68-
isInitialized: true
69-
}, false);
70-
Dispatcher.dispatch(setPoint)
71-
} else
72-
Dispatcher.dispatch(new AddPoint(idx, myCoord, true, false))
73-
}, [menuCoordinate, settings.addPointOnClick, queryPoints])
60+
let idx = queryPoints.length
61+
if (idx == 2) {
62+
if (!queryPoints[1].isInitialized) idx--
63+
}
64+
if (idx == 1) {
65+
if (!queryPoints[0].isInitialized) idx--
66+
}
67+
if (idx < 2) {
68+
const setPoint = new SetPoint(
69+
{
70+
...queryPoints[idx],
71+
coordinate: myCoord,
72+
queryText: coordinateToText(myCoord),
73+
isInitialized: true,
74+
},
75+
false
76+
)
77+
Dispatcher.dispatch(setPoint)
78+
} else Dispatcher.dispatch(new AddPoint(idx, myCoord, true, false))
79+
},
80+
[menuCoordinate, settings.addPointOnClick, queryPoints]
81+
)
7482

7583
useEffect(() => {
7684
overlay.setElement(container.current!)
@@ -81,8 +89,8 @@ export default function ContextMenu({map, route, queryPoints}: ContextMenuProps)
8189
function onMapTargetChange() {
8290
const targetElement = map.getTargetElement()
8391
if (!targetElement) {
84-
console.warn('Map target element is null. Delaying event listeners setup.');
85-
return;
92+
console.warn('Map target element is null. Delaying event listeners setup.')
93+
return
8694
}
8795

8896
targetElement.addEventListener('contextmenu', openContextMenu)

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)))

src/stores/MapOptionsStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
SelectMapLayer,
66
ToggleExternalMVTLayer,
77
ToggleRoutingGraph,
8-
ToggleUrbanDensityLayer, UpdateSettings,
8+
ToggleUrbanDensityLayer,
9+
UpdateSettings,
910
} from '@/actions/Actions'
1011
import config from 'config'
1112

@@ -199,7 +200,6 @@ export default class MapOptionsStore extends Store<MapOptionsStoreState> {
199200
selectedStyle: styleOption,
200201
}
201202
} else if (action instanceof UpdateSettings) {
202-
203203
} else if (action instanceof ToggleRoutingGraph) {
204204
return {
205205
...state,

src/stores/SettingsStore.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Store from '@/stores/Store'
2-
import {Action} from '@/stores/Dispatcher'
3-
import {SetCustomModelEnabled, UpdateSettings} from '@/actions/Actions'
4-
import {getMap} from "@/map/map";
2+
import { Action } from '@/stores/Dispatcher'
3+
import { SetCustomModelEnabled, UpdateSettings } from '@/actions/Actions'
4+
import { getMap } from '@/map/map'
55

66
export interface Settings {
77
showDistanceInMiles: boolean

0 commit comments

Comments
 (0)