Skip to content

Commit c31e76a

Browse files
authored
Basemaps styles v5 (#103)
* Update documentation for @protomaps/basemaps v5.0.0 * rename Theme into Flavor object and add more docs on customization
1 parent 495c8a6 commit c31e76a

File tree

10 files changed

+100
-80
lines changed

10 files changed

+100
-80
lines changed

.vitepress/config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default defineConfig({
7575
items: [
7676
{ text: "Downloads", link: "/basemaps/downloads" },
7777
{ text: "Basemap Layers", link: "/basemaps/layers" },
78-
{ text: "Basemap Themes", link: "/basemaps/themes" },
78+
{ text: "Basemap Flavors", link: "/basemaps/flavors" },
7979
{ text: "Basemap Localization", link: "/basemaps/localization" },
8080
{ text: "Building Tiles", link: "/basemaps/build" },
8181
{ text: "MapLibre GL", link: "/basemaps/maplibre" },

basemaps/downloads.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Please note that **URLs may change** and hotlinking to these downloads are disco
1818

1919
## Current Version
2020

21-
The Version 4 Protomaps basemap daily build channel is available at [maps.protomaps.com/builds](https://maps.protomaps.com/builds). This is compatible with `protomaps-themes-base` style v4.0.0 and newer.
21+
The Version 4 Protomaps basemap daily build channel is available at [maps.protomaps.com/builds](https://maps.protomaps.com/builds). This is compatible with `@protomaps/basemaps` style v4.0.0 and newer.
2222

2323
[BLAKE3](https://github.com/BLAKE3-team/BLAKE3/releases/) hashes are provided for daily builds. Use `b3sum` to verify the integrity of your downloaded file.
2424

basemaps/flavors.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Basemap Flavors
3+
outline: deep
4+
---
5+
6+
<script setup>
7+
import MaplibreMap from '../components/MaplibreMap.vue'
8+
</script>
9+
10+
# Basemap Flavors
11+
12+
These examples use the preferred [MapLibre GL JS](/basemaps/maplibre) library.
13+
14+
The `Flavor` TypeScript interface is the preferred way to customize the basemap style. See the shape of the interface at the [@protomaps/basemaps TypeScript docs](https://maps.protomaps.com/typedoc/interfaces/Flavor.html).
15+
16+
A `Flavor` is a plain object of color definitions and optional properties such as font names, landcover shades and POI properties. You can define a `Flavor` yourself for a custom style, similar to a text editor color scheme, or use one of the default named flavors as a base.
17+
18+
## Default Flavors
19+
20+
These flavors are included as part of the `@protomaps/basemaps` package.
21+
22+
### light
23+
24+
A general-purpose basemap with icons.
25+
26+
<MaplibreMap flavor="light" :zoom=13 :lat="51.509" :lng="-0.14"/>
27+
28+
### dark
29+
30+
A general-purpose basemap with icons.
31+
32+
<MaplibreMap flavor="dark" :zoom=13 :lat="51.509" :lng="-0.14"/>
33+
34+
### white
35+
36+
A flavor for data visualization.
37+
38+
<MaplibreMap flavor="white" :zoom=13 :lat="51.509" :lng="-0.14"/>
39+
40+
### grayscale
41+
42+
A flavor for data visualization.
43+
44+
<MaplibreMap flavor="grayscale" :zoom=13 :lat="51.509" :lng="-0.14"/>
45+
46+
### black
47+
48+
A flavor for data visualization.
49+
50+
<MaplibreMap flavor="black" :zoom=13 :lat="51.509" :lng="-0.14"/>
51+
52+
## Overriding Defaults
53+
54+
Use [ES6 spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) to override any part of the Flavor object. For example, to color buildings red:
55+
56+
```ts
57+
import { namedFlavor } from "@protomaps/basemaps"
58+
let flavor = {...namedFlavor("light"),buildings:"red")
59+
```

basemaps/maplibre.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You can view a list of available fonts [in the GitHub repository](https://github
2626

2727
### Sprites
2828

29-
The `sprite` key references a URL specific to one of [the default themes](/basemaps/themes):
29+
The `sprite` key references a URL specific to one of [the default flavors](/basemaps/flavors):
3030

3131
```js
3232
sprite: "https://protomaps.github.io/basemaps-assets/sprites/v4/light"
@@ -36,20 +36,20 @@ These are required for townspots, highway shields and point of interest icons.
3636

3737
## Loading styles as JSON
3838

39-
Because [MapLibre styles](https://maplibre.org/maplibre-style-spec/) are JSON documents, the simplest way to define a style in your application is with static JSON. You can use the `Get style JSON` feature of [maps.protomaps.com](https://maps.protomaps.com) to generate static JSON for a specific theme and style package version.
39+
Because [MapLibre styles](https://maplibre.org/maplibre-style-spec/) are JSON documents, the simplest way to define a style in your application is with static JSON. You can use the `Get style JSON` feature of [maps.protomaps.com](https://maps.protomaps.com) to generate static JSON for a specific flavor and style package version.
4040

4141
## Creating styles programatically
4242

43-
For more control and less code, you can add use the [`protomaps-themes-base`](https://www.npmjs.com/package/protomaps-themes-base) NPM package as a dependency.
43+
For more control and less code, you can add use the [`@protomaps/basemaps`](https://www.npmjs.com/package/@protomaps/basemaps) NPM package as a dependency.
4444

4545
### Using the npm package
4646

4747
```bash
48-
npm install protomaps-themes-base
48+
npm install @protomaps/basemaps
4949
```
5050

5151
```js
52-
import layers from 'protomaps-themes-base';
52+
import { layers, namedFlavor } from '@protomaps/basemaps';
5353
```
5454

5555
```js
@@ -65,24 +65,26 @@ style: {
6565
attribution: '<a href="https://protomaps.com">Protomaps</a> © <a href="https://openstreetmap.org">OpenStreetMap</a>'
6666
}
6767
},
68-
layers: layers("protomaps","light")
68+
layers: layers("protomaps",namedFlavor("light"),{lang:"en"})
6969
}
7070
```
7171

72-
the default export from `protomaps-themes-base` is a function that takes 2 arguments:
72+
the `layers` from `@protomaps/basemaps` is a function that takes 3 arguments:
7373

7474
* the source name of the basemap, like `protomaps` in the `sources` example above.
7575

76-
* the [theme](/basemaps/themes), one of `light`, `dark`, `white`, `black`, `grayscale`.
76+
* A [flavor object](/basemaps/flavors); the defaults can be fetched `namedFlavor` with `light`, `dark`, `white`, `black`, `grayscale`.
77+
78+
* An options object: to display labels. pass a `lang` key. Pass `labelsOnly` to display only labels.
7779

7880
### Using a CDN
7981

80-
Loading the `protomaps-themes-base` package from NPM will define the `protomaps_themes_base` global variable.
82+
Loading the `@protomaps/basemaps` package from NPM will define the `basemaps` global variable.
8183

8284
```html
83-
<script src="https://unpkg.com/protomaps-themes-base@4/dist/protomaps-themes-base.js" crossorigin="anonymous"></script>
85+
<script src="https://unpkg.com/@protomaps/basemaps@5/dist/basemaps.js" crossorigin="anonymous"></script>
8486
```
8587

8688
```js
87-
layers: protomaps_themes_base.default("protomaps","light")
89+
layers: basemaps.layers("protomaps",basemaps.namedFlavor("light"),{lang:"en"})
8890
````

basemaps/themes.md

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

components/MaplibreMap.vue

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<script setup lang="ts">
22
import maplibregl from "maplibre-gl";
33
import { ref, onMounted, onUpdated, watch } from "vue";
4-
import { default as layers } from "protomaps-themes-base";
5-
import { language_script_pairs } from "protomaps-themes-base";
4+
import {
5+
language_script_pairs,
6+
layers,
7+
namedFlavor,
8+
} from "@protomaps/basemaps";
69
import { useData } from "vitepress";
710
811
const { isDark } = useData();
@@ -67,9 +70,9 @@ const highlightLayers = (sourceName: string, highlightName?: string) => {
6770
];
6871
};
6972
70-
const style = (passedTheme?: string, highlightLayer?: string, lang?: lang) => {
71-
const theme =
72-
passedTheme ||
73+
const style = (passedFlavor?: string, highlightLayer?: string, lang?: lang) => {
74+
const flavor =
75+
passedFlavor ||
7376
(isDark.value
7477
? highlightLayer
7578
? "black"
@@ -81,7 +84,7 @@ const style = (passedTheme?: string, highlightLayer?: string, lang?: lang) => {
8184
version: 8,
8285
glyphs:
8386
"https://protomaps.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf",
84-
sprite: `https://protomaps.github.io/basemaps-assets/sprites/v4/${theme}`,
87+
sprite: `https://protomaps.github.io/basemaps-assets/sprites/v4/${flavor}`,
8588
sources: {
8689
protomaps: {
8790
type: "vector",
@@ -91,14 +94,14 @@ const style = (passedTheme?: string, highlightLayer?: string, lang?: lang) => {
9194
transition: {
9295
duration: 0,
9396
},
94-
layers: layers("protomaps", theme, lang).concat(
97+
layers: layers("protomaps", namedFlavor(flavor), { lang: lang }).concat(
9598
highlightLayers("protomaps", highlightLayer),
9699
),
97100
};
98101
};
99102
100103
const props = defineProps<{
101-
theme?: string;
104+
flavor?: string;
102105
highlightLayer?: string;
103106
center?: number;
104107
zoom?: number;
@@ -118,7 +121,7 @@ onMounted(() => {
118121
currentZoom.value = props.zoom;
119122
map = new maplibregl.Map({
120123
container: mapRef.value,
121-
style: style(props.theme, props.highlightLayer),
124+
style: style(props.flavor, props.highlightLayer, lang),
122125
cooperativeGestures: true,
123126
attributionControl: false,
124127
center: props.lng && props.lat ? [props.lng, props.lat] : [0, 0],
@@ -157,7 +160,7 @@ onMounted(() => {
157160
});
158161
159162
watch([isDark, lang], () => {
160-
map.setStyle(style(props.theme, props.highlightLayer, lang.value));
163+
map.setStyle(style(props.flavor, props.highlightLayer, lang.value));
161164
});
162165
163166
language_script_pairs.sort((a, b) => a.full_name.localeCompare(b.full_name));

guide/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ pmtiles extract https://build.protomaps.com/{{ dateNoDashes }}.pmtiles planet_z6
6565
## Next Steps
6666

6767
* Upload your tiles to cloud storage: [Cloud Storage](/pmtiles/cloud-storage)
68-
* Change the appearance or theme of the basemap: [Basemap Styles](/basemaps/themes)
68+
* Change the appearance of the basemap: [Basemap Styles](/basemaps/flavors)
6969
* Bring your own datasets: [Creating PMTiles](/pmtiles/create)

guide/security-privacy.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Below is a complete example of a map application that avoids third-party data pr
9393
<link rel="stylesheet" href="maplibre-gl.css">
9494
<script src="maplibre-gl.js"></script>
9595
<script src="pmtiles.js"></script>
96-
<script src="protomaps-themes-base.js"></script>
96+
<script src="basemaps.js"></script>
9797
</head>
9898
<body>
9999
<div id="map" style="height: 100%; width: 100%"></div>
@@ -119,7 +119,7 @@ Below is a complete example of a map application that avoids third-party data pr
119119
attribution: '© <a href="https://openstreetmap.org">OpenStreetMap</a>'
120120
},
121121
},
122-
layers: protomaps_themes_base.default("protomaps", "light")
122+
layers: basemaps.layers("protomaps", basemaps.namedFlavor("light"), {lang: "en"})
123123
},
124124
});
125125
</script>
@@ -129,7 +129,7 @@ Below is a complete example of a map application that avoids third-party data pr
129129

130130
* `maplibre-gl.js`, `maplibre-gl.css` - JavaScript and CSS for the MapLibre GL rendering library.
131131
* `pmtiles.js` - JavaScript for decoding PMTiles archives in the browser.
132-
* `protomaps-themes-base.js` - JavaScript for creating a MapLibre GL style for a basemap tileset.
132+
* `basemaps.js` - JavaScript for creating a MapLibre GL style for a basemap tileset.
133133
* `mapbox-gl-rtl-text.min.js` - MapLibre plugin for supporting right-to-left languages.
134134
* `fonts/{fontstack}/{range}.pbf` - Font glyphs for rendering labels, available at [protomaps/basemaps-assets](https://github.com/protomaps/basemaps-assets).
135-
* `sprites/{version/{theme}` - Sprites for basemap icons, available at [protomaps/basemaps-assets](https://github.com/protomaps/basemaps-assets).
135+
* `sprites/{version/{flavor_name}` - Sprites for basemap icons, available at [protomaps/basemaps-assets](https://github.com/protomaps/basemaps-assets).

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"maplibre-gl": "^4.7.1",
1111
"pmtiles": "^4.1.0",
12-
"protomaps-themes-base": "4.4.0",
12+
"@protomaps/basemaps": "5.0.0",
1313
"vitepress": "^1.5.0"
1414
},
1515
"devDependencies": {

0 commit comments

Comments
 (0)