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

Nearby view support #655

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cef0cc2
feat(types): Add "stop" to Place type
daniel-heppner-ibigroup Aug 11, 2023
4857a56
feat(types): add otp2 types to stop type
daniel-heppner-ibigroup Aug 11, 2023
e85f08d
feat(itinerary-body): add full stop data to view stop button return
daniel-heppner-ibigroup Aug 11, 2023
fc1a706
fix(core-utils): add more data to stop object
daniel-heppner-ibigroup Aug 11, 2023
e58cf71
fix(map-popup): setViewedStop passes whole stop
daniel-heppner-ibigroup Aug 15, 2023
38aefe6
fix(otp2-tile-overlay): use new stop callback
daniel-heppner-ibigroup Aug 15, 2023
eb9b041
fix(stops-overlay): use new stop callback
daniel-heppner-ibigroup Aug 15, 2023
016f1d4
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Sep 13, 2023
97deeb8
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Sep 28, 2023
f52f435
fix: use alpha versions
daniel-heppner-ibigroup Sep 28, 2023
a4483f6
feat(stops-overlay): add highlighted stop support
daniel-heppner-ibigroup Oct 24, 2023
52cdc89
fix(stops-overlay): add support for custom highlight color
daniel-heppner-ibigroup Oct 25, 2023
b500a49
fix(stops-overlay): fix memoization on highlighted stop
daniel-heppner-ibigroup Oct 24, 2023
d3a51f5
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Nov 3, 2023
694575d
deps: update internal dependencies
daniel-heppner-ibigroup Nov 13, 2023
1354178
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Nov 13, 2023
d2ffb77
revert unneeded change to graphql query
daniel-heppner-ibigroup Nov 16, 2023
16b1e65
fix duplicate id in types
daniel-heppner-ibigroup Nov 16, 2023
7a178de
use new stopeventhandler
daniel-heppner-ibigroup Nov 16, 2023
8b59a21
add stopId to prevent breaking change
daniel-heppner-ibigroup Nov 16, 2023
bf4da86
fix(map-popup): use StopEventHandler
daniel-heppner-ibigroup Nov 16, 2023
f40bd02
fix(otp2-tile-overlay): use StopEventHandler
daniel-heppner-ibigroup Nov 16, 2023
e6fb544
fix(stops-overlay): use StopEventHandler type
daniel-heppner-ibigroup Nov 16, 2023
ff5b3db
deps: update internal dependencies
daniel-heppner-ibigroup Nov 18, 2023
b2cdbbf
deps: move deps into devdeps
daniel-heppner-ibigroup Nov 18, 2023
b6fa7aa
revert breaking change in itinerary body
daniel-heppner-ibigroup Nov 18, 2023
27ff939
sort props
daniel-heppner-ibigroup Nov 18, 2023
a710085
feat(map-popup): pass the whole Stop object on stop click
daniel-heppner-ibigroup Nov 20, 2023
8ba60ef
simplify types
daniel-heppner-ibigroup Nov 21, 2023
99213e1
Merge branch 'master' into nearby-view-support
daniel-heppner-ibigroup Nov 27, 2023
edbdc5d
deps: update internal dependencies
daniel-heppner-ibigroup Nov 27, 2023
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
23 changes: 13 additions & 10 deletions packages/core-utils/src/planQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
fragment StopParameters on Stop {
code
gtfsId
name
id
lat
lon
}

