Skip to content

Commit

Permalink
OpenPlaceGuide integration
Browse files Browse the repository at this point in the history
* Fetch federation instance(s) for the current feature from OpenPlaceGuide discover
* But only, if the country is list of supported countries
* Add links to the specific detail pages, if available
  • Loading branch information
amenk committed Jun 23, 2024
1 parent ccfa83c commit 8303054
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
56 changes: 56 additions & 0 deletions src/components/FeaturePanel/FeatureOpenPlaceGuideLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { t } from '../../services/intl';
import { fetchJson } from '../../services/fetch';
import { useFeatureContext } from '../utils/FeatureContext';
import { getUrlOsmId } from '../../services/helpers';

const Spacer = styled.div`
padding-bottom: 10px;
`;

const getData = async (center, osmId) => {
if (center === undefined || !center.length) {
return null;
}
const body = await fetchJson(
`https://discover.openplaceguide.org/v2/discover?lat=${center[1]}&lon=${center[0]}&osmId=${osmId}`,
);
return body;
};

export const FeatureOpenPlaceGuideLink = () => {
const supportedCountries = ['et']; // refer to the list of countries here: https://github.com/OpenPlaceGuide/discover-cf-worker/blob/main/index.js#L43

const { feature } = useFeatureContext();
const osmId = getUrlOsmId(feature.osmMeta);

if (!supportedCountries.includes(feature.countryCode)) {
return null;
}

const [instances, setInstances] = useState([]);

useEffect(() => {
getData(feature.center, osmId).then(setInstances);
}, [osmId]);

if (instances.length === 0) {
return null;
}

return (
<>
{instances.map((instance) => (
<>
<a href={instance.url}>
{t('featurepanel.more_in_openplaceguide', {
instanceName: instance.name,
})}
</a>
<Spacer />
</>
))}
</>
);
};
3 changes: 3 additions & 0 deletions src/components/FeaturePanel/FeaturePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FeatureDescription } from './FeatureDescription';
import { ObjectsAround } from './ObjectsAround';
import { OsmError } from './OsmError';
import { Members } from './Members';
import { FeatureOpenPlaceGuideLink } from './FeatureOpenPlaceGuideLink';
import { getLabel } from '../../helpers/featureLabel';
import { ImageSection } from './ImageSection/ImageSection';
import { PublicTransport } from './PublicTransport/PublicTransport';
Expand Down Expand Up @@ -123,6 +124,8 @@ export const FeaturePanel = () => {

<PublicTransport tags={tags} />

<FeatureOpenPlaceGuideLink />

{editEnabled && <SuggestEdit />}

{point && <ObjectsAround advanced={advanced} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function requestLines(
// use the overpass api to request the lines in
const overpassQuery = `[out:csv(ref, colour; false; ';')];
${featureType}(${id});
rel(bn)["public_transport"="stop_area"];
rel(bn)["public_transport"~"stop_area|platform"];
node(r: "stop") -> .stops;
rel(bn.stops)["route"~"bus|train|tram|subway|light_rail|ferry|monorail"];
out;`;
Expand Down
1 change: 1 addition & 0 deletions src/locales/vocabulary.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default {
'featurepanel.uncertain_image': 'This is the closest street view image from Mapillary. It may be inaccurate.',
'featurepanel.inline_edit_title': 'Edit',
'featurepanel.objects_around': 'Nearby objects',
'featurepanel.more_in_openplaceguide': 'More information on __instanceName__',

'opening_hours.open': 'Open: __todayTime__',
'opening_hours.now_closed_but_today': 'Closed now - Open __todayTime__',
Expand Down

0 comments on commit 8303054

Please sign in to comment.