Skip to content

Commit

Permalink
toggle button on map for better usage
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Sep 20, 2023
1 parent 5599679 commit 5ef578a
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 23 deletions.
17 changes: 17 additions & 0 deletions src/App.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,20 @@
.sidebarOpenButton:hover svg {
fill: black;
}

.drawIcon {
position: absolute;
right: 62px;
top: 10px;
background-color: white;

padding: 4px;
width: 34px;
height: 34px;
}

.drawIcon svg {
color: gray;
width: 100%;
height: 100%;
}
50 changes: 47 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import PlainButton from '@/PlainButton'
import useAreasLayer from '@/layers/UseAreasLayer'
import useExternalMVTLayer from '@/layers/UseExternalMVTLayer'
import LocationButton from '@/map/LocationButton'
import DrawIcon from './map/gesture.svg'
import Dispatcher from '@/stores/Dispatcher'
import { DrawHandfreeQueryPoints, ToggleRoutingGraph } from '@/actions/Actions'

export const POPUP_CONTAINER_ID = 'popup-container'
export const SIDEBAR_CONTENT_ID = 'sidebar-content'
Expand Down Expand Up @@ -105,7 +108,13 @@ export default function App() {
useAreasLayer(map, settings.drawAreasEnabled, query.customModelStr, query.customModelEnabled)
useRoutingGraphLayer(map, mapOptions.routingGraphEnabled)
useUrbanDensityLayer(map, mapOptions.urbanDensityEnabled)
usePathsLayer(map, route.routingResult.paths, route.selectedPath, query.queryPoints)
usePathsLayer(
map,
route.routingResult.paths,
route.selectedPath,
query.queryPoints,
settings.drawHandfreeQueryPointsEnabled
)
useQueryPointsLayer(map, query.queryPoints)
usePathDetailsLayer(map, pathDetails)
const isSmallScreen = useMediaQuery({ query: '(max-width: 44rem)' })
Expand All @@ -123,6 +132,7 @@ export default function App() {
error={error}
encodedValues={info.encoded_values}
drawAreas={settings.drawAreasEnabled}
drawHandfreeQueryPoints={settings.drawHandfreeQueryPointsEnabled}
/>
) : (
<LargeScreenLayout
Expand All @@ -133,6 +143,7 @@ export default function App() {
error={error}
encodedValues={info.encoded_values}
drawAreas={settings.drawAreasEnabled}
drawHandfreeQueryPoints={settings.drawHandfreeQueryPointsEnabled}
/>
)}
</div>
Expand All @@ -148,9 +159,19 @@ interface LayoutProps {
error: ErrorStoreState
encodedValues: object[]
drawAreas: boolean
drawHandfreeQueryPoints: boolean
}

function LargeScreenLayout({ query, route, map, error, mapOptions, encodedValues, drawAreas }: LayoutProps) {
function LargeScreenLayout({
query,
route,
map,
error,
mapOptions,
encodedValues,
drawAreas,
drawHandfreeQueryPoints,
}: LayoutProps) {
const [showSidebar, setShowSidebar] = useState(true)
const [showCustomModelBox, setShowCustomModelBox] = useState(false)
return (
Expand Down Expand Up @@ -200,6 +221,13 @@ function LargeScreenLayout({ query, route, map, error, mapOptions, encodedValues
<div className={styles.popupContainer} id={POPUP_CONTAINER_ID} />
<div className={styles.onMapRightSide}>
<MapOptions {...mapOptions} />
<div
style={drawHandfreeQueryPoints ? { backgroundColor: 'black' } : {}}
className={styles.drawIcon}
onClick={e => Dispatcher.dispatch(new DrawHandfreeQueryPoints(!drawHandfreeQueryPoints))}
>
<DrawIcon />
</div>
<LocationButton queryPoints={query.queryPoints} />
</div>
<div className={styles.map}>
Expand All @@ -213,7 +241,16 @@ function LargeScreenLayout({ query, route, map, error, mapOptions, encodedValues
)
}

function SmallScreenLayout({ query, route, map, error, mapOptions, encodedValues, drawAreas }: LayoutProps) {
function SmallScreenLayout({
query,
route,
map,
error,
mapOptions,
encodedValues,
drawAreas,
drawHandfreeQueryPoints,
}: LayoutProps) {
return (
<>
<div className={styles.smallScreenSidebar}>
Expand All @@ -231,6 +268,13 @@ function SmallScreenLayout({ query, route, map, error, mapOptions, encodedValues
<div className={styles.smallScreenMapOptions}>
<div className={styles.onMapRightSide}>
<MapOptions {...mapOptions} />
<div
style={drawHandfreeQueryPoints ? { backgroundColor: 'black' } : {}}
className={styles.drawIcon}
onClick={e => Dispatcher.dispatch(new DrawHandfreeQueryPoints(!drawHandfreeQueryPoints))}
>
<DrawIcon />
</div>
<LocationButton queryPoints={query.queryPoints} />
</div>
</div>
Expand Down
10 changes: 9 additions & 1 deletion src/actions/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,15 @@ export class InstructionClicked implements Action {

export class ToggleDistanceUnits implements Action {}

export class DrawAreas implements Action {
export class DrawCustomModelAreas implements Action {
readonly enabled: boolean

constructor(enabled: boolean) {
this.enabled = enabled
}
}

export class DrawHandfreeQueryPoints implements Action {
readonly enabled: boolean

constructor(enabled: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class ApiImpl implements Api {
const routeNumber = this.routeCounter++

this.mapMatch(args)
// this.route(args)
// this.route(args)
.then(result => {
if (routeNumber > this.lastRouteNumber) {
this.lastRouteNumber = routeNumber
Expand Down
37 changes: 25 additions & 12 deletions src/layers/UsePathsLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import VectorSource from 'ol/source/Vector'
import { GeoJSON } from 'ol/format'
import { Stroke, Style } from 'ol/style'
import { fromLonLat } from 'ol/proj'
import { Draw, Select } from 'ol/interaction'
import { Draw, Modify, Select, Snap } from 'ol/interaction'
import { click, primaryAction } from 'ol/events/condition'
import Dispatcher from '@/stores/Dispatcher'
import { SetQueryPoints, SetSelectedPath } from '@/actions/Actions'
Expand All @@ -22,10 +22,18 @@ const selectedPathLayerKey = 'selectedPathLayer'
const accessNetworkLayerKey = 'accessNetworkLayer'
const handDrawQueryPointsLayerKey = 'handDrawQueryPointsLayer'

export default function usePathsLayer(map: Map, paths: Path[], selectedPath: Path, queryPoints: QueryPoint[]) {
export default function usePathsLayer(
map: Map,
paths: Path[],
selectedPath: Path,
queryPoints: QueryPoint[],
drawFreehandQueryPoints: boolean
) {
useEffect(() => {
removeHandDrawQueryPointsLayers(map)
addHandDrawQueryPointLayer(map)
removeDrawHandfreeQueryPointsLayers(map)

if (drawFreehandQueryPoints) addDrawFreehandQueryPointsLayer(map)
else removeDrawHandfreeQueryPointsLayers(map)

removeCurrentPathLayers(map)
addUnselectedPathsLayer(
Expand All @@ -36,9 +44,9 @@ export default function usePathsLayer(map: Map, paths: Path[], selectedPath: Pat
addAccessNetworkLayer(map, selectedPath, queryPoints)
return () => {
removeCurrentPathLayers(map)
removeHandDrawQueryPointsLayers(map)
removeDrawHandfreeQueryPointsLayers(map)
}
}, [map, paths, selectedPath])
}, [map, paths, selectedPath, drawFreehandQueryPoints])
}

function removeCurrentPathLayers(map: Map) {
Expand All @@ -48,14 +56,20 @@ function removeCurrentPathLayers(map: Map) {
.forEach(l => map.removeLayer(l))
}

function removeHandDrawQueryPointsLayers(map: Map) {
function removeDrawHandfreeQueryPointsLayers(map: Map) {
map.getInteractions()
.getArray()
.forEach(i => {
if ('gh:draw_handfree' == i.get('source') && i instanceof Draw) i.setActive(false)
})

map.getLayers()
.getArray()
.filter(l => l.get(handDrawQueryPointsLayerKey))
.forEach(l => map.removeLayer(l))
}

function addHandDrawQueryPointLayer(map: Map) {
function addDrawFreehandQueryPointsLayer(map: Map) {
const source = new VectorSource()

// TODO NOW cache style
Expand Down Expand Up @@ -87,7 +101,7 @@ function addHandDrawQueryPointLayer(map: Map) {
return [style]
},
})

vectorLayer.set(handDrawQueryPointsLayerKey, true)
map.addLayer(vectorLayer)

const draw = new Draw({
Expand All @@ -98,8 +112,7 @@ function addHandDrawQueryPointLayer(map: Map) {
// we handle this later
// maxPoints: 200,

/* TODO how to move the map? */
// freehand: false,
freehand: true,
source: source,
type: 'LineString',
})
Expand Down Expand Up @@ -149,7 +162,7 @@ function addHandDrawQueryPointLayer(map: Map) {
}
return false
})

draw.set('source', 'gh:draw_handfree')
map.addInteraction(draw)
}

Expand Down
1 change: 1 addition & 0 deletions src/map/gesture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions src/sidebar/CustomModelBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import styles from '@/sidebar/CustomModelBox.module.css'
import { useCallback, useEffect, useRef, useState } from 'react'
import { create } from 'custom-model-editor/src/index'
import Dispatcher from '@/stores/Dispatcher'
import { ClearRoute, DismissLastError, DrawAreas, SetCustomModel, SetCustomModelEnabled } from '@/actions/Actions'
import {
ClearRoute,
DismissLastError,
DrawCustomModelAreas,
SetCustomModel,
SetCustomModelEnabled,
} from '@/actions/Actions'
import { tr } from '@/translation/Translation'
import PlainButton from '@/PlainButton'
import { customModel2prettyString, customModelExamples } from '@/sidebar/CustomModelExamples'
Expand Down Expand Up @@ -101,7 +107,7 @@ export default function CustomModelBox({
className={styles.drawAreas}
title={tr('draw_areas_enabled')}
style={{ color: drawAreas ? '' : 'lightgray' }}
onClick={() => Dispatcher.dispatch(new DrawAreas(!drawAreas))}
onClick={() => Dispatcher.dispatch(new DrawCustomModelAreas(!drawAreas))}
>
{drawAreas ? <DrawAreasIcon /> : <DrawAreasDisabledIcon />}
</PlainButton>
Expand Down
18 changes: 14 additions & 4 deletions src/stores/SettingsStore.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import Store from '@/stores/Store'
import { Action } from '@/stores/Dispatcher'
import { DrawAreas, SetCustomModelEnabled, ToggleDistanceUnits } from '@/actions/Actions'
import {
DrawCustomModelAreas,
DrawHandfreeQueryPoints,
SetCustomModelEnabled,
ToggleDistanceUnits,
} from '@/actions/Actions'

export interface Settings {
showDistanceInMiles: boolean
drawAreasEnabled: boolean
handDrawQueryPointsEnabled: boolean
drawHandfreeQueryPointsEnabled: boolean
}

export default class SettingsStore extends Store<Settings> {
constructor() {
super({
showDistanceInMiles: false,
drawAreasEnabled: false,
handDrawQueryPointsEnabled: true,
drawHandfreeQueryPointsEnabled: false,
})
}

Expand All @@ -29,7 +34,12 @@ export default class SettingsStore extends Store<Settings> {
...state,
drawAreasEnabled: false,
}
} else if (action instanceof DrawAreas) {
} else if (action instanceof DrawHandfreeQueryPoints) {
return {
...state,
drawHandfreeQueryPointsEnabled: action.enabled,
}
} else if (action instanceof DrawCustomModelAreas) {
return {
...state,
drawAreasEnabled: action.enabled,
Expand Down

0 comments on commit 5ef578a

Please sign in to comment.