Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OpenLayers instead of Mapbox #176

Merged
merged 70 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
f3d4246
Replace awesome-typescript-loader with ts-loader, update package-lock…
easbar Nov 10, 2021
c33d240
Upgrade to npm 8.1.0, lockfileVersion 2
easbar Nov 10, 2021
233faaa
remove mapbox, add ol
easbar Nov 10, 2021
83e637d
hello ol
easbar Nov 10, 2021
02e1e1e
disable test for now
easbar Nov 10, 2021
18f51f9
Remove @types/ol
easbar Nov 11, 2021
8f26073
code formatting
easbar Nov 11, 2021
5c6bf18
Enable other raster layers
easbar Nov 11, 2021
a5aa582
Enable commented out raster layers too (they work with OL)
easbar Nov 11, 2021
2dc764d
Include vector tiles using ol-mapbox-style
easbar Nov 11, 2021
64e119f
Properly remove existing layers
easbar Nov 11, 2021
be71e3e
trigger build
easbar Nov 11, 2021
f24b454
Move MapStore and BackgroundLayer out of Map component
easbar Nov 11, 2021
686b2a3
Show paths layer and dummy markers
easbar Nov 11, 2021
520fc7e
Handle view change actions
easbar Nov 11, 2021
bb2f14a
remove controls
easbar Nov 11, 2021
03e6186
Remove MapLayer, add some comments
easbar Nov 12, 2021
7ccf309
Update route when dragging markers
easbar Nov 12, 2021
9529a3d
code formatting
easbar Nov 12, 2021
f75c4d9
Allow click selection of alternative paths
easbar Nov 12, 2021
a270a38
Add context menu
easbar Nov 12, 2021
24c4d68
disable user selection on ios
Oct 29, 2021
cb3e74e
Make context menu work on ios using long touch handler
easbar Nov 15, 2021
4e1b5e1
code formatting
easbar Nov 15, 2021
ddc0764
Add map attributions
easbar Nov 15, 2021
738db85
Add function names
easbar Nov 15, 2021
bf63e92
Update comments
easbar Nov 15, 2021
44aba35
Merge branch 'master' into fix_package_lock
easbar Nov 16, 2021
ff9ccb1
Merge branch 'fix_package_lock' into ol_exp
easbar Nov 16, 2021
09e426f
Merge branch 'master' into fix_package_lock
easbar Nov 16, 2021
172c1c0
Merge branch 'fix_package_lock' into ol_exp
easbar Nov 16, 2021
6f2d51b
Update package-lock.json
easbar Nov 16, 2021
46bf484
Add path detail popup and elevation visualization
easbar Nov 16, 2021
c9cd40a
Update package-lock.json
easbar Nov 17, 2021
f2213e2
Add markers (still has a few issues)
easbar Nov 17, 2021
44f833b
Update package-lock.json
easbar Nov 17, 2021
313fa38
Merge branch 'fix_package_lock' into ol_exp
easbar Nov 17, 2021
2b93d66
Add px and backtick for translate transform of SVG marker (as in Mark…
easbar Nov 17, 2021
d1fda59
Update todo comments
easbar Nov 17, 2021
7528a3c
Fix cursor appearance when hovering the map and when grabbing markers…
easbar Nov 17, 2021
0744bcb
Do not change cursor for vector tile elements
easbar Nov 17, 2021
29f749b
Set maxZoom for different raster tile layers
easbar Nov 17, 2021
6972a78
Merge branch 'master' into fix_package_lock
easbar Nov 18, 2021
3ddf866
Update package-lock.json again
easbar Nov 18, 2021
dddea6c
go back to node gallium
easbar Nov 18, 2021
5cac394
Remove tileSize, add tilePixelRatio for 2x tiles
easbar Nov 19, 2021
07b7967
Update readme (use fermium for now)
easbar Nov 22, 2021
60f4c4e
Merge branch 'master' into fix_package_lock
easbar Nov 22, 2021
eb400e4
Merge branch 'fix_package_lock' into ol_exp
easbar Nov 22, 2021
0673b58
Update to master
easbar Nov 22, 2021
1b0a795
No fit bounds for /info bbox, disable view animation
easbar Nov 22, 2021
f598f40
Merge branch 'master' into ol_exp
easbar Dec 2, 2021
ea787a5
code formatting
easbar Dec 2, 2021
dafbbac
Merge branch 'master' into ol_exp
easbar Dec 4, 2021
eadca9e
Merge branch 'master' into ol_exp
easbar Jan 17, 2022
ad10643
Use raster tiles by default
easbar Jan 18, 2022
a8bd00b
Merge branch 'master' into ol_exp
easbar Jan 18, 2022
fa2af4d
estimate bbox from query points
easbar Jan 18, 2022
c2ba47c
Use custom hooks for layers
easbar Jan 18, 2022
2e4dddc
Make map just an action receiver instead of a store
easbar Jan 18, 2022
8c75821
Separate map creation from action receiving code
easbar Jan 18, 2022
3e0cb14
minor
easbar Jan 18, 2022
ff745d0
Merge branch 'master' into ol_exp
easbar Jan 19, 2022
adb8315
Remove allowJs, use typed useRef etc.
easbar Jan 19, 2022
d9213ec
Use display grid for App module instead of 100% height/width for map
easbar Jan 19, 2022
74ab4a7
Use Omniscale tiles by default
easbar Jan 20, 2022
dd0ade8
Fix map size estimation for initial bbox choice
easbar Jan 20, 2022
e41435c
aws deployment does not show map on mobile, try to revert css change
easbar Jan 20, 2022
d401067
Really? Revert "aws deployment does not show map on mobile, try to re…
easbar Jan 20, 2022
3976084
go back to start... Revert "Really? Revert "aws deployment does not s…
easbar Jan 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
403 changes: 186 additions & 217 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
"test": "jest"
},
"dependencies": {
"geojson": "^0.5.0",
"leaflet.heightgraph": "github:easbar/Leaflet.Heightgraph#82cff7b3013dd73d7221521c5b404ded6439e050",
"ol": "^6.9.0",
"ol-mapbox-style": "^6.5.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-map-gl": "^5.3.17",
"react-responsive": "^8.2.0"
},
"devDependencies": {
"@svgr/webpack": "^5.5.0",
"@types/geojson": "^7946.0.8",
"@types/jest": "^26.0.24",
"@types/react": "^17.0.36",
"@types/react-dom": "^17.0.11",
Expand Down
66 changes: 26 additions & 40 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import {
getPathDetailsStore,
getQueryStore,
getRouteStore,
getViewportStore,
} from '@/stores/Stores'
import MapComponent from '@/map/Map'
import MapComponent from '@/map/MapComponent'
import { ApiInfo } from '@/api/graphhopper'
import MapOptions from '@/map/MapOptions'
import MobileSidebar from '@/sidebar/MobileSidebar'
Expand All @@ -23,11 +22,14 @@ import { MapOptionsStoreState } from '@/stores/MapOptionsStore'
import { ErrorStoreState } from '@/stores/ErrorStore'
import Search from '@/sidebar/search/Search'
import ErrorMessage from '@/sidebar/ErrorMessage'
import { ViewportStoreState } from '@/stores/ViewportStore'
import createPathDetailsLayer from '@/layers/PathDetailsLayer'
import createQueryPointsLayer from '@/layers/QueryPointsLayer'
import createPathsLayer from '@/layers/PathsLayer'
import { MapLayer } from '@/layers/MapLayer'
import useBackgroundLayer from '@/layers/UseBackgroundLayer'
import useQueryPointsLayer from '@/layers/UseQueryPointsLayer'
import usePathsLayer from '@/layers/UsePathsLayer'
import ContextMenu from '@/layers/ContextMenu'
import usePathDetailsLayer from '@/layers/UsePathDetailsLayer'
import PathDetailPopup from '@/layers/PathDetailPopup'
import { Map } from 'ol'
import { getMap } from '@/map/map'

export const POPUP_CONTAINER_ID = 'popup-container'
export const SIDEBAR_CONTENT_ID = 'sidebar-content'
Expand All @@ -39,7 +41,8 @@ export default function App() {
const [error, setError] = useState(getErrorStore().state)
const [mapOptions, setMapOptions] = useState(getMapOptionsStore().state)
const [pathDetails, setPathDetails] = useState(getPathDetailsStore().state)
const [viewport, setViewport] = useState(getViewportStore().state)

const map = getMap()

useEffect(() => {
const onQueryChanged = () => setQuery(getQueryStore().state)
Expand All @@ -48,15 +51,13 @@ export default function App() {
const onErrorChanged = () => setError(getErrorStore().state)
const onMapOptionsChanged = () => setMapOptions(getMapOptionsStore().state)
const onPathDetailsChanged = () => setPathDetails(getPathDetailsStore().state)
const onViewportChanged = () => setViewport(getViewportStore().state)

getQueryStore().register(onQueryChanged)
getApiInfoStore().register(onInfoChanged)
getRouteStore().register(onRouteChanged)
getErrorStore().register(onErrorChanged)
getMapOptionsStore().register(onMapOptionsChanged)
getPathDetailsStore().register(onPathDetailsChanged)
getViewportStore().register(onViewportChanged)

return () => {
getQueryStore().deregister(onQueryChanged)
Expand All @@ -65,26 +66,25 @@ export default function App() {
getErrorStore().deregister(onErrorChanged)
getMapOptionsStore().deregister(onMapOptionsChanged)
getPathDetailsStore().deregister(onPathDetailsChanged)
getViewportStore().deregister(onViewportChanged)
}
})

const isSmallScreen = useMediaQuery({ query: '(max-width: 44rem)' })

const mapLayers: MapLayer[] = [
createQueryPointsLayer(query.queryPoints),
createPathsLayer(route.selectedPath, route.routingResult.paths),
]
if (!isSmallScreen) mapLayers.push(createPathDetailsLayer(pathDetails))
// our different map layers
useBackgroundLayer(map, mapOptions.selectedStyle)
usePathsLayer(map, route.routingResult.paths, route.selectedPath)
useQueryPointsLayer(map, query.queryPoints)
usePathDetailsLayer(map, pathDetails)

const isSmallScreen = useMediaQuery({ query: '(max-width: 44rem)' })
return (
<div className={styles.appWrapper}>
<PathDetailPopup map={map} pathDetails={pathDetails} />
<ContextMenu map={map} route={route} queryPoints={query.queryPoints} />
{isSmallScreen ? (
<SmallScreenLayout
query={query}
route={route}
viewport={viewport}
mapLayers={mapLayers}
map={map}
mapOptions={mapOptions}
error={error}
info={info}
Expand All @@ -93,8 +93,7 @@ export default function App() {
<LargeScreenLayout
query={query}
route={route}
viewport={viewport}
mapLayers={mapLayers}
map={map}
mapOptions={mapOptions}
error={error}
info={info}
Expand All @@ -107,14 +106,13 @@ export default function App() {
interface LayoutProps {
query: QueryStoreState
route: RouteStoreState
viewport: ViewportStoreState
mapLayers: MapLayer[]
map: Map
mapOptions: MapOptionsStoreState
error: ErrorStoreState
info: ApiInfo
}

function LargeScreenLayout({ query, route, viewport, mapLayers, error, mapOptions, info }: LayoutProps) {
function LargeScreenLayout({ query, route, map, error, mapOptions, info }: LayoutProps) {
return (
<>
<div className={styles.sidebar}>
Expand All @@ -140,13 +138,7 @@ function LargeScreenLayout({ query, route, viewport, mapLayers, error, mapOption
</div>
<div className={styles.popupContainer} id={POPUP_CONTAINER_ID} />
<div className={styles.map}>
<MapComponent
viewport={viewport}
styleOption={mapOptions.selectedStyle}
queryPoints={query.queryPoints}
route={route}
mapLayers={mapLayers}
/>
<MapComponent map={map} />
</div>
<div className={styles.mapOptions}>
<MapOptions {...mapOptions} />
Expand All @@ -159,20 +151,14 @@ function LargeScreenLayout({ query, route, viewport, mapLayers, error, mapOption
)
}

function SmallScreenLayout({ query, route, viewport, mapLayers, error, mapOptions, info }: LayoutProps) {
function SmallScreenLayout({ query, route, map, error, mapOptions, info }: LayoutProps) {
return (
<>
<div className={styles.smallScreenSidebar}>
<MobileSidebar info={info} query={query} route={route} error={error} />
</div>
<div className={styles.smallScreenMap}>
<MapComponent
viewport={viewport}
queryPoints={query.queryPoints}
styleOption={mapOptions.selectedStyle}
route={route}
mapLayers={mapLayers}
/>
<MapComponent map={map} />
</div>
<div className={styles.smallScreenMapOptions}>
<div className={styles.smallScreenMapOptionsContent}>
Expand Down
21 changes: 6 additions & 15 deletions src/actions/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Coordinate, QueryPoint } from '@/stores/QueryStore'
import { ApiInfo, Bbox, Path, RoutingArgs, RoutingProfile, RoutingResult } from '@/api/graphhopper'
import { StyleOption } from '@/stores/MapOptionsStore'
import { PathDetailsPoint } from '@/stores/PathDetailsStore'
import { ViewportStoreState } from '@/stores/ViewportStore'

export class InfoReceived implements Action {
readonly result: ApiInfo
Expand Down Expand Up @@ -108,11 +107,13 @@ export class SelectMapStyle implements Action {

export class MapIsLoaded implements Action {}

export class SetViewport implements Action {
readonly viewport: ViewportStoreState
export class ZoomMapToPoint implements Action {
readonly coordinate: Coordinate
readonly zoom: number

constructor(viewport: ViewportStoreState) {
this.viewport = viewport
constructor(coordinate: Coordinate, zoom: number) {
this.coordinate = coordinate
this.zoom = zoom
}
}

Expand All @@ -124,16 +125,6 @@ export class SetInitialBBox implements Action {
}
}

export class SetViewportToPoint implements Action {
readonly coordinate: Coordinate
readonly zoom: number

constructor(coordinate: Coordinate, zoom: number) {
this.coordinate = coordinate
this.zoom = zoom
}
}

export class PathDetailsHover implements Action {
readonly pathDetailsPoint: PathDetailsPoint | null

Expand Down
15 changes: 9 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
getPathDetailsStore,
getQueryStore,
getRouteStore,
getViewportStore,
setStores,
} from '@/stores/Stores'
import Dispatcher from '@/stores/Dispatcher'
Expand All @@ -20,10 +19,11 @@ import QueryStore from '@/stores/QueryStore'
import ErrorStore from '@/stores/ErrorStore'
import MapOptionsStore from '@/stores/MapOptionsStore'
import PathDetailsStore from '@/stores/PathDetailsStore'
import ViewportStore from '@/stores/ViewportStore'
import NavBar from '@/NavBar'
import * as config from 'config'
import { getApi, setApi } from '@/api/Api'
import MapActionReceiver from '@/stores/MapActionReceiver'
import { createMap, getMap, setMap } from '@/map/map'

let locale = new URL(window.location.href).searchParams.get('locale')
setTranslation(locale || navigator.language)
Expand All @@ -33,26 +33,29 @@ setApi(config.api, getApiKey())
const queryStore = new QueryStore(getApi())
const routeStore = new RouteStore(queryStore)

const smallScreenMediaQuery = window.matchMedia('(max-width: 44rem)')

setStores({
queryStore: queryStore,
routeStore: routeStore,
infoStore: new ApiInfoStore(),
errorStore: new ErrorStore(),
mapOptionsStore: new MapOptionsStore(),
pathDetailsStore: new PathDetailsStore(),
viewportStore: new ViewportStore(routeStore, () => smallScreenMediaQuery.matches),
})

setMap(createMap())

// register stores at dispatcher to receive actions
Dispatcher.register(getQueryStore())
Dispatcher.register(getRouteStore())
Dispatcher.register(getApiInfoStore())
Dispatcher.register(getErrorStore())
Dispatcher.register(getMapOptionsStore())
Dispatcher.register(getPathDetailsStore())
Dispatcher.register(getViewportStore())

// register map action receiver
const smallScreenMediaQuery = window.matchMedia('(max-width: 44rem)')
const mapActionReceiver = new MapActionReceiver(getMap(), routeStore, () => smallScreenMediaQuery.matches)
Dispatcher.register(mapActionReceiver)

getApi().infoWithDispatch() // get infos about the api as soon as possible

Expand Down
37 changes: 37 additions & 0 deletions src/layers/ContextMenu.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* todo: this is just copy-pasta from https://openlayers.org/en/latest/examples/popup.html, I have no idea what all this means,
and the popup looks ugly still, at the very minimum the background color needs to be set though
the popup design needs an overhaul anyway... https://github.com/graphhopper/graphhopper-maps/issues/136
*/
.popup {
Comment on lines +1 to +5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared to the react-map-gl wrapper OpenLayers does not provide a popup component. Therefore I used a simple div and copy-pasted some css from the OpenLayers examples for the context menu and path details popup. I'm pretty sure this can be improved...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a better template at hand at the moment. Since this is such a big PR already, I would suggest to go with this version.

position: absolute;
background-color: white;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
padding: 15px;
border-radius: 10px;
border: 1px solid #cccccc;
bottom: 12px;
left: -50px;
min-width: 100px;
}
.popup:after,
.popup:before {
top: 100%;
border: solid transparent;
content: ' ';
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.popup:after {
border-top-color: white;
border-width: 10px;
left: 48px;
margin-left: -10px;
}
.popup:before {
border-top-color: #cccccc;
border-width: 11px;
left: 48px;
margin-left: -11px;
}
Loading