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

Add stop layer to new Debug UI #5602

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2218c1a
Add new debug vector tiles
leonardehrenfried Dec 19, 2023
176187c
Add stop layer to tile.json
leonardehrenfried Dec 19, 2023
7aaf79f
Move classes into their own packages
leonardehrenfried Dec 19, 2023
033000a
Move styles into separate class
leonardehrenfried Dec 20, 2023
57f07dd
Use style.json from server
leonardehrenfried Dec 21, 2023
71f7393
Refactor dependencies of map style classes
leonardehrenfried Dec 21, 2023
ffd8ae6
Add popup data
leonardehrenfried Dec 22, 2023
da28cf2
Remove edge layer builder
leonardehrenfried Dec 30, 2023
18eb243
Make styles a but prettier
leonardehrenfried Dec 30, 2023
7cfbae8
Add test for debug style spec
leonardehrenfried Dec 30, 2023
c7395d8
Save a JSON round trip
leonardehrenfried Dec 30, 2023
934b809
Add attribution, remove client side style
leonardehrenfried Jan 2, 2024
826a842
Add documentation, fix frontend code
leonardehrenfried Jan 2, 2024
c864200
Make TS compiler happy
leonardehrenfried Jan 2, 2024
a18d77d
Convert from class to type
leonardehrenfried Jan 2, 2024
1cbce1f
Use optional chaining
leonardehrenfried Jan 2, 2024
bed4eff
Rename the feature flag DebugClient to DebugUi, remove separate one f…
leonardehrenfried Jan 9, 2024
c4523af
Merge remote-tracking branch 'upstream/dev-2.x' into vector-debug
leonardehrenfried Jan 9, 2024
4b98891
Update comment
leonardehrenfried Jan 9, 2024
2b65d57
Make mapStyle configurable
leonardehrenfried Jan 9, 2024
756a289
Use proper copyright symbol
leonardehrenfried Jan 9, 2024
0503e9f
Merge remote-tracking branch 'upstream/dev-2.x' into vector-debug
leonardehrenfried Jan 11, 2024
5972e5d
Resolve merge artifacts
leonardehrenfried Jan 11, 2024
4fd4325
Update docs
leonardehrenfried Jan 11, 2024
c5dc289
Apply review feedback
leonardehrenfried Jan 11, 2024
24d5929
Remove extra function definition
leonardehrenfried Jan 11, 2024
cf5d875
Remove extra method call indirection
leonardehrenfried Jan 11, 2024
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
3 changes: 2 additions & 1 deletion client-next/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_API_URL=/otp/routers/default/transmodel/index/graphql
VITE_API_URL=/otp/routers/default/transmodel/index/graphql
VITE_DEBUG_STYLE_URL=/otp/routers/default/inspector/vectortile/style.json
3 changes: 2 additions & 1 deletion client-next/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_API_URL=http://localhost:8080/otp/routers/default/transmodel/index/graphql
VITE_API_URL=http://localhost:8080/otp/routers/default/transmodel/index/graphql
VITE_DEBUG_STYLE_URL=http://localhost:8080/otp/routers/default/inspector/vectortile/style.json
27 changes: 27 additions & 0 deletions client-next/src/components/MapView/GeometryPropertyPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { LngLat, Popup } from 'react-map-gl';
import { Table } from 'react-bootstrap';

export function GeometryPropertyPopup({
coordinates,
properties,
onClose,
}: {
coordinates: LngLat;
properties: { [s: string]: string };
onClose: () => void;
}) {
return (
<Popup latitude={coordinates.lat} longitude={coordinates.lng} closeButton={true} onClose={() => onClose()}>
<Table bordered>
<tbody>
{Object.entries(properties).map(([key, value]) => (
<tr key={key}>
<th scope="row">{key}</th>
<td>{value}</td>
</tr>
))}
</tbody>
</Table>
</Popup>
);
}
48 changes: 40 additions & 8 deletions client-next/src/components/MapView/MapView.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LngLat, Map, NavigationControl } from 'react-map-gl';
import { LngLat, Map, MapboxGeoJSONFeature, NavigationControl } from 'react-map-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
import { TripPattern, TripQuery, TripQueryVariables } from '../../gql/graphql.ts';
import { NavigationMarkers } from './NavigationMarkers.tsx';
import { LegLines } from './LegLines.tsx';
import { useMapDoubleClick } from './useMapDoubleClick.ts';
import { mapStyle } from './mapStyle.ts';
import { useState } from 'react';
import { ContextMenuPopup } from './ContextMenuPopup.tsx';
import { GeometryPropertyPopup } from './GeometryPropertyPopup.tsx';

