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

feat(public-poi-content): fetch feature details from service #887

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 29 additions & 11 deletions app/component/map/sidebar/PublicPoiContent.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
import PropTypes from 'prop-types';
import React from 'react';
import React, { useEffect, useState } from 'react';
import { intlShape, FormattedMessage } from 'react-intl';
import SidebarContainer from './SidebarContainer';
import Icon from '../../Icon';
import OSMOpeningHours from '../popups/OSMOpeningHours';
import { getLayerByCode } from '../../../util/mapLayerUtils';

const PublicPoiContent = ({ match }, { intl, config }) => {
const { osmId, lat, lng } = match.location.query;

const [code] = match.location.pathname.split('/').reverse();

const layer = getLayerByCode(code, config);

const [featureProperties, setFeatureProperties] = useState(null);

useEffect(() => {
fetch(
`${config.featuresUrl}/collections/public.pois/items.json?osm_id=${osmId}&category3=${code}`,
)
.then(response => response.json())
.then(({ features }) => {
if (features.length) {
setFeatureProperties(features[0].properties);
}
});
}, [osmId, code]);

if (!layer || !featureProperties) {
return null;
}

const {
lat,
lng: lon,
code,
name,
address,
opening_hours: openingHours,
Expand All @@ -22,13 +43,10 @@ const PublicPoiContent = ({ match }, { intl, config }) => {
internet_access: internetAccess,
operator,
brand,
} = match.location.query;
} = featureProperties;

const layer = getLayerByCode(code, config);

if (!layer) {
return null;
}
const latitude = Number(lat);
const longitude = Number(lng);

const accessibilityMessage =
wheelchair === 'yes'
Expand Down Expand Up @@ -77,7 +95,7 @@ const PublicPoiContent = ({ match }, { intl, config }) => {
name={layer.translations[intl.locale] || layer.translations.en}
description={name}
dataURI={svg ? `data:image/svg+xml;base64,${btoa(svg)}` : undefined}
location={{ lat, lon, address, name }}
location={{ lat: latitude, lon: longitude, address: address || name }}
>
<div className="content">
{(address || phone || website) && <div className="divider" />}
Expand Down
17 changes: 2 additions & 15 deletions app/component/map/tile-layer/SelectPublicPoiRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,18 @@ import Icon from '../../Icon';
export default function SelectPublicPoi(props, { config, intl }) {
const { properties, latitude, longitude } = props;

const { category3: code, name, address, website, phone } = properties;
const { category3: code, name, osm_id: osmId } = properties;

const layer = getLayerByCode(code, config);

const svg = layer?.properties?.icon?.svg;

const detailsProperties = { ...properties };

// Filter out properties that are not in the layer's attributes
Object.keys(detailsProperties).forEach(key => {
if (!layer?.properties?.attributes?.includes(key)) {
delete detailsProperties[key];
}
});

const params = pickBy(
{
...detailsProperties,
lat: latitude,
lng: longitude,
code,
name: name || layer.translations[intl.locale],
address,
website,
phone,
osmId,
},
value => value !== undefined,
);
Expand Down
22 changes: 5 additions & 17 deletions app/component/map/tile-layer/TileLayerContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,33 +257,21 @@ class TileLayerContainer extends GridLayer {
return layer === 'publicPois';
})
) {
const { lat, lon: lng } = selectableTargets[0].coords;
const { coords: coordinates, feature } = selectableTargets[0];

const { properties } = selectableTargets[0].feature;
const { lat, lon: lng } = coordinates;
const { properties } = feature;

const { category3: code, name, address, website, phone } = properties;
const { category3: code, name, osm_id: osmId } = properties;

const layer = getLayerByCode(code, config);

const detailsProperties = { ...properties };

// Filter out properties that are not in the layer's attributes
Object.keys(detailsProperties).forEach(key => {
if (!layer?.properties?.attributes?.includes(key)) {
delete detailsProperties[key];
}
});

const params = pickBy(
{
...detailsProperties,
lat,
lng,
code,
name: name || layer.translations[intl.locale],
address,
website,
phone,
osmId,
},
value => value !== undefined,
);
Expand Down
3 changes: 3 additions & 0 deletions app/configurations/config.herrenberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const CONFIG = 'herrenberg';
const APP_TITLE = 'stadtnavi Herrenberg';
const APP_DESCRIPTION = 'Gemeinsam Mobilität neu denken - die intermodale Verbindungssuche mit offenen, lokalen Daten';
const API_URL = process.env.API_URL || 'https://api.stadtnavi.de';
const FEATURES_URL = 'https://featuredetails.stadtnavi.eu'
const YEAR = 1900 + new Date().getYear();
const STATIC_MESSAGE_URL =
process.env.STATIC_MESSAGE_URL ||
Expand Down Expand Up @@ -453,6 +454,8 @@ export default configMerger(parentConfig, {
layers,

staticMessagesUrl: STATIC_MESSAGE_URL,

featuresUrl: FEATURES_URL,

parkAndRideBannedVehicleParkingTags: [
'lot_type:Parkplatz',
Expand Down
Loading