query Plan(
$arriveBy: Boolean
$banned: InputBanned
Expand Down Expand Up @@ -100,9 +109,7 @@ query Plan(
effectiveStartDate
id
}
code
gtfsId
id
...StopParameters
}
vertexType
}
Expand Down Expand Up @@ -202,25 +209,21 @@ query Plan(
effectiveStartDate
id
}
code
gtfsId
id
...StopParameters
}
vertexType
}
transitLeg
trip {
arrivalStoptime {
stop {
gtfsId
id
...StopParameters
}
stopPosition
}
departureStoptime {
stop {
gtfsId
id
...StopParameters
}
stopPosition
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function TransitLegSubheader({
}}
/>
{!isFlex(leg) && (
<ViewStopButton onStopClick={onStopClick} stopId={from.stopId} />
<ViewStopButton onStopClick={onStopClick} stop={from.stop} />
)}
</S.PlaceSubheader>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React, { Component, ReactElement } from "react";
import { Stop } from "@opentripplanner/types";
import { FormattedMessage } from "react-intl";

import * as S from "../styled";
import { defaultMessages } from "../util";

interface Props {
onStopClick: ({ stopId: string }) => void;
stopId: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Keep this prop (as a fallback) otherwise it is a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it an either or type, let me know if that's good

onStopClick: (stop: Stop) => void;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a breaking change. Either:

  1. Add breaking change commits to all packages that use this new method signature, or,
  2. If maintaining compatibility, change the signature of onStopClick to (stop: Stop | { stopId: string }) (You could create an alias type StopEventHanlder = (stop: Stop | { stopId: string }) => void in the types package to avoid repetition.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great idea! I'll add it. Thank you for the suggestion

stop: Stop;
}

export default class ViewStopButton extends Component<Props> {
onClick = (): void => {
const { onStopClick, stopId } = this.props;
onStopClick({ stopId });
const { onStopClick, stop } = this.props;
onStopClick(stop);
};

render(): ReactElement {
Expand Down
3 changes: 2 additions & 1 deletion packages/itinerary-body/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Leg,
LegIconComponent,
Place,
Stop,
TransitOperator
} from "@opentripplanner/types";

Expand Down Expand Up @@ -84,7 +85,7 @@ export type SetViewedTripFunction = (tripSection: TripSection) => void;

export interface TransitLegSubheaderProps {
leg: Leg;
onStopClick?: ({ stopId: string }) => void;
onStopClick?: (stop: Stop) => void;
}

export interface TransitLegSummaryProps {
Expand Down
36 changes: 22 additions & 14 deletions packages/map-popup/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ const StationHubDetails = ({ station }: { station: Station }) => {
const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => void; }) => {
return (
<BaseMapStyled.PopupRow>
<strong>
<FormattedMessage
defaultMessage={defaultMessages["otpUi.MapPopup.stopId"]}
description="Displays the stop id"
id="otpUi.MapPopup.stopId"
values={{
stopId: id
}}
/>
</strong>
<strong>
<FormattedMessage
defaultMessage={defaultMessages["otpUi.MapPopup.stopId"]}
description="Displays the stop id"
id="otpUi.MapPopup.stopId"
values={{
stopId: id
}}
/>
</strong>
<S.ViewStopButton onClick={setViewedStop}>
<FormattedMessage
defaultMessage={defaultMessages["otpUi.MapPopup.stopViewer"]}
Expand All @@ -88,9 +88,13 @@ type Props = {
entity: Entity
getEntityName?: (entity: Entity, configCompanies: Company[],) => string;
setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;
setViewedStop?: ({ stopId }: { stopId: string }) => void;
setViewedStop?: (stop: Stop) => void;
};

function entityIsStation(entity: Entity): entity is Station {
return "bikesAvailable" in entity
}

/**
* Renders a map popup for a stop, scooter, or shared bike
*/
Expand All @@ -102,9 +106,8 @@ export function MapPopup({ configCompanies, entity, getEntityName, setLocation,
const name = getNameFunc(entity, configCompanies);


const bikesAvailablePresent = "bikesAvailable" in entity
const bikesAvailablePresent = entityIsStation(entity)
const entityIsStationHub = bikesAvailablePresent && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;
// @ts-expect-error ts doesn't understand entityIsStop
const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(":")[1] || entity.id

return (
Expand All @@ -114,7 +117,12 @@ export function MapPopup({ configCompanies, entity, getEntityName, setLocation,
{entityIsStationHub && <StationHubDetails station={entity} />}

{/* render stop viewer link if available */}
{setViewedStop && !bikesAvailablePresent && <StopDetails id={stopId} setViewedStop={useCallback(() => setViewedStop({ stopId: entity.id }), [entity.id])} />}
{setViewedStop && !bikesAvailablePresent && (
<StopDetails
id={stopId}
setViewedStop={useCallback(() => setViewedStop(entity), [entity])}
/>
)}

{/* The "Set as [from/to]" ButtonGroup */}
{setLocation && (
Expand Down
2 changes: 1 addition & 1 deletion packages/otp2-tile-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react-map-gl": "^7.0.15"
},
"dependencies": {
"@opentripplanner/map-popup": "^2.0.5"
"@opentripplanner/map-popup": "^2.0.7-alpha.1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

The tile overlay package should probably be released from a separate PR after the map popup package is released.

},
"devDependencies": {
"@opentripplanner/base-map": "^3.0.14",
Expand Down
5 changes: 3 additions & 2 deletions packages/otp2-tile-overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import EntityPopup from "@opentripplanner/map-popup"
import {
ConfiguredCompany,
MapLocationActionArg,
Stop,
} from "@opentripplanner/types"
// eslint-disable-next-line prettier/prettier
import type { EventData } from "mapbox-gl"
Expand Down Expand Up @@ -52,7 +53,7 @@ const OTP2TileLayerWithPopup = ({
* A method fired when the stop viewer is opened in the default popup. If this method is
* not passed, the stop viewer link will not be shown.
*/
setViewedStop?: ({ stopId }: { stopId: string }) => void
setViewedStop?: (stop: Stop) => void
/**
* Determines which layer of the OTP2 tile data to display. Also determines icon color.
*/
Expand Down Expand Up @@ -173,7 +174,7 @@ const generateOTP2TileLayers = (
layers: { color?: string; name?: string; network?: string; type: string, initiallyVisible?: boolean }[],
endpoint: string,
setLocation?: (location: MapLocationActionArg) => void,
setViewedStop?: ({ stopId }: { stopId: string }) => void,
setViewedStop?: (stop: Stop) => void,
configCompanies?: ConfiguredCompany[]
): JSX.Element[] => {
return [
Expand Down
2 changes: 1 addition & 1 deletion packages/stops-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@opentripplanner/base-map": "^3.0.14",
"@opentripplanner/from-to-location-picker": "^2.1.8",
"@opentripplanner/map-popup": "^2.0.5",
"@opentripplanner/map-popup": "^2.0.7-alpha.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

The stops overlay package should probably be released from a separate PR after the map popup package is released.

"flat": "^5.0.2"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/stops-overlay/src/StopsOverlay.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ const Example = ({
minZoom = 15,
setLocation = action("setLocation"),
setViewedStop = action("setViewedStop"),
stops = mockStops
stops = mockStops,
highlightedStop = "8338"
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
}: StopProps & { mapCenter?: [number, number] }) => {
return (
<StopsOverlay
minZoom={minZoom}
setLocation={setLocation}
setViewedStop={setViewedStop}
stops={stops}
highlightedStop={highlightedStop}
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
highlightedStopColor="#0000ff"
visible
/>
);
Expand Down
30 changes: 27 additions & 3 deletions packages/stops-overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type Props = {
* An optional id to override the active stop with
*/
activeStop?: string;
/**
* An optional id to highlight a stop on the map
*/
highlightedStop?: string;
/**
* A color to use for the highlighted stop
*/
highlightedStopColor?: string;
/**
* The list of stops to create stop markers for.
*/
Expand All @@ -40,7 +48,7 @@ type Props = {
/**
* A method fired when the stop viewer is opened in the popup
*/
setViewedStop?: ({ stopId: string }) => void;
setViewedStop?: (stop: Stop) => void;
};

/**
Expand All @@ -51,6 +59,8 @@ const StopsOverlay = (props: Props): JSX.Element => {
const {
activeStop,
color,
highlightedStop,
highlightedStopColor,
minZoom,
refreshStops,
setLocation,
Expand Down Expand Up @@ -127,12 +137,13 @@ const StopsOverlay = (props: Props): JSX.Element => {
type: "Feature",
properties: {
...stop,
flex: isGeoJsonFlex(stop?.geometries?.geoJson)
flex: isGeoJsonFlex(stop?.geometries?.geoJson),
highlighted: stop.id === highlightedStop
},
geometry: { type: "Point", coordinates: [stop.lon, stop.lat] }
}))
}),
[stops]
[stops, highlightedStop]
);

// Don't render if no map or no stops are defined.
Expand All @@ -157,6 +168,19 @@ const StopsOverlay = (props: Props): JSX.Element => {
}}
type="circle"
/>
<Layer
id="higlightedStop"
filter={["==", "highlighted", true]}
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
paint={{
"circle-color": highlightedStopColor || "#ff0000",
"circle-opacity": 1,
"circle-radius": 10,
// TODO: Use tinycolor to generate outline with appropriate contrast.
"circle-stroke-color": color ? "#fff" : "#333",
"circle-stroke-width": 2
}}
type="circle"
/>
<Layer
filter={["==", "flex", true]}
id="flex-stops"
Expand Down
18 changes: 16 additions & 2 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,22 @@ export type Place = {
name: string;
networks?: string[];
rentalVehicle?: { network: string };
stop?: Stop;
/**
* @deprecated Only for OTP1 support, removal is immenent
*/
stopCode?: string;
/**
* @deprecated Only for OTP1 support, removal is immenent
*/
stopId?: string;
/**
* @deprecated Only for OTP1 support, removal is immenent
*/
stopIndex?: number;
/**
* @deprecated Only for OTP1 support, removal is immenent
*/
stopSequence?: number;
vertexType: string;
zoneId?: string;
Expand Down Expand Up @@ -473,10 +486,11 @@ export type Stop = {
dist?: number;
geometries?: { geoJson?: GeoJSON.Polygon };
id: string;
lat: number;
lon: number;
lat?: number;
lon?: number;
name: string;
routes?: Route[];
gtfsId: string;
};

export type Agency = {
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,16 @@
resolved "https://registry.yarnpkg.com/@open-draft/until/-/until-1.0.3.tgz#db9cc719191a62e7d9200f6e7bab21c5b848adca"
integrity sha512-Aq58f5HiWdyDlFffbbSjAlv596h/cOnt2DO1w3DOC7OJ5EHs0hd/nycJfiu9RJbT6Yk6F1knnRRXNSpxoIVZ9Q==

"@opentripplanner/map-popup@^2.0.7-alpha.1":
version "2.0.7-alpha.1"
resolved "https://registry.yarnpkg.com/@opentripplanner/map-popup/-/map-popup-2.0.7-alpha.1.tgz#c8e771989ecad23b1614e83b4ee4831c7c019491"
integrity sha512-YXNoE1R30ClgaPuj5khWlKv7bcBBbJETuniqrg+55AeL8dpMEndUQPsmDWexr9XkY5xOmqhrrfjJ6aew00gYOQ==
dependencies:
"@opentripplanner/base-map" "^3.0.14"
"@opentripplanner/core-utils" "^11.0.2"
"@opentripplanner/from-to-location-picker" "^2.1.8"
flat "^5.0.2"

"@opentripplanner/[email protected]":
version "7.0.0-alpha.2"
resolved "https://registry.yarnpkg.com/@opentripplanner/types/-/types-7.0.0-alpha.2.tgz#d10c69f99b2da6d1e80ab5989520bde8e558627b"
Expand Down
Loading