// TODO: this should be configurable
const initialViewState = {
Expand All @@ -15,6 +15,10 @@ const initialViewState = {
zoom: 4,
};

const styleUrl = import.meta.env.VITE_DEBUG_STYLE_URL;

type PopupData = { coordinates: LngLat; feature: MapboxGeoJSONFeature };

export function MapView({
tripQueryVariables,
setTripQueryVariables,
Expand All @@ -29,20 +33,41 @@ export function MapView({
loading: boolean;
}) {
const onMapDoubleClick = useMapDoubleClick({ tripQueryVariables, setTripQueryVariables });
const [showPopup, setShowPopup] = useState<LngLat | null>(null);
const [showContextPopup, setShowContextPopup] = useState<LngLat | null>(null);
const [showPropsPopup, setShowPropsPopup] = useState<PopupData | null>(null);
const showFeaturePropPopup = (
e: mapboxgl.MapMouseEvent & {
features?: mapboxgl.MapboxGeoJSONFeature[] | undefined;
},
) => {
if (e.features) {
// if you click on a cluster of map features it's possible that there are multiple
// to select from. we are using the first one instead of presenting a selection UI.
// you can always zoom in closer if you want to make a more specific click.
const feature = e.features[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

That's neat. A potential improvement could be to instead zoom in one level if you encounter a cluster? Not critical for me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if that would be a good or bad UX but I'm willing to try it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's something I've seen in other map implementations at least.

Copy link
Member Author

Choose a reason for hiding this comment

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

We agreed that we will implement in an upcoming PR.

setShowPropsPopup({ coordinates: e.lngLat, feature: feature });
}
};

return (
<div className="map-container below-content">
<Map
// @ts-ignore
mapLib={import('maplibre-gl')}
// @ts-ignore
mapStyle={mapStyle}
mapStyle={styleUrl}
initialViewState={initialViewState}
onDblClick={onMapDoubleClick}
onContextMenu={(e) => {
setShowPopup(e.lngLat);
setShowContextPopup(e.lngLat);
}}
interactiveLayerIds={['regular-stop']}
onClick={showFeaturePropPopup}
// put lat/long in URL and pan to it on page reload
hash={true}
// disable pitching and rotating the map
touchPitch={false}
dragRotate={false}
>
<NavigationControl position="top-left" />
<NavigationMarkers
Expand All @@ -53,12 +78,19 @@ export function MapView({
{tripQueryResult?.trip.tripPatterns.length && (
<LegLines tripPattern={tripQueryResult.trip.tripPatterns[selectedTripPatternIndex] as TripPattern} />
)}
{showPopup && (
{showContextPopup && (
<ContextMenuPopup
tripQueryVariables={tripQueryVariables}
setTripQueryVariables={setTripQueryVariables}
coordinates={showPopup}
onClose={() => setShowPopup(null)}
coordinates={showContextPopup}
onClose={() => setShowContextPopup(null)}
/>
)}
{showPropsPopup?.feature?.properties && (
<GeometryPropertyPopup
coordinates={showPropsPopup?.coordinates}
properties={showPropsPopup?.feature?.properties}
onClose={() => setShowPropsPopup(null)}
/>
)}
</Map>
Expand Down
19 changes: 0 additions & 19 deletions client-next/src/components/MapView/mapStyle.ts

This file was deleted.

Loading
Loading