Skip to content

Commit da2dfd6

Browse files
committed
Support api key in digitransit queries; add some data licenses
1 parent e99d5fb commit da2dfd6

File tree

7 files changed

+32
-13
lines changed

7 files changed

+32
-13
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ jobs:
8383
if: github.ref == 'refs/heads/main'
8484
run: yarn run build
8585
env:
86+
API_KEY_DIGITRANSIT: ${{ secrets.API_KEY_DIGITRANSIT }}
87+
API_KEY_NLS: ${{ secrets.API_KEY_NLS }}
8688
TILESERVER_URL: ${{ secrets.TILESERVER_URL }}
8789
NLS_TILESERVER_URL: ${{ secrets.NLS_TILESERVER_URL }}
8890
CITIES: "'Kangasala','Lempäälä','Nokia','Orivesi','Pirkkala','Tampere','Vesilahti','Ylöjärvi'"
@@ -103,6 +105,7 @@ jobs:
103105
if: startsWith(github.ref, 'refs/tags/release')
104106
run: yarn run build
105107
env:
108+
API_KEY_DIGITRANSIT: ${{ secrets.API_KEY_DIGITRANSIT }}
106109
API_KEY_NLS: ${{ secrets.API_KEY_NLS }}
107110
TILESERVER_URL: ${{ secrets.TAMPERE_TILESERVER_URL }}
108111
NLS_TILESERVER_URL: ${{ secrets.TAMPERE_NLS_TILESERVER_URL }}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ Tarmo - Tampere Mobilemap
2626

