Skip to content

Move to Vector Tiles (MapLibreGL) #657

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

Merged
merged 82 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
cb12d2c
feat: migrate from Leaflet to MapLibreGL
miles-grant-ibigroup Jun 27, 2022
e9d1d51
Merge branch 'batch-ui-redesign' into vector-tiles
miles-grant-ibigroup Jun 27, 2022
c15ce6e
refactor: avoid senseless re-render
miles-grant-ibigroup Jun 27, 2022
bf9780d
refactor(metro-ui): support custom vector tile base layers
miles-grant-ibigroup Jun 28, 2022
6f7ad96
refactor: automatic bounds updating
miles-grant-ibigroup Jun 29, 2022
3388bb8
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Jun 30, 2022
cc08b77
refactor: bring back transit-vehicle-overlay
miles-grant-ibigroup Jun 30, 2022
425e33e
refactor(connected-transit-vehicle-overlay): support route color
miles-grant-ibigroup Jul 1, 2022
5bcd9c5
refactor(maplibregl): don't refresh map
miles-grant-ibigroup Jul 1, 2022
5636ce8
refactor(maplibregl): hack to support redux based panning
miles-grant-ibigroup Jul 1, 2022
5f49a41
refactor(maplibregl): show trip viewer
miles-grant-ibigroup Jul 1, 2022
edcd139
refactor(maplibregl): attempt at making zoom hack less troublesome
miles-grant-ibigroup Jul 1, 2022
743e97b
refactor(vector tiles): hack to make printable itinerary not display …
miles-grant-ibigroup Jul 11, 2022
da46914
chore: update lockfile
miles-grant-ibigroup Jul 12, 2022
e43307f
refactor: better handle poor data
miles-grant-ibigroup Jul 12, 2022
d925b37
refactor park and ride overlay to functional component
caleb-diehl-ibigroup Jul 14, 2022
69b8655
Merge branch 'vector-tiles' of github.com:opentripplanner/otp-react-r…
miles-grant-ibigroup Jul 14, 2022
dc30a87
stop viewer icon enhancements
caleb-diehl-ibigroup Jul 14, 2022
f4cffb4
stop viewer icon enhancements
caleb-diehl-ibigroup Jul 14, 2022
5406840
Merge branch 'vector-tiles' of https://github.com/opentripplanner/otp…
caleb-diehl-ibigroup Jul 14, 2022
a5f8ed2
route viewer styling changes
caleb-diehl-ibigroup Jul 14, 2022
e884e22
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Jul 19, 2022
a8f75f3
refactor: don't use named map
miles-grant-ibigroup Jul 19, 2022
1078086
Merge branch 'vector-tiles' of https://github.com/opentripplanner/otp…
caleb-diehl-ibigroup Jul 19, 2022
238f2d4
elevation styling
caleb-diehl-ibigroup Jul 19, 2022
1645098
add navigation control
caleb-diehl-ibigroup Jul 19, 2022
109b75b
refactor: support zoom to leg
miles-grant-ibigroup Jul 22, 2022
ba23fbe
refactor(route-viewer): make more use of route color
miles-grant-ibigroup Jul 22, 2022
275f8c3
chore(deps): upgrade otp-ui packages
miles-grant-ibigroup Jul 26, 2022
f95fff3
refactor(route-viewer): adjust style refresh
miles-grant-ibigroup Jul 27, 2022
41f6bfa
refactor(stop-viewer): calm borders
miles-grant-ibigroup Jul 27, 2022
bffdbcc
refactor: repair route block on webkit browsers
miles-grant-ibigroup Aug 5, 2022
cd79b79
fix(enhanced-stop-marker): fix icon sizing
daniel-heppner-ibigroup Aug 10, 2022
27e2899
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Aug 12, 2022
830dd23
refactor: resolve merge-related bugs
miles-grant-ibigroup Aug 12, 2022
e9bdd34
chore: update caniuse-lite
miles-grant-ibigroup Aug 12, 2022
704ab64
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Aug 29, 2022
9a614e9
refactor(pattern-viewer): ensure less garish background colors
miles-grant-ibigroup Aug 29, 2022
ed368d6
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Sep 2, 2022
8799e35
chore: address linter issues
miles-grant-ibigroup Sep 2, 2022
d42259c
refactor: revert bad typescript auto-change
miles-grant-ibigroup Sep 2, 2022
1dcf7b6
refactor(a11y): set screen resolution
miles-grant-ibigroup Sep 2, 2022
e9e661b
refactor(a11y): attempt to reload on problematic route
miles-grant-ibigroup Sep 2, 2022
44c30e1
refactor(a11y): attempt to reload on problematic route
miles-grant-ibigroup Sep 2, 2022
f3ef982
refactor: resolve regression breaking pattern viewer in OTP1
miles-grant-ibigroup Sep 6, 2022
93f7b77
chore(deps): upgrade otp-ui
miles-grant-ibigroup Sep 9, 2022
52836d3
refactor: clean up
miles-grant-ibigroup Sep 9, 2022
e1ace3c
test: update snapshots
miles-grant-ibigroup Sep 9, 2022
48b005a
refactor(route-viewer): use RouteRenderer
miles-grant-ibigroup Sep 9, 2022
420f7c3
refactor(apiv2): render color-less flex zones
miles-grant-ibigroup Sep 9, 2022
783fa22
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Sep 14, 2022
d3575aa
refactor: address pr feedback
miles-grant-ibigroup Sep 14, 2022
fbe1f96
refactor(route-viewer): render pattern viewer header in route color
miles-grant-ibigroup Sep 14, 2022
5bc23ce
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Sep 21, 2022
d8150f5
fix(PrintLayout): Remove map update on component mount
binh-dam-ibigroup Sep 22, 2022
f63e197
improvement(ResponsiveWebApp): Add MapProvider component
binh-dam-ibigroup Sep 22, 2022
01b8c8e
improvement(withMap): Add HOC to access native map object.
binh-dam-ibigroup Sep 22, 2022
e8b8f7c
refactor(StopViewer): Use map reference when fetching/zooming to stop
binh-dam-ibigroup Sep 22, 2022
a5bb996
refactor: Remove setMapZoom
binh-dam-ibigroup Sep 22, 2022
dbe423f
refactor(create-otp-reducer): Remove unused actions
binh-dam-ibigroup Sep 22, 2022
301fbcd
refactor(DefaultMap): Reimplement non-redux map state, extract PointP…
binh-dam-ibigroup Sep 22, 2022
f84007b
refactor: Fix types
binh-dam-ibigroup Sep 22, 2022
b436038
refactor(ResponsiveWebApp): Enable location focus on mobile view
binh-dam-ibigroup Sep 22, 2022
462c193
refactor: sort css
miles-grant-ibigroup Sep 23, 2022
266d367
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Sep 23, 2022
968fb83
docs(PrintLayout): Add FIXME comment for improving reframing/bounds
binh-dam-ibigroup Sep 23, 2022
747508b
improvement(StopViewer): Make zoom-to-stop fly the map to the stop.
binh-dam-ibigroup Sep 26, 2022
4b2380b
fix(ConnectedStopViewer): Run flyTo effect only if stop coordinates (…
binh-dam-ibigroup Sep 26, 2022
bc29368
fix(LiveStopTimes): Make real-time checkbox a controlled component.
binh-dam-ibigroup Sep 26, 2022
e359af2
test(StopViewer): Update snapshots
binh-dam-ibigroup Sep 26, 2022
db081d3
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Sep 26, 2022
e637dd7
refactor(LiveStopTimes): Fix types
binh-dam-ibigroup Sep 26, 2022
dcbc3d4
fix(DefaultMap): Prevent viewport reset when setting from/to locations.
binh-dam-ibigroup Sep 26, 2022
98bd530
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Sep 28, 2022
953e0c3
Merge branch 'vector-tiles' into vector-tiles-qbd
miles-grant-ibigroup Sep 28, 2022
5820753
Merge pull request #666 from opentripplanner/vector-tiles-qbd
miles-grant-ibigroup Sep 28, 2022
43b7bd2
refactor: repair spin prop
miles-grant-ibigroup Sep 28, 2022
afeb800
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Sep 28, 2022
213d0f8
test: update snapshots
miles-grant-ibigroup Sep 28, 2022
2f77c73
refactor: address pr feedback
miles-grant-ibigroup Oct 4, 2022
a93c6bf
Merge branch 'dev' into vector-tiles
miles-grant-ibigroup Oct 4, 2022
37494c2
refactor: address pr feedback
miles-grant-ibigroup Oct 10, 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
33,621 changes: 16,336 additions & 17,285 deletions __tests__/components/viewers/__snapshots__/stop-viewer.js.snap

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Object {
"mobile": "BOTH_LOCATIONS_CHANGED",
},
"debouncePlanTimeMs": 0,
"focusRoute": false,
"homeTimezone": "America/Los_Angeles",
"language": Object {},
"onTimeThresholdSeconds": 60,
Expand Down
5 changes: 5 additions & 0 deletions a11y/a11y.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ async function runAxeTestOnPath(otpPath) {
const page = await browser.newPage()
const filePath = `http://localhost:${MOCK_SERVER_PORT}/#${otpPath}`
await Promise.all([
page.setViewport({
deviceScaleFactor: 1,
height: 1080,
width: 1920
}),
page.goto(filePath),
page.waitForNavigation({ waitUntil: 'networkidle2' })
])
Expand Down
3 changes: 1 addition & 2 deletions index.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@import url(node_modules/bootstrap/dist/css/bootstrap.min.css);

@import url(https://unpkg.com/[email protected]/dist/leaflet.css);
@import url(node_modules/transitive-js/lib/transitive.css);
@import url(node_modules/maplibre-gl/dist/maplibre-gl.css);

@import url(lib/components/admin/call-taker.css);
@import url(lib/components/app/app.css);
Expand Down
4 changes: 2 additions & 2 deletions lib/actions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ export function vehicleRentalQuery(
export const findStopResponse = createAction('FIND_STOP_RESPONSE')
export const findStopError = createAction('FIND_STOP_ERROR')

export function fetchStopInfo(stop) {
return executeOTPAction('fetchStopInfo', stop)
export function fetchStopInfo(map, stop) {
return executeOTPAction('fetchStopInfo', map, stop)
}

// Single trip lookup query
Expand Down
20 changes: 16 additions & 4 deletions lib/actions/apiV1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import L from 'leaflet'
import qs from 'qs'

import {
Expand All @@ -16,6 +15,7 @@ import {
findRoutesAtStop,
findStopError,
findStopResponse,
findStopsForPattern,
findStopsForTrip,
findStopTimesForStop,
findStopTimesForTrip,
Expand All @@ -28,6 +28,10 @@ import {
import { setViewedStop } from './ui'
import { zoomToStop } from './map'

// Import must be done like this as maplibregl is incompatible with jest
let maplibregl = null
if (typeof jest === 'undefined') maplibregl = require('maplibre-gl')

const findTrip = (params) =>
createQueryAction(
`index/trips/${params.tripId}`,
Expand Down Expand Up @@ -56,7 +60,9 @@ export function vehicleRentalQuery(

function findNearbyAmenities({ lat, lon, radius = 300 }, stopId) {
return function (dispatch, getState) {
const bounds = L.latLng(lat, lon).toBounds(radius)
if (typeof jest !== 'undefined') return

const bounds = new maplibregl.LngLat(lon, lat).toBounds(radius)
const { lat: low, lng: left } = bounds.getSouthWest()
const { lat: up, lng: right } = bounds.getNorthEast()
dispatch(
Expand Down Expand Up @@ -123,7 +129,7 @@ export const findStop = (params) =>
}
)

const fetchStopInfo = (stop) =>
const fetchStopInfo = (map, stop) =>
async function (dispatch, getState) {
await dispatch(findStop({ stopId: stop.stopId }))
const state = getState()
Expand All @@ -149,7 +155,7 @@ const fetchStopInfo = (stop) =>
dispatch(
findNearbyAmenities({ lat, lon, radius: nearbyRadius }, stop.stopId)
)
dispatch(zoomToStop(fetchedStop))
dispatch(zoomToStop(map, fetchedStop))
}
}

Expand Down Expand Up @@ -189,6 +195,12 @@ export const findPatternsForRoute = (params) =>
})
)
}
dispatch(
findStopsForPattern({
patternId: ptn.id,
routeId: params.routeId
})
)
})
},

Expand Down
39 changes: 22 additions & 17 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import {
receivedVehiclePositions,
receivedVehiclePositionsError
} from './api'
import { setMapZoom } from './config'
import { zoomToStop } from './map'

const LIGHT_GRAY = '666666'

/**
* Generic helper for crafting GraphQL queries.
*/
Expand Down Expand Up @@ -147,7 +148,7 @@ export const vehicleRentalQuery = (
// we should re-write the rest of the UI to match OTP's behavior instead
rewritePayload: (payload) => {
return {
stations: payload?.data?.rentalVehicles.map((vehicle) => {
stations: payload?.data?.rentalVehicles?.map((vehicle) => {
return {
allowPickup: vehicle.allowPickupNow,
id: vehicle.vehicleId,
Expand Down Expand Up @@ -297,27 +298,27 @@ const findNearbyAmenities = ({ lat, lon, radius = 300, stopId }) => {
{
noThrottle: true,
rewritePayload: (payload) => {
if (!payload.data)
if (!payload.data?.nearest)
return {
bikeRental: { stations: [] },
vehicleRentalQuery: { stations: [] }
}
const { edges } = payload.data.nearest || []
const bikeStations = edges.filter(
const bikeStations = edges?.filter(
(edge) =>
edge?.node?.place?.bikesAvailable !== undefined ||
!!edge?.node?.place?.bicyclePlaces ||
edge?.node?.place?.vehicleType?.formFactor === 'BICYCLE'
)
const parkAndRides = edges.filter(
const parkAndRides = edges?.filter(
(edge) => edge?.node?.place?.carPlaces
)
const vehicleRentals = edges.filter(
const vehicleRentals = edges?.filter(
(edge) => edge?.node?.place?.vehicleType?.formFactor === 'SCOOTER'
)
return {
bikeRental: {
stations: bikeStations.map((edge) => {
stations: bikeStations?.map((edge) => {
const {
__typename,
bikesAvailable,
Expand All @@ -344,7 +345,7 @@ const findNearbyAmenities = ({ lat, lon, radius = 300, stopId }) => {
}
})
},
parkAndRideLocations: parkAndRides.map((edge) => {
parkAndRideLocations: parkAndRides?.map((edge) => {
const { id, lat, lon, name } = edge?.node?.place
return {
distance: edge.node.distance,
Expand All @@ -358,7 +359,7 @@ const findNearbyAmenities = ({ lat, lon, radius = 300, stopId }) => {
}),
stopId,
vehicleRental: {
stations: vehicleRentals.map((edge) => {
stations: vehicleRentals?.map((edge) => {
const { id, lat, lon, name, network, networks } =
edge?.node?.place
return {
Expand All @@ -380,7 +381,7 @@ const findNearbyAmenities = ({ lat, lon, radius = 300, stopId }) => {
)
}

const fetchStopInfo = (stop) => {
const fetchStopInfo = (map, stop) => {
const { stopId } = stop
if (!stopId)
return function (dispatch, getState) {
Expand Down Expand Up @@ -424,17 +425,20 @@ const fetchStopInfo = (stop) => {
})
)

dispatch(zoomToStop(stop))

if (stop?.geometries?.geoJson?.type !== 'Point') {
dispatch(setMapZoom(10))
}
dispatch(
zoomToStop(
map,
stop,
stop?.geometries?.geoJson?.type !== 'Point' && 10
)
)
},
rewritePayload: (payload) => {
const { stop } = payload?.data
if (!stop) return findStopError()

const color = stop.routes?.length > 0 && `#${stop.routes[0].color}`
const color =
stop.routes?.length > 0 && `#${stop.routes[0]?.color || LIGHT_GRAY}`

// Doing some OTP1 compatibility rewriting here
return {
Expand Down Expand Up @@ -583,7 +587,8 @@ export const findRoute = (params) =>
newRoute.patterns.forEach((pattern) => {
const patternStops = pattern.stops.map((stop) => {
const color =
stop.routes?.length > 0 && `#${stop.routes[0].color}`
stop.routes?.length > 0 &&
`#${stop.routes[0]?.color || LIGHT_GRAY}`
if (stop.routes) delete stop.routes
return { ...stop, color }
})
Expand Down
2 changes: 0 additions & 2 deletions lib/actions/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ import { createAction } from 'redux-actions'
export const setAutoPlan = createAction('SET_AUTOPLAN')

// TODO: this should eventually be handled via mapState
export const setMapCenter = createAction('SET_MAP_CENTER')
export const setMapZoom = createAction('SET_MAP_ZOOM')
export const setRouterId = createAction('SET_ROUTER_ID')
export const updateOverlayVisibility = createAction('UPDATE_OVERLAY_VISIBILITY')
28 changes: 21 additions & 7 deletions lib/actions/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import getGeocoder from '@opentripplanner/geocoder'
import { clearActiveSearch } from './form'
import { deleteUserPlace } from './user'
import { routingQuery } from './api'
import { setMapCenter, setMapZoom } from './config'

/* SET_LOCATION action creator. Updates a from or to location in the store
*
Expand Down Expand Up @@ -47,11 +46,26 @@ export function clearLocation(payload) {
}
}

export function zoomToStop(stop) {
return function (dispatch, getState) {
if (!stop) return
dispatch(setMapZoom({ zoom: 17 }))
dispatch(setMapCenter({ lat: stop.lat, lon: stop.lon }))
/**
* Centers the given map to the coordinates of the specified place.
*/
export function setMapCenter(map /* MapRef */, location, zoom) {
return function () {
const { lat, lon } = location
if (map && !isNaN(lat) && !isNaN(lon)) {
map.jumpTo({ center: [lon, lat], zoom })
}
}
}

/**
* Animates the map to the specified stop and the specified zoom level.
*/
export function zoomToStop(map /* MapRef */, stop, zoom) {
return function () {
if (stop && map) {
map.flyTo({ center: [stop.lon, stop.lat], zoom: zoom || 17 })
}
}
}

Expand Down Expand Up @@ -148,7 +162,7 @@ export const setElevationPoint = createAction('SET_ELEVATION_POINT')
export const setMapPopupLocation = createAction('SET_MAP_POPUP_LOCATION')

export function setMapPopupLocationAndGeocode(mapEvent) {
const location = coreUtils.map.constructLocation(mapEvent.latlng)
const location = coreUtils.map.constructLocation(mapEvent.lngLat)
return function (dispatch, getState) {
dispatch(setMapPopupLocation({ location }))
getGeocoder(getState().otp.config.geocoder)
Expand Down
20 changes: 14 additions & 6 deletions lib/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { getModesForActiveAgencyFilter, getUiUrlParams } from '../util/state'
import { getPathFromParts } from '../util/ui'

import { clearActiveSearch, parseUrlQueryString, setActiveSearch } from './form'
import { clearLocation } from './map'
import { clearLocation, setMapCenter } from './map'
import { findRoute, setUrlSearch } from './api'
import { setActiveItinerary } from './narrative'
import { setMapCenter, setMapZoom, setRouterId } from './config'
import { setRouterId } from './config'

const updateLocale = createAction('UPDATE_LOCALE')

Expand Down Expand Up @@ -62,7 +62,6 @@ const viewStop = createAction('SET_VIEWED_STOP')
export const setHoveredStop = createAction('SET_HOVERED_STOP')
export const setViewedTrip = createAction('SET_VIEWED_TRIP')
const viewRoute = createAction('SET_VIEWED_ROUTE')
export const unfocusRoute = createAction('UNFOCUS_ROUTE')
export const toggleAutoRefresh = createAction('TOGGLE_AUTO_REFRESH')
const setPreviousItineraryView = createAction('SET_PREVIOUS_ITINERARY_VIEW')
export const setPopupContent = createAction('SET_POPUP_CONTENT')
Expand Down Expand Up @@ -97,6 +96,16 @@ export function routeTo(url, replaceSearch, routingMethod = push) {

export function setViewedRoute(payload) {
return function (dispatch, getState) {
const { otp } = getState()
const { viewedRoute } = otp.ui
if (
viewedRoute &&
payload?.viewedRoute?.routeId === viewedRoute.routeId &&
payload?.viewedRoute?.patternId === viewedRoute.patternId
) {
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use braces.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added in d3575aa

Copy link
Contributor

Choose a reason for hiding this comment

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

Not seeing braces.

}

dispatch(viewRoute(payload))

const path = getPathFromParts(
Expand Down Expand Up @@ -167,7 +176,7 @@ function idToParams(id, delimiter = ',') {
* Checks URL and redirects app to appropriate content (e.g., viewed
* route or stop).
*/
export function matchContentToUrl(location) {
export function matchContentToUrl(map, location) {
// eslint-disable-next-line complexity
return function (dispatch, getState) {
const state = getState()
Expand Down Expand Up @@ -224,8 +233,7 @@ export function matchContentToUrl(location) {
}
console.log(lat, lon, zoom, routerId)
// Update map location/zoom and optionally override router ID.
if (+lat && +lon) dispatch(setMapCenter({ lat, lon }))
if (+zoom) dispatch(setMapZoom({ zoom }))
if (+lat && +lon) dispatch(setMapCenter(map, { lat, lon }, zoom))
// If router ID is provided, override the default routerId.
if (routerId) dispatch(setRouterId(routerId))
dispatch(setMainPanelContent(null))
Expand Down
Loading