Skip to content

Commit

Permalink
Merge branch 'v3' into typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Joona Ojapalo committed Aug 26, 2022
2 parents 344ace2 + 6bf8fd1 commit 139bd1e
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 15 deletions.
14 changes: 8 additions & 6 deletions app/component/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,14 @@ export default class Map extends React.Component {
if (this.props.mapBottomPadding) {
boundsOptions.paddingBottomRight = [0, this.props.mapBottomPadding];
}
let mapUrl =
const mapBaseUrl =
(isDebugTiles && `${config.URL.OTP}inspector/tile/traversal/`) ||
config.URL.MAP;
if (mapUrl !== null && typeof mapUrl === 'object') {
mapUrl = mapUrl[this.props.lang] || config.URL.MAP.default;
}
config.URL.MAP[this.props.lang] ||
config.URL.MAP.default;
const mapUrl = config.hasAPISubscriptionQueryParameter
? `${mapBaseUrl}{z}/{x}/{y}{size}.png?${config.API_SUBSCRIPTION_QUERY_PARAMETER_NAME}=${config.API_SUBSCRIPTION_TOKEN}`
: `${mapBaseUrl}{z}/{x}/{y}{size}.png`;

const leafletObjNew = leafletObjs.concat([
<VectorTileLayerContainer
key="vectorTileLayerContainer"
Expand Down Expand Up @@ -295,7 +297,7 @@ export default class Map extends React.Component {
closePopupOnClick={false}
>
<TileLayer
url={`${mapUrl}{z}/{x}/{y}{size}.png`}
url={mapUrl}
tileSize={config.map.tileSize || 256}
zoomOffset={config.map.zoomOffset || 0}
updateWhenIdle={false}
Expand Down
5 changes: 4 additions & 1 deletion app/component/map/tile-layer/CityBikes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
BIKEAVL_UNKNOWN,
} from '../../../util/citybikes';

import { fetchWithSubscription } from '../../../util/fetchUtils';

const timeOfLastFetch = {};

const query = graphql`
Expand Down Expand Up @@ -46,10 +48,11 @@ class CityBikes {
}

fetchWithAction = actionFn =>
fetch(
fetchWithSubscription(
`${this.config.URL.CITYBIKE_MAP}` +
`${this.tile.coords.z + (this.tile.props.zoomOffset || 0)}/` +
`${this.tile.coords.x}/${this.tile.coords.y}.pbf`,
this.config,
).then(res => {
if (res.status !== 200) {
return undefined;
Expand Down
4 changes: 3 additions & 1 deletion app/component/map/tile-layer/ParkAndRide.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Protobuf from 'pbf';
import { drawParkAndRideIcon } from '../../../util/mapIconUtils';
import { Contour } from '../../../util/geo-utils';
import { isBrowser } from '../../../util/browser';
import { fetchWithSubscription } from '../../../util/fetchUtils';

import carParksQuery from './carParks';
import carParkQuery from './carPark';
Expand All @@ -28,10 +29,11 @@ export default class ParkAndRide {
static getName = () => 'parkAndRide';

getPromise() {
return fetch(
return fetchWithSubscription(
`${this.config.URL.PARK_AND_RIDE_MAP}${
this.tile.coords.z + (this.tile.props.zoomOffset || 0)
}/${this.tile.coords.x}/${this.tile.coords.y}.pbf`,
this.config,
).then(res => {
if (res.status !== 200) {
return undefined;
Expand Down
4 changes: 3 additions & 1 deletion app/component/map/tile-layer/ParkAndRideForBikes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Protobuf from 'pbf';
import { drawParkAndRideForBikesIcon } from '../../../util/mapIconUtils';
import { Contour } from '../../../util/geo-utils';
import { isBrowser } from '../../../util/browser';
import { fetchWithSubscription } from '../../../util/fetchUtils';

import bikeParkQuery from './bikePark';

Expand All @@ -22,10 +23,11 @@ export default class ParkAndRideForBikes {
static getName = () => 'parkAndRideForBikes';

getPromise() {
return fetch(
return fetchWithSubscription(
`${this.config.URL.PARK_AND_RIDE_MAP}${
this.tile.coords.z + (this.tile.props.zoomOffset || 0)
}/${this.tile.coords.x}/${this.tile.coords.y}.pbf`,
this.config,
).then(res => {
if (res.status !== 200) {
return undefined;
Expand Down
4 changes: 3 additions & 1 deletion app/component/map/tile-layer/Stops.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { ExtendedRouteTypes } from '../../../constants';
import { isFeatureLayerEnabled } from '../../../util/mapLayerUtils';
import { PREFIX_ITINERARY_SUMMARY, PREFIX_ROUTES } from '../../../util/path';
import { fetchWithSubscription } from '../../../util/fetchUtils';

function isNull(val) {
return val === 'null' || val === undefined || val === null;
Expand Down Expand Up @@ -100,10 +101,11 @@ class Stops {
};

getPromise() {
return fetch(
return fetchWithSubscription(
`${this.config.URL.STOP_MAP}${
this.tile.coords.z + (this.tile.props.zoomOffset || 0)
}/${this.tile.coords.x}/${this.tile.coords.y}.pbf`,
this.config,
).then(res => {
if (res.status !== 200) {
return undefined;
Expand Down
6 changes: 4 additions & 2 deletions app/configurations/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export default {
default: `${MAP_URL}/map/${MAP_VERSION}/hsl-map/`,
sv: `${MAP_URL}/map/${MAP_VERSION}/hsl-map-sv/`,
},
STOP_MAP: `${MAP_URL}/map/v1/finland-stop-map/`,
CITYBIKE_MAP: `${MAP_URL}/map/v1/finland-citybike-map/`,
STOP_MAP: `${MAP_URL}/map/${MAP_VERSION}/finland-stop-map/`,
CITYBIKE_MAP: `${MAP_URL}/map/${MAP_VERSION}/finland-citybike-map/`,
PARK_AND_RIDE_MAP: `${MAP_URL}/map/${MAP_VERSION}/hsl-parkandride-map/`,

FONT:
'https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;700&family=Roboto:wght@400;700',
PELIAS: `${process.env.GEOCODING_BASE_URL || GEOCODING_BASE_URL}/search`,
Expand Down
2 changes: 1 addition & 1 deletion app/configurations/config.lappeenranta.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default configMerger(walttiConfig, {
sv: 'Cykelrutter',
en: 'Bike routes',
},
url: 'https://ckan.saita.fi/geojson/pyorailyreitit_lpr.geojson',
url: 'https://ckanlpr.meitademo.fi/geojson/pyorailyreitit_lpr.geojson',
isOffByDefault: true,
},
{
Expand Down
2 changes: 1 addition & 1 deletion app/configurations/config.matka.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export default {
parkingAreaSources: ['liipi'],

parkAndRide: {
showParkAndRide: true,
showParkAndRide: false,
parkAndRideMinZoom: 13,
pageContent: {
default: HSLParkAndRideUtils,
Expand Down
13 changes: 12 additions & 1 deletion app/util/fetchUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,15 @@ export const retryFetch = (
});
};

export default retryFetch;
/**
* Uses fetch with subscription header with subscription header
* if it is configured.
*
* @param {String} URL the url to fetch
* @param {*} config The configuration for the software installation
* @returns fetch's promise
*/
export const fetchWithSubscription = (URL, config) =>
fetch(URL, {
headers: addSubscriptionHeader({}, config),
});

0 comments on commit 139bd1e

Please sign in to comment.