Skip to content

Commit 14ea673

Browse files
authored
Merge pull request #181 from ZeLonewolf/customize-server
Make tile server, source, and attribution configurable
2 parents 058a5a1 + 909508f commit 14ea673

File tree

9 files changed

+64
-36
lines changed

9 files changed

+64
-36
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
run: |
2020
cd style
2121
npm install --include=dev
22-
sed 's/<your MapTiler key>/53iZvB2drcamS0Ge0xiD/g' config.default.js > config.js
22+
sed 's/<your MapTiler key>/53iZvB2drcamS0Ge0xiD/g' configs/config.maptiler.js > config.js
2323
npm run build
2424
# MapTiler key 53iZvB2drcamS0Ge0xiD only allows requests from zelonewolf.github.io
2525

.github/workflows/test-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
run: |
1919
cd style
2020
npm install --include=dev
21-
sed 's/<your MapTiler key>/53iZvB2drcamS0Ge0xiD/g' config.default.js > config.js
21+
sed 's/<your MapTiler key>/53iZvB2drcamS0Ge0xiD/g' configs/config.maptiler.js > config.js
2222
npm run build
2323
# MapTiler key 53iZvB2drcamS0Ge0xiD only allows requests from zelonewolf.github.io

style/CONTRIBUTE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ and re-running `npm install`.
102102

103103
## Config File
104104

105-
Environment specific settings go in the untracked file `config.js`. Copy the template
106-
`config.default.js` and rename it `config.js`. The variables in this file can then
107-
be changed without the risk of accidentally comitting to the main repo.
105+
Environment specific settings go in the untracked file `config.js`. Copy from one of
106+
the templates in the style/configs/ folder `config.*.js` and rename it `config.js` in
107+
the style/ folder. The variables in this file can then be changed without the risk of
108+
accidentally comitting to the main repo.
108109

109110
You can create a new copy of the config file by running `npm run config`
110111

style/americana.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,13 @@ var style = {
271271
name: "Americana",
272272
glyphs: "https://fonts.openmaptiles.org/{fontstack}/{range}.pbf",
273273
layers: americanaLayers,
274-
sprite: new URL("sprites/sprite", baseUrl).href,
275274
sources: {
276275
openmaptiles: {
277276
url: config.OPENMAPTILES_URL,
278277
type: "vector",
279278
},
280279
},
280+
sprite: new URL("sprites/sprite", baseUrl).href,
281281
light: {
282282
anchor: "viewport",
283283
color: "white",
@@ -304,12 +304,23 @@ map.on("styleimagemissing", function (e) {
304304
Shield.missingIconHandler(map, e);
305305
});
306306

307-
map.addControl(
308-
new maplibregl.AttributionControl({
309-
customAttribution:
310-
'<a href="https://www.maptiler.com/copyright/" target="_blank">&copy; MapTiler</a>',
311-
})
312-
);
307+
let attributionConfig = {
308+
customAttribution: "",
309+
};
310+
311+
if (config.ATTRIBUTION_TEXT != undefined) {
312+
attributionConfig = {
313+
customAttribution: config.ATTRIBUTION_TEXT,
314+
};
315+
}
316+
317+
map.addControl(new maplibregl.AttributionControl(attributionConfig));
318+
319+
if (config.ATTRIBUTION_LOGO != undefined) {
320+
document.getElementById("attribution-logo").innerHTML =
321+
config.ATTRIBUTION_LOGO;
322+
}
323+
313324
map.addControl(new maplibregl.NavigationControl(), "top-left");
314325

315326
// Add our sample data.

style/config.default.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

style/configs/config.aws.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
3+
/*
4+
Planetiler tile server, hosted at AWS
5+
*/
6+
const OPENMAPTILES_URL =
7+
"https://6ug7hetxl9.execute-api.us-east-2.amazonaws.com/data/v3.json";
8+
9+
export default {
10+
OPENMAPTILES_URL,
11+
};

style/configs/config.maptiler.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
3+
/*
4+
This style requires a vector tile server to run.
5+
This configuration is for running with MapTiler Cloud.
6+
7+
Visit MapTiler Cloud and create an account/log in:
8+
https://cloud.maptiler.com/maps/
9+
10+
Go to Account->Keys and create a key to paste here:
11+
*/
12+
const MAPTILER_KEY = "<your MapTiler key>";
13+
14+
const OPENMAPTILES_URL = `https://api.maptiler.com/tiles/v3-openmaptiles/tiles.json?key=${MAPTILER_KEY}`;
15+
const ATTRIBUTION_LOGO = `
16+
<a id="attribution-logo" href="https://www.maptiler.com/">
17+
<img src="https://api.maptiler.com/resources/logo.svg" alt="MapTiler logo"/>
18+
</a>`;
19+
const ATTRIBUTION_TEXT =
20+
'<a href="https://www.maptiler.com/copyright/" target="_blank">&copy; MapTiler</a>';
21+
22+
export default {
23+
OPENMAPTILES_URL,
24+
ATTRIBUTION_LOGO,
25+
ATTRIBUTION_TEXT,
26+
};

style/index.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
bottom: 0;
2020
width: 100%;
2121
}
22-
#map-tiler-logo {
22+
#attribution-logo {
2323
position: absolute;
2424
bottom: 10px;
2525
z-index: 100;
@@ -33,11 +33,7 @@
3333

3434
<body>
3535
<div id="map"></div>
36-
<a id="map-tiler-logo" href="https://www.maptiler.com/"
37-
><img
38-
src="https://api.maptiler.com/resources/logo.svg"
39-
alt="MapTiler logo"
40-
/></a>
36+
<div id="attribution-logo"></div>
4137
<a href="https://github.com/ZeLonewolf/openstreetmap-americana/"
4238
><img
4339
loading="lazy"

style/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "git+https://github.com/zelonewolf/openstreetmap-americana.git"
99
},
1010
"scripts": {
11-
"config": "cp config.default.js config.js",
11+
"config": "cp configs/config.maptiler.js config.js",
1212
"code_format": "npx prettier --write .",
1313
"clean": "rm -rf dist .parcel-cache",
1414
"presprites": "rm -rf dist/sprites",

0 commit comments

Comments
 (0)