Skip to content

Commit

Permalink
Merge branch 'master' into pnpm-workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhep committed Jan 29, 2025
2 parents db5e491 + 3584435 commit 0a88030
Show file tree
Hide file tree
Showing 16 changed files with 2,049 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/endpoints-overlay/i18n/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ otpUi:
saveAsHome: Save as home
saveAsWork: Save as work
swapLocation: Change to {locationType} location
viewNearby: View nearby
1 change: 1 addition & 0 deletions packages/endpoints-overlay/i18n/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ otpUi:
swapLocation: >-
En faire {locationType, select, from {le point de départ} to {la
destination} other {{locationType}}}
viewNearby: À proximité
2 changes: 1 addition & 1 deletion packages/endpoints-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/endpoints-overlay",
"version": "3.0.1",
"version": "3.1.0",
"description": "A map overlay to show the from and to locations of an itinerary",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
3 changes: 3 additions & 0 deletions packages/endpoints-overlay/src/EndpointsOverlay.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const clearLocation = action("clearLocation");
const forgetPlace = action("forgetPlace");
const rememberPlace = action("rememberPlace");
const setLocation = action("setLocation");
const setViewNearby = action("setViewNearby");
const unnamedFromLocation = {
lat: 45.522497,
lon: -122.676029,
Expand Down Expand Up @@ -57,6 +58,7 @@ export const EndpointsOverlayWithUserSettings: ComponentStory<typeof EndpointsOv
locations={locations}
rememberPlace={rememberPlace}
setLocation={setLocation}
setViewNearby={setViewNearby}
showUserSettings
toLocation={toLocation}
/>
Expand Down Expand Up @@ -91,6 +93,7 @@ export const EndpointsOverlayWithUnnamedPlace: ComponentStory<typeof EndpointsOv
<EndpointsOverlay
fromLocation={unnamedFromLocation}
setLocation={setLocation}
setViewNearby={setViewNearby}
showUserSettings
toLocation={unnamedToLocation}
/>
Expand Down
25 changes: 24 additions & 1 deletion packages/endpoints-overlay/src/endpoint.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Briefcase } from "@styled-icons/fa-solid/Briefcase";
import { Popup } from "@opentripplanner/base-map";
import { Search } from "@styled-icons/fa-solid/Search";
import {
ClearLocationArg,
Location,
Expand Down Expand Up @@ -30,6 +31,7 @@ interface Props {
MapMarkerIcon: ComponentType<UserLocationAndType>;
rememberPlace: (arg: UserLocationAndType) => void;
setLocation: (arg: MapLocationActionArg) => void;
setViewNearby?: (arg: Location) => void;
showUserSettings: boolean;
type: string;
}
Expand Down Expand Up @@ -60,6 +62,8 @@ function UserLocationInnerIcon({ type }: IconProps) {
return <Sync size={12} />;
case "times":
return <Times size={12} />;
case "nearby":
return <Search size={12} />;
default:
return null;
}
Expand Down Expand Up @@ -150,7 +154,14 @@ const Endpoint = (props: Props): JSX.Element => {
};

const [showPopup, setShowPopup] = useState(false);
const { location, locations, MapMarkerIcon, showUserSettings, type } = props;
const {
location,
locations,
MapMarkerIcon,
setViewNearby,
showUserSettings,
type
} = props;
if (!(location && location.lat && location.lon)) return null;
const match = locations.find(l => coreUtils.map.matchLatLon(l, location));
const isWork = match && match.type === "work";
Expand Down Expand Up @@ -273,6 +284,18 @@ const Endpoint = (props: Props): JSX.Element => {
/>
</S.Button>
</div>
<div>
<S.Button onClick={() => setViewNearby(location)}>
<UserLocationIcon type="nearby" />
<FormattedMessage
defaultMessage={
defaultMessages["otpUi.EndpointsOverlay.viewStop"]
}
description="Button text to view the coordinates in the nearby view"
id="otpUi.EndpointsOverlay.viewNearby"
/>
</S.Button>
</div>
</FocusTrapWrapper>
</Popup>
)}
Expand Down
7 changes: 7 additions & 0 deletions packages/endpoints-overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ interface Props {
* { location: {...location}, reverseGeocode: true, type: "from/to" }
*/
setLocation?: (arg: MapLocationActionArg) => void;
/**
* Opens the nearby view from the location coordinates
*/
setViewNearby?: (arg: Location) => void;
/**
* Whether or not to show the user settings popup when an endpoint is clicked.
*/
Expand Down Expand Up @@ -121,6 +125,7 @@ const EndpointsOverlay = ({
MapMarkerIcon = DefaultMapMarkerIcon,
rememberPlace = noop,
setLocation = noop,
setViewNearby = noop,
showUserSettings,
toLocation
}: Props): ReactElement => (
Expand All @@ -133,6 +138,7 @@ const EndpointsOverlay = ({
MapMarkerIcon={MapMarkerIcon}
rememberPlace={rememberPlace}
setLocation={setLocation}
setViewNearby={setViewNearby}
showUserSettings={showUserSettings}
type="from"
/>
Expand Down Expand Up @@ -161,6 +167,7 @@ const EndpointsOverlay = ({
rememberPlace={rememberPlace}
setLocation={setLocation}
showUserSettings={showUserSettings}
setViewNearby={setViewNearby}
type="to"
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/geocoder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentripplanner/geocoder",
"version": "3.0.2",
"version": "3.0.3",
"description": "Geocoding tools for multiple geocoding providers",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
38 changes: 33 additions & 5 deletions packages/geocoder/src/geocoders/pelias.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Prettier does not support typescript annotation
// eslint-disable-next-line prettier/prettier
import type { FeatureCollection, Point } from "geojson"
import Geocoder from "./abstract-geocoder";
// Prettier does not support typescript annotation
// eslint-disable-next-line prettier/prettier
import type { AutocompleteQuery, SearchQuery } from "..";
import type { SingleOrMultiGeocoderResponse } from "./types";
import type { MultiGeocoderResponse, SingleOrMultiGeocoderResponse } from "./types";

const DEFAULT_LAYERS = "address,venue,street,intersection"
const DEFAULT_LAYERS = "address,venue,street,intersection";

/**
* Geocoder implementation for the Pelias geocoder.
Expand All @@ -17,7 +20,7 @@ export default class PeliasGeocoder extends Geocoder {
* Generate an autocomplete query specifically for the Pelias API. The
* `sources` parameter is a Pelias-specific option.
* This function fills in some more fields of the query
* from the existing values in the GeocoderConfig.
* from the existing values in the GeocoderConfig.
*/
getAutocompleteQuery(query: AutocompleteQuery): AutocompleteQuery {
const {
Expand Down Expand Up @@ -48,7 +51,7 @@ export default class PeliasGeocoder extends Geocoder {
* Generate a search query specifically for the Pelias API. The
* `sources` parameter is a Pelias-specific option.
* This function fills in some more fields of the query
* from the existing values in the GeocoderConfig.
* from the existing values in the GeocoderConfig.
*/
getSearchQuery(query: SearchQuery): SearchQuery {
const {
Expand Down Expand Up @@ -81,7 +84,7 @@ export default class PeliasGeocoder extends Geocoder {
* first feature returned from the geocoder.
*/
rewriteReverseResponse(response): SingleOrMultiGeocoderResponse {
if (this.geocoderConfig?.reverseUseFeatureCollection) return response
if (this.geocoderConfig?.reverseUseFeatureCollection) return response;
const { lat, lon } = response.isomorphicMapzenSearchQuery.point;

const firstFeature = response[0];
Expand All @@ -92,4 +95,29 @@ export default class PeliasGeocoder extends Geocoder {
rawGeocodedFeature: firstFeature
};
}

/**
* Remove duplicates based on name, which Pelias sometimes creates
*/
rewriteAutocompleteResponse(response: MultiGeocoderResponse): MultiGeocoderResponse {
const features = (response as FeatureCollection)?.features;

const filtered = features?.filter(
(feature, index) =>
!features
.slice(index + 1)
.some(
f =>
f?.properties?.name === feature?.properties?.name &&
// This is unclean, but we know geometry will never contain objects
JSON.stringify((feature?.geometry as Point)?.coordinates) ===
JSON.stringify((f?.geometry as Point)?.coordinates)
)
);

return {
...(response as FeatureCollection),
features: filtered
} as MultiGeocoderResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@
},
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-122.673377, 45.516278]
},
"properties": {
"id": "node/4243944023",
"gid": "openstreetmap:venue:node/4243944023",
"layer": "venue",
"source": "openstreetmap",
"source_id": "node/4243944023",
"name": "Mill Ends Park",
"distance": 0.491,
"accuracy": "point",
"country": "United States",
"country_gid": "whosonfirst:country:85633793",
"country_a": "USA",
"region": "Oregon",
"region_gid": "whosonfirst:region:85688513",
"region_a": "OR",
"county": "Multnomah County",
"county_gid": "whosonfirst:county:102081631",
"county_a": "MU",
"locality": "Portland",
"locality_gid": "whosonfirst:locality:101715829",
"neighbourhood": "Downtown",
"neighbourhood_gid": "whosonfirst:neighbourhood:85867131",
"continent": "North America",
"continent_gid": "whosonfirst:continent:102191575",
"label": "Mill Ends Park, Portland, OR, USA"
}
},
{
"type": "Feature",
"geometry": {
Expand Down
Loading

0 comments on commit 0a88030

Please sign in to comment.