Skip to content

Commit

Permalink
Merge pull request #181 from ZeLonewolf/customize-server
Browse files Browse the repository at this point in the history
Make tile server, source, and attribution configurable
  • Loading branch information
ZeLonewolf authored Feb 21, 2022
2 parents 058a5a1 + 909508f commit 14ea673
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: |
cd style
npm install --include=dev
sed 's/<your MapTiler key>/53iZvB2drcamS0Ge0xiD/g' config.default.js > config.js
sed 's/<your MapTiler key>/53iZvB2drcamS0Ge0xiD/g' configs/config.maptiler.js > config.js
npm run build
# MapTiler key 53iZvB2drcamS0Ge0xiD only allows requests from zelonewolf.github.io

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
run: |
cd style
npm install --include=dev
sed 's/<your MapTiler key>/53iZvB2drcamS0Ge0xiD/g' config.default.js > config.js
sed 's/<your MapTiler key>/53iZvB2drcamS0Ge0xiD/g' configs/config.maptiler.js > config.js
npm run build
# MapTiler key 53iZvB2drcamS0Ge0xiD only allows requests from zelonewolf.github.io
7 changes: 4 additions & 3 deletions style/CONTRIBUTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ and re-running `npm install`.

## Config File

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

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

Expand Down
25 changes: 18 additions & 7 deletions style/americana.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ var style = {
name: "Americana",
glyphs: "https://fonts.openmaptiles.org/{fontstack}/{range}.pbf",
layers: americanaLayers,
sprite: new URL("sprites/sprite", baseUrl).href,
sources: {
openmaptiles: {
url: config.OPENMAPTILES_URL,
type: "vector",
},
},
sprite: new URL("sprites/sprite", baseUrl).href,
light: {
anchor: "viewport",
color: "white",
Expand All @@ -304,12 +304,23 @@ map.on("styleimagemissing", function (e) {
Shield.missingIconHandler(map, e);
});

map.addControl(
new maplibregl.AttributionControl({
customAttribution:
'<a href="https://www.maptiler.com/copyright/" target="_blank">&copy; MapTiler</a>',
})
);
let attributionConfig = {
customAttribution: "",
};

if (config.ATTRIBUTION_TEXT != undefined) {
attributionConfig = {
customAttribution: config.ATTRIBUTION_TEXT,
};
}

map.addControl(new maplibregl.AttributionControl(attributionConfig));

if (config.ATTRIBUTION_LOGO != undefined) {
document.getElementById("attribution-logo").innerHTML =
config.ATTRIBUTION_LOGO;
}

map.addControl(new maplibregl.NavigationControl(), "top-left");

// Add our sample data.
Expand Down
17 changes: 0 additions & 17 deletions style/config.default.js

This file was deleted.

11 changes: 11 additions & 0 deletions style/configs/config.aws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

/*
Planetiler tile server, hosted at AWS
*/
const OPENMAPTILES_URL =
"https://6ug7hetxl9.execute-api.us-east-2.amazonaws.com/data/v3.json";

export default {
OPENMAPTILES_URL,
};
26 changes: 26 additions & 0 deletions style/configs/config.maptiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

/*
This style requires a vector tile server to run.
This configuration is for running with MapTiler Cloud.
Visit MapTiler Cloud and create an account/log in:
https://cloud.maptiler.com/maps/
Go to Account->Keys and create a key to paste here:
*/
const MAPTILER_KEY = "<your MapTiler key>";

const OPENMAPTILES_URL = `https://api.maptiler.com/tiles/v3-openmaptiles/tiles.json?key=${MAPTILER_KEY}`;
const ATTRIBUTION_LOGO = `
<a id="attribution-logo" href="https://www.maptiler.com/">
<img src="https://api.maptiler.com/resources/logo.svg" alt="MapTiler logo"/>
</a>`;
const ATTRIBUTION_TEXT =
'<a href="https://www.maptiler.com/copyright/" target="_blank">&copy; MapTiler</a>';

export default {
OPENMAPTILES_URL,
ATTRIBUTION_LOGO,
ATTRIBUTION_TEXT,
};
8 changes: 2 additions & 6 deletions style/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
bottom: 0;
width: 100%;
}
#map-tiler-logo {
#attribution-logo {
position: absolute;
bottom: 10px;
z-index: 100;
Expand All @@ -33,11 +33,7 @@

<body>
<div id="map"></div>
<a id="map-tiler-logo" href="https://www.maptiler.com/"
><img
src="https://api.maptiler.com/resources/logo.svg"
alt="MapTiler logo"
/></a>
<div id="attribution-logo"></div>
<a href="https://github.com/ZeLonewolf/openstreetmap-americana/"
><img
loading="lazy"
Expand Down
2 changes: 1 addition & 1 deletion style/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "git+https://github.com/zelonewolf/openstreetmap-americana.git"
},
"scripts": {
"config": "cp config.default.js config.js",
"config": "cp configs/config.maptiler.js config.js",
"code_format": "npx prettier --write .",
"clean": "rm -rf dist .parcel-cache",
"presprites": "rm -rf dist/sprites",
Expand Down

0 comments on commit 14ea673

Please sign in to comment.