2727
Use Node>=v16.
2828
See [instructions](https://www.maanmittauslaitos.fi/rajapinnat/api-avaimen-ohje)
29-
for acquiring an NLS API key (in Finnish).
29+
for acquiring an NLS API key (in Finnish). Optionally, see [instructions](https://digitransit.fi/en/developers/api-registration/) for acquiring a Digitransit API key if you want bus stops on your map.
3030

3131
1. Build and start the development containers with `docker-compose -f docker-compose.dev.yml up -d`
3232
2. Populate the database by running `make test-all-layers`.
3333
3. Navigate into the `web` directory.
34-
4. Copy `.env.sample` as `.env` and fill your NLS API key.
34+
4. Copy `.env.sample` as `.env` and fill your NLS API key (plus optionally Digitransit API key).
3535
5. Install dependencies:
3636
```shell
3737
yarn

licenses.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
[_Tampereen kaupungin WFS-rajapinta_](https://geodata.tampere.fi/geoserver/web/)
88

99
- Aineiston lisenssi [Creative Commons Attribution 4.0](https://creativecommons.org/licenses/by/4.0/)
10-
- Luontopolkurastit
11-
- Luonnonmuistomerkit
10+
- Luontopolkurastit (Tampereen kaupunki, Ympäristönsuojelu)
11+
- Luonnonmuistomerkit (Tampereen kaupunki, Ympäristönsuojelu)
1212

1313
_[Jyväskylän yliopisto, Lipas Liikuntapaikat.fi](https://www.lipas.fi/etusivu)_
1414

@@ -25,6 +25,13 @@ _[Digitransit](https://digitransit.fi/en/developers/apis/)_
2525
- Lisenssi: [Creative Commons BY 4.0 International](https://creativecommons.org/licenses/by/4.0/)
2626
- Hyödynnetään toteutuksessa Digitransit-APIn Waltti-reititintä
2727
- Joukkoliikennepysäkit
28+
- Kaupunkipyöräasemat
29+
30+
-[Suomen Ympäristökeskus](https://www.syke.fi/avointieto)
31+
32+
- Lisenssi: [Creative Commons BY 4.0 International](https://creativecommons.org/licenses/by/4.0/)
33+
- Valtion maiden luonnonsuojelualueet (Metsähallitus)
34+
- Natura 2000 -alueet (Suomen Ympäristökeskus)
2835

2936
_[Maanmittauslaitos](https://www.maanmittauslaitos.fi/tietoa-maanmittauslaitoksesta/teemat/tutustu-rajapintapalveluiden-kayttoon/rajapintojen-kautta)_
3037

web/.env.sample

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
API_KEY_NLS=<your-api-key>
22
NLS_TILESERVER_URL=https://avoin-karttakuva.maanmittauslaitos.fi
3+
API_KEY_DIGITRANSIT=<your-api-key>
34
TILESERVER_URL=http://localhost:7800
45
CITIES="'Kangasala','Lempäälä','Nokia','Orivesi','Pirkkala','Tampere','Vesilahti','Ylöjärvi'"
56
DISABLED_LAYERS="Roskikset;Penkit ja pöydät"

web/src/components/InfoSlider.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ export default function InfoSlider({ popupInfo }: PopupProps) {
145145
};
146146

147147
const dataSources: {[prefix:string]: DataSource} = {
148-
"lipas": {name: "LIPAS", url: "https://www.lipas.fi/"},
148+
"lipas": {name: "Jyväskylän yliopisto, Lipas Liikuntapaikat.fi", url: "https://www.lipas.fi/"},
149149
"museovirastoarcrest": {name: "Museovirasto", url: "https://www.kyppi.fi/"},
150-
"tamperewfs": {name: "Tampereen kaupunki", url: "https://data.tampere.fi/"},
151-
"osm": {name: "OpenStreetMap", url: "https://www.openstreetmap.org/"},
152-
"syke": {name: "Suomen ympäristökeskus", url: "https://www.syke.fi/"},
150+
"tamperewfs": {name: "Tampereen kaupunki, Ympäristönsuojelu", url: "https://data.tampere.fi/"},
151+
"osm": {name: "OpenStreetMapin tekijät", url: "https://www.openstreetmap.org/"},
152+
"syke": {name: "Suomen ympäristökeskus/Metsähallitus", url: "https://www.syke.fi/"},
153153
"digitransit": {name: "Digitransit", url: "https://digitransit.fi"}
154154
}
155155

@@ -178,7 +178,7 @@ export default function InfoSlider({ popupInfo }: PopupProps) {
178178
return (
179179
<Box pb={2}>
180180
<Typography variant="h6">
181-
Tietolähde: <Link href={url} target="_blank" color="#fbfbfb">{name}</Link>
181+
© <Link href={url} target="_blank" color="#fbfbfb">{name}</Link> {new Date().getFullYear()}
182182
</Typography>
183183
</Box>
184184
);

web/src/components/Map.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export default function TarmoMap({ setPopupInfo }: TarmoMapProps): JSX.Element {
107107
LayerId.DigiTransitPoint,
108108
{
109109
url: "https://api.digitransit.fi/routing/v1/routers/waltti/index/graphql",
110+
headers: {
111+
"digitransit-subscription-key": `${process.env.API_KEY_DIGITRANSIT}`
112+
},
110113
tarmo_category: "Pysäkit",
111114
zoomThreshold: minZoomByCategory.get("Pysäkit")!,
112115
reload: true,
@@ -131,6 +134,9 @@ export default function TarmoMap({ setPopupInfo }: TarmoMapProps): JSX.Element {
131134
LayerId.DigiTransitBikePoint,
132135
{
133136
url: "https://api.digitransit.fi/routing/v1/routers/waltti/index/graphql",
137+
headers: {
138+
"digitransit-subscription-key": `${process.env.API_KEY_DIGITRANSIT}`
139+
},
134140
tarmo_category: "Pysäkit",
135141
zoomThreshold: minZoomByCategory.get("Pysäkit")!,
136142
reload: false,
@@ -162,9 +168,6 @@ export default function TarmoMap({ setPopupInfo }: TarmoMapProps): JSX.Element {
162168

163169
const loadExternalData = () => {
164170
// Load external data for the visible area
165-
const requestHeaders: HeadersInit = {
166-
"User-Agent": "TARMO - Tampere Mobilemap",
167-
};
168171
externalSources.forEach((value, key) => {
169172
// Do not reload if data is not visible
170173
if (
@@ -178,10 +181,14 @@ export default function TarmoMap({ setPopupInfo }: TarmoMapProps): JSX.Element {
178181
}
179182
const url = value.url;
180183
let query = value.gqlQuery ? value.gqlQuery : "";
184+
const headers: HeadersInit = {
185+
"User-Agent": "TARMO - Tampere Mobilemap",
186+
...value.headers
187+
};
181188
if (bounds && query && zoom > value.zoomThreshold) {
182189
const params = new Map<string, string>(Object.entries(bounds));
183190
query = buildQuery(query, params);
184-
rawRequest(url, query, requestHeaders).then(response => {
191+
rawRequest(url, query, undefined, headers).then(response => {
185192
const featureCollection = parseResponse(response);
186193
// https://medium.com/swlh/using-es6-map-with-react-state-hooks-800b91eedd5f
187194
setExternalData(prevState => {

web/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface ExternalSource {
2525
url: string;
2626
tarmo_category: keyof CategoryFilters;
2727
zoomThreshold: number;
28+
headers?: object;
2829
gqlQuery?: string;
2930
reload?: boolean;
3031
}

0 commit comments

Comments
 (0)