From 3a50140c2c514a16ad0509f33f0a89c0bf475466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20=C5=9Awi=C4=99cki?= Date: Wed, 18 Nov 2026 21:57:50 +0100 Subject: [PATCH 1/5] Add maps-vector-uploader The new command publishes a vector tiles based map into cinode: * index.html - MapLibre GL JS based viewer with rotate buttons, * style.json - OpenMapTiles schema style derived from OSM Bright with OSM Carto-like colors, road widths and house numbers, * tiles - pre-generated vector tiles (e.g. from Planetiler) taken from one or more directories, later directories override earlier ones so that detailed regions can be layered over a low-zoom world map, * optional assets directory (MapLibre build, fonts, sprites), fetched with toolbox/fetch-vector-assets.sh. Regions may have different max zoom levels: missing tiles are rendered by the viewer from the closest existing ancestor tile (overzoom.mjs), tiles/coverage.json lists per-zoom bounding rectangles of existing tiles so that non-existing ones are not probed. Like maps-tile-uploader it is configured through environment variables. The writer info can be kept in a file (CINODE_MAPTILES_WRITERINFO_FILE), a new link is created and saved there when the file doesn't exist, and the map entrypoint can be saved after the upload (CINODE_MAPTILES_ENTRYPOINT_FILE), so that consecutive runs update the same map without passing secrets around. Co-Authored-By: Claude Opus 5.5 --- README.md | 70 + cmd/maps-vector-uploader/main.go | 213 + cmd/maps-vector-uploader/main_test.go | 147 + pkg/vectormap/static_data/vector/index.html | 97 + pkg/vectormap/static_data/vector/overzoom.mjs | 219 + pkg/vectormap/static_data/vector/style.json | 8192 +++++++++++++++++ pkg/vectormap/vectormap.go | 326 + pkg/vectormap/vectormap_test.go | 126 + toolbox/fetch-vector-assets.sh | 47 + 9 files changed, 9437 insertions(+) create mode 100644 cmd/maps-vector-uploader/main.go create mode 100644 cmd/maps-vector-uploader/main_test.go create mode 100644 pkg/vectormap/static_data/vector/index.html create mode 100644 pkg/vectormap/static_data/vector/overzoom.mjs create mode 100644 pkg/vectormap/static_data/vector/style.json create mode 100644 pkg/vectormap/vectormap.go create mode 100644 pkg/vectormap/vectormap_test.go create mode 100755 toolbox/fetch-vector-assets.sh diff --git a/README.md b/README.md index 4007404..db1aea0 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,73 @@ Changing PostgreSQL server settings restarts PostgreSQL which aborts a running import, the import is then started again from scratch. `noSync: true` additionally disables crash safety of PostgreSQL, a crash can then corrupt the database which has to be imported again. + +## Vector map (prototype) + +`maps-vector-uploader` publishes a vector tiles based map: pre-generated +tiles split by zoom level (same `{z}/{x}/{y}` layout as the raster map), +styled and rendered in the browser with MapLibre GL JS. + +Resulting cinode directory: + +```text +/index.html MapLibre viewer +/overzoom.mjs client-side over-zoom for regions with lower max zoom +/style.json map style (OpenMapTiles schema, derived from OSM Bright + with OSM Carto-like colors, road widths and house numbers) +/maplibre/ MapLibre GL JS +/fonts/{fontstack}/{range}.pbf +/sprites/sprite*.{json,png} +/tiles/coverage.json per-zoom bounding rectangles of existing tiles +/tiles/{z}/{x}/{y}.pbf uncompressed Mapbox Vector Tiles +``` + +### 1. Generate tiles with Planetiler + +[Planetiler](https://github.com/onthegomap/planetiler) builds OpenMapTiles-schema +tiles straight from an `.osm.pbf` file (no database). Tiles must be written as +plain files and **without gzip** (the cinode proxy does not set +`Content-Encoding`). + +Low zoom levels for the whole world (Natural Earth + water polygons): + +```bash +java -Xmx6g -jar planetiler.jar --area=luxembourg --bounds=world --download \ + --output="tiles-world?format=files" --tile_compression=none --maxzoom=6 +``` + +Detailed region(s): + +```bash +java -Xmx6g -jar planetiler.jar --area=luxembourg --download \ + --output="tiles-luxembourg?format=files" --tile_compression=none --maxzoom=14 +``` + +### 2. Fetch client-side assets + +```bash +toolbox/fetch-vector-assets.sh assets +``` + +### 3. Upload to cinode + +```bash +CINODE_DATASTORE= \ +CINODE_MAPTILES_NEW_WRITERINFO=1 \ +CINODE_VECTOR_TILES_DIRS=tiles-world:tiles-luxembourg \ +CINODE_VECTOR_ASSETS_DIR=assets \ +go run ./cmd/maps-vector-uploader +``` + +Tiles from later directories override earlier ones. Use +`CINODE_MAPTILES_WRITERINFO=` instead of +`CINODE_MAPTILES_NEW_WRITERINFO` to update an existing map. Unchanged tiles +produce the same blobs, so an update only stores what actually changed. + +### Different max zoom per region + +MapLibre supports a single max zoom per source. When a tile doesn't exist +(e.g. z10 outside of detailed regions), `overzoom.mjs` fetches the closest +existing ancestor tile (using `tiles/coverage.json` to skip non-existing ones) +and rescales its geometry on the client. Above the highest generated zoom +(14), MapLibre over-zooms natively. diff --git a/cmd/maps-vector-uploader/main.go b/cmd/maps-vector-uploader/main.go new file mode 100644 index 0000000..0790b4c --- /dev/null +++ b/cmd/maps-vector-uploader/main.go @@ -0,0 +1,213 @@ +// Command maps-vector-uploader publishes a vector tiles based map into cinode +package main + +import ( + "context" + "errors" + "fmt" + "io/fs" + "log/slog" + "os" + "os/signal" + "path/filepath" + "runtime" + "strconv" + "strings" + "syscall" + + "github.com/cinode/go/pkg/blenc" + "github.com/cinode/go/pkg/cinodefs" + "github.com/cinode/go/pkg/datastore" + "github.com/cinode/osm-machinery/pkg/vectormap" +) + +const usageStr = ` +This program uploads a vector tiles based map (pre-generated tiles, +MapLibre GL JS viewer and client-side assets) to Cinode datastore. +It is configured through environment variables: + + * CINODE_DATASTORE - address of the target datastore, required + * CINODE_MAPTILES_WRITERINFO - writerinfo of map entrypoint + * CINODE_MAPTILES_NEW_WRITERINFO - create new writerinfo + * CINODE_MAPTILES_WRITERINFO_FILE - file with writerinfo of map entrypoint, + if the file does not exist, new writerinfo is created and saved there + * CINODE_MAPTILES_ENTRYPOINT_FILE - file where the map entrypoint is saved + after a successful upload + * CINODE_VECTOR_TILES_DIRS - list of directories with uncompressed + {z}/{x}/{y}.pbf tiles separated with '` + string(os.PathListSeparator) + `', required, + tiles from later directories override earlier ones + * CINODE_VECTOR_ASSETS_DIR - directory with client-side assets + (maplibre/, fonts/, sprites/) + * CINODE_VECTOR_PARALLELISM - number of concurrent tile uploads, + defaults to the number of CPUs +` + +type envConfig struct { + datastoreAddr string + writerInfo string + writerInfoFile string + entrypointFile string + vector vectormap.Config + newWriterInfo bool +} + +func configFromEnv(getenv func(string) string) (envConfig, error) { + cfg := envConfig{ + datastoreAddr: getenv("CINODE_DATASTORE"), + writerInfo: getenv("CINODE_MAPTILES_WRITERINFO"), + writerInfoFile: getenv("CINODE_MAPTILES_WRITERINFO_FILE"), + entrypointFile: getenv("CINODE_MAPTILES_ENTRYPOINT_FILE"), + newWriterInfo: getenv("CINODE_MAPTILES_NEW_WRITERINFO") != "", + vector: vectormap.Config{ + AssetsDir: getenv("CINODE_VECTOR_ASSETS_DIR"), + Parallelism: runtime.NumCPU(), + }, + } + + if cfg.datastoreAddr == "" { + return cfg, errors.New("missing CINODE_DATASTORE env variable") + } + + if cfg.writerInfo == "" && cfg.writerInfoFile == "" && !cfg.newWriterInfo { + return cfg, errors.New( + "one of CINODE_MAPTILES_WRITERINFO, CINODE_MAPTILES_WRITERINFO_FILE " + + "or CINODE_MAPTILES_NEW_WRITERINFO env variables must be specified", + ) + } + + for _, dir := range filepath.SplitList(getenv("CINODE_VECTOR_TILES_DIRS")) { + if dir != "" { + cfg.vector.TilesDirs = append(cfg.vector.TilesDirs, dir) + } + } + if len(cfg.vector.TilesDirs) == 0 { + return cfg, errors.New("missing CINODE_VECTOR_TILES_DIRS env variable") + } + + if p := getenv("CINODE_VECTOR_PARALLELISM"); p != "" { + n, err := strconv.Atoi(p) + if err != nil || n < 1 { + return cfg, fmt.Errorf("invalid CINODE_VECTOR_PARALLELISM value: '%s'", p) + } + cfg.vector.Parallelism = n + } + + return cfg, nil +} + +func usage(msg string) { + fmt.Fprint(os.Stderr, usageStr) + fmt.Fprintf(os.Stderr, "\nError: %s\n", msg) + os.Exit(1) +} + +func main() { + cfg, err := configFromEnv(os.Getenv) + if err != nil { + usage(err.Error()) + } + + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) + err = run(ctx, slog.Default(), cfg) + cancel() + if err != nil { + slog.Error("Failed to upload vector map", "err", err) + os.Exit(1) + } +} + +// rootOption selects the root of the uploaded map, the returned flag is set +// if a new link is created and its writer info must be saved +func rootOption(cfg envConfig) (cinodefs.Option, bool, error) { + switch { + case cfg.writerInfo != "": + return cinodefs.RootWriterInfoString(cfg.writerInfo), false, nil + + case cfg.writerInfoFile != "": + data, err := os.ReadFile(cfg.writerInfoFile) + if errors.Is(err, fs.ErrNotExist) { + return cinodefs.NewRootDynamicLink(), true, nil + } + if err != nil { + return nil, false, fmt.Errorf("failed to read writer info file: %w", err) + } + return cinodefs.RootWriterInfoString(strings.TrimSpace(string(data))), false, nil + + default: + return cinodefs.NewRootDynamicLink(), true, nil + } +} + +// writeFileAtomic replaces the file content so that readers never observe +// a partially written file +func writeFileAtomic(path, data string, perm os.FileMode) error { + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + return err + } + tmp := path + ".tmp" + if err := os.WriteFile(tmp, []byte(data+"\n"), perm); err != nil { + return err + } + return os.Rename(tmp, path) +} + +func run(ctx context.Context, log *slog.Logger, cfg envConfig) error { + ds, err := datastore.FromLocation(cfg.datastoreAddr) + if err != nil { + return fmt.Errorf("failed to open datastore: %w", err) + } + + rootOpt, newLink, err := rootOption(cfg) + if err != nil { + return err + } + + cfs, err := cinodefs.New(ctx, blenc.FromDatastore(ds), rootOpt) + if err != nil { + return fmt.Errorf("failed to open cinodefs root: %w", err) + } + + if newLink { + // Store the link in the datastore before its writer info is saved, + // otherwise a failed upload would leave writer info of a link that + // does not exist + if err := cfs.Flush(ctx); err != nil { + return fmt.Errorf("failed to store new link: %w", err) + } + wi, err := cfs.RootWriterInfo(ctx) + if err != nil { + return err + } + if cfg.writerInfoFile != "" { + // Saved before the upload so that the link is not lost if the upload fails + if err := writeFileAtomic(cfg.writerInfoFile, wi.String(), 0o600); err != nil { + return fmt.Errorf("failed to save writer info: %w", err) + } + log.InfoContext(ctx, "Created new map link", "writerInfoFile", cfg.writerInfoFile) + } else { + fmt.Printf("WriterInfo: %s\n", wi) + } + } + + if err := vectormap.Generate(ctx, log, cfg.vector, cfs); err != nil { + return err + } + + if err := cfs.Flush(ctx); err != nil { + return fmt.Errorf("failed to flush the filesystem: %w", err) + } + + ep, err := cfs.RootEntrypoint() + if err != nil { + return err + } + fmt.Printf("Entrypoint: %s\n", ep) + + if cfg.entrypointFile != "" { + if err := writeFileAtomic(cfg.entrypointFile, ep.String(), 0o644); err != nil { + return fmt.Errorf("failed to save entrypoint: %w", err) + } + } + + return nil +} diff --git a/cmd/maps-vector-uploader/main_test.go b/cmd/maps-vector-uploader/main_test.go new file mode 100644 index 0000000..11ca586 --- /dev/null +++ b/cmd/maps-vector-uploader/main_test.go @@ -0,0 +1,147 @@ +package main + +import ( + "context" + "io" + "log/slog" + "os" + "path/filepath" + "runtime" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func envFrom(m map[string]string) func(string) string { + return func(k string) string { return m[k] } +} + +func TestConfigFromEnv(t *testing.T) { + base := func() map[string]string { + return map[string]string{ + "CINODE_DATASTORE": "memory://", + "CINODE_MAPTILES_WRITERINFO": "wi", + "CINODE_VECTOR_TILES_DIRS": "/world:/region", + } + } + + t.Run("valid", func(t *testing.T) { + env := base() + env["CINODE_VECTOR_ASSETS_DIR"] = "/assets" + cfg, err := configFromEnv(envFrom(env)) + require.NoError(t, err) + require.Equal(t, "memory://", cfg.datastoreAddr) + require.Equal(t, "wi", cfg.writerInfo) + require.False(t, cfg.newWriterInfo) + require.Equal(t, []string{"/world", "/region"}, cfg.vector.TilesDirs) + require.Equal(t, "/assets", cfg.vector.AssetsDir) + require.Equal(t, runtime.NumCPU(), cfg.vector.Parallelism) + }) + + t.Run("new writer info and parallelism", func(t *testing.T) { + env := base() + delete(env, "CINODE_MAPTILES_WRITERINFO") + env["CINODE_MAPTILES_NEW_WRITERINFO"] = "1" + env["CINODE_VECTOR_PARALLELISM"] = "3" + cfg, err := configFromEnv(envFrom(env)) + require.NoError(t, err) + require.True(t, cfg.newWriterInfo) + require.Equal(t, 3, cfg.vector.Parallelism) + }) + + t.Run("writer info file", func(t *testing.T) { + env := base() + delete(env, "CINODE_MAPTILES_WRITERINFO") + env["CINODE_MAPTILES_WRITERINFO_FILE"] = "/data/wi" + env["CINODE_MAPTILES_ENTRYPOINT_FILE"] = "/data/ep" + cfg, err := configFromEnv(envFrom(env)) + require.NoError(t, err) + require.Equal(t, "/data/wi", cfg.writerInfoFile) + require.Equal(t, "/data/ep", cfg.entrypointFile) + }) + + for name, mod := range map[string]func(map[string]string){ + "no datastore": func(m map[string]string) { delete(m, "CINODE_DATASTORE") }, + "no writer info": func(m map[string]string) { delete(m, "CINODE_MAPTILES_WRITERINFO") }, + "no tiles dirs": func(m map[string]string) { m["CINODE_VECTOR_TILES_DIRS"] = ":" }, + "invalid parallelism": func(m map[string]string) { m["CINODE_VECTOR_PARALLELISM"] = "0" }, + } { + t.Run(name, func(t *testing.T) { + env := base() + mod(env) + _, err := configFromEnv(envFrom(env)) + require.Error(t, err) + }) + } +} + +func readTrimmed(t *testing.T, path string) string { + t.Helper() + data, err := os.ReadFile(path) + require.NoError(t, err) + return strings.TrimSpace(string(data)) +} + +func TestRunPersistsLink(t *testing.T) { + ctx := context.Background() + log := slog.New(slog.NewTextHandler(io.Discard, nil)) + + dir := t.TempDir() + tiles := filepath.Join(dir, "tiles") + require.NoError(t, os.MkdirAll(filepath.Join(tiles, "0", "0"), 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(tiles, "0", "0", "0.pbf"), []byte("tile"), 0o644)) + + cfg, err := configFromEnv(envFrom(map[string]string{ + "CINODE_DATASTORE": "file://" + filepath.Join(dir, "datastore"), + "CINODE_MAPTILES_WRITERINFO_FILE": filepath.Join(dir, "link", "writerinfo"), + "CINODE_MAPTILES_ENTRYPOINT_FILE": filepath.Join(dir, "link", "entrypoint"), + "CINODE_VECTOR_TILES_DIRS": tiles, + "CINODE_VECTOR_PARALLELISM": "2", + })) + require.NoError(t, err) + + // First run creates a new link and saves its writer info + require.NoError(t, run(ctx, log, cfg)) + wi := readTrimmed(t, cfg.writerInfoFile) + ep := readTrimmed(t, cfg.entrypointFile) + require.NotEmpty(t, wi) + require.NotEmpty(t, ep) + + st, err := os.Stat(cfg.writerInfoFile) + require.NoError(t, err) + require.Equal(t, os.FileMode(0o600), st.Mode().Perm()) + + // Next run updates the same link + require.NoError(t, os.WriteFile(filepath.Join(tiles, "0", "0", "0.pbf"), []byte("tile-v2"), 0o644)) + require.NoError(t, run(ctx, log, cfg)) + require.Equal(t, wi, readTrimmed(t, cfg.writerInfoFile)) + require.Equal(t, ep, readTrimmed(t, cfg.entrypointFile)) +} + +func TestRunReusesLinkAfterFailure(t *testing.T) { + ctx := context.Background() + log := slog.New(slog.NewTextHandler(io.Discard, nil)) + + dir := t.TempDir() + tiles := filepath.Join(dir, "tiles") + + cfg, err := configFromEnv(envFrom(map[string]string{ + "CINODE_DATASTORE": "file://" + filepath.Join(dir, "datastore"), + "CINODE_MAPTILES_WRITERINFO_FILE": filepath.Join(dir, "link", "writerinfo"), + "CINODE_MAPTILES_ENTRYPOINT_FILE": filepath.Join(dir, "link", "entrypoint"), + "CINODE_VECTOR_TILES_DIRS": tiles, + })) + require.NoError(t, err) + + // Tiles dir is missing - the upload fails after the link is created + require.Error(t, run(ctx, log, cfg)) + wi := readTrimmed(t, cfg.writerInfoFile) + require.NoFileExists(t, cfg.entrypointFile) + + require.NoError(t, os.MkdirAll(filepath.Join(tiles, "0", "0"), 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(tiles, "0", "0", "0.pbf"), []byte("tile"), 0o644)) + require.NoError(t, run(ctx, log, cfg)) + require.Equal(t, wi, readTrimmed(t, cfg.writerInfoFile)) + require.FileExists(t, cfg.entrypointFile) +} diff --git a/pkg/vectormap/static_data/vector/index.html b/pkg/vectormap/static_data/vector/index.html new file mode 100644 index 0000000..f5d87e2 --- /dev/null +++ b/pkg/vectormap/static_data/vector/index.html @@ -0,0 +1,97 @@ + + + + + Cinode maps + + + + + + + +
+ + + + diff --git a/pkg/vectormap/static_data/vector/overzoom.mjs b/pkg/vectormap/static_data/vector/overzoom.mjs new file mode 100644 index 0000000..ebd3d69 --- /dev/null +++ b/pkg/vectormap/static_data/vector/overzoom.mjs @@ -0,0 +1,219 @@ +// Client-side over-zooming of vector tiles. +// +// Tiles are pre-generated up to different max zoom levels in different +// regions (e.g. z6 for the whole world, z14 for detailed regions). MapLibre +// only supports a single max zoom per source, so for tiles that don't exist +// this module finds the closest existing ancestor tile and rescales its +// geometry so that it can be rendered as the requested tile. +// +// Only the geometry of MVT features is rewritten, all other protobuf fields +// are copied verbatim, so no vector-tile library is needed. + +// ---- protobuf helpers ------------------------------------------------------ + +function readVarint(buf, pos) { + let val = 0, mul = 1, b; + do { + b = buf[pos.p++]; + val += (b & 0x7f) * mul; + mul *= 128; + } while (b & 0x80); + return val; +} + +function writeVarint(out, val) { + while (val >= 0x80) { + out.push((val % 128) | 0x80); + val = Math.floor(val / 128); + } + out.push(val); +} + +const zigzagEncode = (n) => (n >= 0 ? 2 * n : -2 * n - 1); +const zigzagDecode = (n) => (n % 2 === 0 ? n / 2 : -(n + 1) / 2); + +// Splits a message into a list of fields: {tag, wire, start, end, value} +// where start..end covers the whole field (key included) and value is +// a varint value or [from, to) payload range for length-delimited fields. +function readFields(buf, from, to) { + const fields = []; + const pos = { p: from }; + while (pos.p < to) { + const start = pos.p; + const key = readVarint(buf, pos); + const tag = Math.floor(key / 8), wire = key & 7; + let value; + switch (wire) { + case 0: value = readVarint(buf, pos); break; + case 1: pos.p += 8; break; + case 2: { + const len = readVarint(buf, pos); + value = [pos.p, pos.p + len]; + pos.p += len; + break; + } + case 5: pos.p += 4; break; + default: throw new Error(`unsupported wire type ${wire}`); + } + fields.push({ tag, wire, start, end: pos.p, value }); + } + return fields; +} + +function pushBytes(out, bytes) { + for (let i = 0; i < bytes.length; i++) out.push(bytes[i]); +} + +function pushLenDelimited(out, tag, bytes) { + writeVarint(out, tag * 8 + 2); + writeVarint(out, bytes.length); + pushBytes(out, bytes); +} + +// ---- MVT rewriting --------------------------------------------------------- + +// Rescales geometry of a single feature, returns null if the feature lies +// completely outside of the target tile (including a buffer). +function transformGeometry(buf, [from, to], scale, offX, offY, extent) { + const pos = { p: from }; + const out = []; + let x = 0, y = 0; // cursor in source tile coordinates + let nx = 0, ny = 0; // cursor in target tile coordinates + let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; + + while (pos.p < to) { + const cmdInt = readVarint(buf, pos); + writeVarint(out, cmdInt); + const cmd = cmdInt & 7, count = Math.floor(cmdInt / 8); + if (cmd !== 1 && cmd !== 2) continue; // ClosePath has no params + for (let i = 0; i < count; i++) { + x += zigzagDecode(readVarint(buf, pos)); + y += zigzagDecode(readVarint(buf, pos)); + const tx = x * scale - offX, ty = y * scale - offY; + writeVarint(out, zigzagEncode(tx - nx)); + writeVarint(out, zigzagEncode(ty - ny)); + nx = tx; ny = ty; + if (tx < minX) minX = tx; + if (tx > maxX) maxX = tx; + if (ty < minY) minY = ty; + if (ty > maxY) maxY = ty; + } + } + + const buffer = extent / 8; + if (maxX < -buffer || maxY < -buffer || minX > extent + buffer || minY > extent + buffer) { + return null; + } + return out; +} + +function transformFeature(buf, [from, to], scale, ox, oy, extent) { + const out = []; + for (const f of readFields(buf, from, to)) { + if (f.tag === 4 && f.wire === 2) { + const geom = transformGeometry(buf, f.value, scale, ox * extent, oy * extent, extent); + if (!geom) return null; + pushLenDelimited(out, 4, geom); + } else { + pushBytes(out, buf.subarray(f.start, f.end)); + } + } + return out; +} + +function transformLayer(buf, [from, to], scale, ox, oy) { + const fields = readFields(buf, from, to); + const extentField = fields.find((f) => f.tag === 5 && f.wire === 0); + const extent = extentField ? extentField.value : 4096; + + const out = []; + for (const f of fields) { + if (f.tag === 2 && f.wire === 2) { + const feature = transformFeature(buf, f.value, scale, ox, oy, extent); + if (feature) pushLenDelimited(out, 2, feature); + } else { + pushBytes(out, buf.subarray(f.start, f.end)); + } + } + return out; +} + +// Converts tile data of tile (pz, px, py) into tile (z, x, y), where the +// latter is a descendant of the former. +export function overzoomTile(data, pz, px, py, z, x, y) { + const buf = new Uint8Array(data); + const dz = z - pz; + if (dz === 0) return buf; + const scale = 2 ** dz; + const ox = x - px * scale, oy = y - py * scale; + + const out = []; + for (const f of readFields(buf, 0, buf.length)) { + if (f.tag === 3 && f.wire === 2) { + pushLenDelimited(out, 3, transformLayer(buf, f.value, scale, ox, oy)); + } else { + pushBytes(out, buf.subarray(f.start, f.end)); + } + } + return new Uint8Array(out); +} + +// ---- MapLibre protocol ----------------------------------------------------- + +// Registers `://` protocol in MapLibre. +// The tile URL itself is a regular http(s) URL with z/x/y already +// substituted by MapLibre, e.g. `overzoom://http://host/tiles/9/1/2.pbf`. +// +// If `coverage.json` exists next to the tiles (generated by map-toolbox), +// it is used to skip ancestors that certainly don't exist, otherwise +// missing tiles are found by probing (404 responses). +export function registerOverzoomProtocol(maplibregl, name = 'overzoom') { + const missing = new Set(); // urls of tiles known not to exist + const coverages = new Map(); // tiles url prefix -> Promise + const tileRE = /^(.*\/)(\d+)\/(\d+)\/(\d+)(\.[a-z]+)$/; + + const tileURL = (prefix, z, x, y, ext) => `${prefix}${z}/${x}/${y}${ext}`; + + const getCoverage = (prefix) => { + if (!coverages.has(prefix)) { + coverages.set(prefix, fetch(prefix + 'coverage.json') + .then((r) => (r.ok ? r.json() : null)) + .then((c) => (c && c.zooms ? c.zooms : null)) + .catch(() => null)); + } + return coverages.get(prefix); + }; + + const mayExist = (coverage, z, x, y) => { + if (!coverage) return true; + const rects = coverage[z]; + return !!rects && rects.some(([x0, y0, x1, y1]) => x >= x0 && x <= x1 && y >= y0 && y <= y1); + }; + + maplibregl.addProtocol(name, async (params, abortController) => { + const url = params.url.slice(name.length + 3); + const m = tileRE.exec(url); + if (!m) throw new Error(`invalid tile url: ${url}`); + const [, prefix, zs, xs, ys, ext] = m; + const z = +zs, x = +xs, y = +ys; + const coverage = await getCoverage(prefix); + + for (let pz = z; pz >= 0; pz--) { + const px = x >> (z - pz), py = y >> (z - pz); + if (!mayExist(coverage, pz, px, py)) continue; + const u = tileURL(prefix, pz, px, py, ext); + if (missing.has(u)) continue; + + const resp = await fetch(u, { signal: abortController.signal }); + if (resp.status === 404) { + missing.add(u); + continue; + } + if (!resp.ok) throw new Error(`tile fetch failed: ${resp.status} ${u}`); + + const data = await resp.arrayBuffer(); + return { data: overzoomTile(data, pz, px, py, z, x, y).buffer }; + } + return { data: new ArrayBuffer(0) }; + }); +} diff --git a/pkg/vectormap/static_data/vector/style.json b/pkg/vectormap/static_data/vector/style.json new file mode 100644 index 0000000..7c42a37 --- /dev/null +++ b/pkg/vectormap/static_data/vector/style.json @@ -0,0 +1,8192 @@ +{ + "version": 8, + "name": "Bright", + "metadata": { + "mapbox:autocomposite": false, + "mapbox:groups": { + "1444849242106.713": { + "collapsed": false, + "name": "Places" + }, + "1444849334699.1902": { + "collapsed": true, + "name": "Bridges" + }, + "1444849345966.4436": { + "collapsed": false, + "name": "Roads" + }, + "1444849354174.1904": { + "collapsed": true, + "name": "Tunnels" + }, + "1444849364238.8171": { + "collapsed": false, + "name": "Buildings" + }, + "1444849382550.77": { + "collapsed": false, + "name": "Water" + }, + "1444849388993.3071": { + "collapsed": false, + "name": "Land" + } + }, + "mapbox:type": "template", + "openmaptiles:mapbox:owner": "openmaptiles", + "openmaptiles:mapbox:source:url": "mapbox://openmaptiles.4qljc88t", + "openmaptiles:version": "3.x", + "cinode:source": "Derived from OSM Bright v1.11 (https://github.com/openmaptiles/osm-bright-gl-style), code BSD-3-Clause, design CC-BY 4.0. Relative URLs are resolved by index.html." + }, + "bearing": 0, + "pitch": 0, + "sources": { + "openmaptiles": { + "type": "vector", + "tiles": [ + "tiles/{z}/{x}/{y}.pbf" + ], + "minzoom": 0, + "maxzoom": 14, + "attribution": "© OpenMapTiles © OpenStreetMap contributors" + } + }, + "sprite": "sprites/sprite", + "glyphs": "fonts/{fontstack}/{range}.pbf", + "layers": [ + { + "id": "background", + "type": "background", + "paint": { + "background-color": "#f2efe9" + } + }, + { + "id": "landcover-glacier", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "landcover", + "filter": [ + "==", + "subclass", + "glacier" + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "#fff", + "fill-opacity": { + "base": 1, + "stops": [ + [ + 0, + 0.9 + ], + [ + 10, + 0.3 + ] + ] + } + } + }, + { + "id": "landuse-residential", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "landuse", + "filter": [ + "all", + [ + "in", + "class", + "residential", + "suburb", + "neighbourhood" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "#e0dfdf", + "fill-opacity": { + "base": 1, + "stops": [ + [ + 9, + 0.3 + ], + [ + 12, + 1 + ] + ] + } + } + }, + { + "id": "landuse-commercial", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "landuse", + "filter": [ + "all", + [ + "==", + "$type", + "Polygon" + ], + [ + "==", + "class", + "commercial" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "hsla(1, 54%, 90%, 0.8)" + } + }, + { + "id": "landuse-industrial", + "type": "fill", + "source": "openmaptiles", + "source-layer": "landuse", + "filter": [ + "all", + [ + "==", + "$type", + "Polygon" + ], + [ + "in", + "class", + "industrial", + "garages", + "dam" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "hsla(311, 30%, 89%, 0.8)" + } + }, + { + "id": "landuse-cemetery", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "landuse", + "filter": [ + "==", + "class", + "cemetery" + ], + "paint": { + "fill-color": "#e0e4dd" + } + }, + { + "id": "landuse-hospital", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "landuse", + "filter": [ + "==", + "class", + "hospital" + ], + "paint": { + "fill-color": "#fde" + } + }, + { + "id": "landuse-school", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "landuse", + "filter": [ + "==", + "class", + "school" + ], + "paint": { + "fill-color": "#f0e8f8" + } + }, + { + "id": "landuse-railway", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "landuse", + "filter": [ + "==", + "class", + "railway" + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "hsla(30, 19%, 90%, 0.4)" + } + }, + { + "id": "landcover-wood", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "landcover", + "filter": [ + "==", + "class", + "wood" + ], + "paint": { + "fill-antialias": { + "base": 1, + "stops": [ + [ + 0, + false + ], + [ + 9, + true + ] + ] + }, + "fill-color": "#add19e", + "fill-opacity": { + "base": 1, + "stops": [ + [ + 8, + 0.4 + ], + [ + 12, + 0.8 + ] + ] + }, + "fill-outline-color": "hsla(0, 0%, 0%, 0.03)" + } + }, + { + "id": "landcover-grass", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "landcover", + "filter": [ + "==", + "class", + "grass" + ], + "paint": { + "fill-color": "#cdebb0", + "fill-opacity": 1 + } + }, + { + "id": "landcover-grass-park", + "type": "fill", + "metadata": { + "mapbox:group": "1444849388993.3071" + }, + "source": "openmaptiles", + "source-layer": "park", + "filter": [ + "==", + "class", + "public_park" + ], + "paint": { + "fill-color": "#c8facc", + "fill-opacity": 0.8 + } + }, + { + "id": "waterway_tunnel", + "type": "line", + "source": "openmaptiles", + "source-layer": "waterway", + "minzoom": 14, + "filter": [ + "all", + [ + "in", + "class", + "river", + "stream", + "canal" + ], + [ + "==", + "brunnel", + "tunnel" + ] + ], + "layout": { + "line-cap": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "#a0c8f0", + "line-dasharray": [ + 2, + 4 + ], + "line-width": { + "base": 1.3, + "stops": [ + [ + 13, + 0.5 + ], + [ + 20, + 6 + ] + ] + } + } + }, + { + "id": "waterway-other", + "type": "line", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "waterway", + "filter": [ + "all", + [ + "!in", + "class", + "canal", + "river", + "stream" + ], + [ + "==", + "intermittent", + 0 + ] + ], + "layout": { + "line-cap": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "#a0c8f0", + "line-width": { + "base": 1.3, + "stops": [ + [ + 13, + 0.5 + ], + [ + 20, + 2 + ] + ] + } + } + }, + { + "id": "waterway-other-intermittent", + "type": "line", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "waterway", + "filter": [ + "all", + [ + "!in", + "class", + "canal", + "river", + "stream" + ], + [ + "==", + "intermittent", + 1 + ] + ], + "layout": { + "line-cap": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "#a0c8f0", + "line-dasharray": [ + 4, + 3 + ], + "line-width": { + "base": 1.3, + "stops": [ + [ + 13, + 0.5 + ], + [ + 20, + 2 + ] + ] + } + } + }, + { + "id": "waterway-stream-canal", + "type": "line", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "waterway", + "filter": [ + "all", + [ + "in", + "class", + "canal", + "stream" + ], + [ + "!=", + "brunnel", + "tunnel" + ], + [ + "==", + "intermittent", + 0 + ] + ], + "layout": { + "line-cap": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "#a0c8f0", + "line-width": { + "base": 1.3, + "stops": [ + [ + 13, + 0.5 + ], + [ + 20, + 6 + ] + ] + } + } + }, + { + "id": "waterway-stream-canal-intermittent", + "type": "line", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "waterway", + "filter": [ + "all", + [ + "in", + "class", + "canal", + "stream" + ], + [ + "!=", + "brunnel", + "tunnel" + ], + [ + "==", + "intermittent", + 1 + ] + ], + "layout": { + "line-cap": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "#a0c8f0", + "line-dasharray": [ + 4, + 3 + ], + "line-width": { + "base": 1.3, + "stops": [ + [ + 13, + 0.5 + ], + [ + 20, + 6 + ] + ] + } + } + }, + { + "id": "waterway-river", + "type": "line", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "waterway", + "filter": [ + "all", + [ + "==", + "class", + "river" + ], + [ + "!=", + "brunnel", + "tunnel" + ], + [ + "==", + "intermittent", + 0 + ] + ], + "layout": { + "line-cap": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "#a0c8f0", + "line-width": { + "base": 1.2, + "stops": [ + [ + 10, + 0.8 + ], + [ + 20, + 6 + ] + ] + } + } + }, + { + "id": "waterway-river-intermittent", + "type": "line", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "waterway", + "filter": [ + "all", + [ + "==", + "class", + "river" + ], + [ + "!=", + "brunnel", + "tunnel" + ], + [ + "==", + "intermittent", + 1 + ] + ], + "layout": { + "line-cap": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "#a0c8f0", + "line-dasharray": [ + 3, + 2.5 + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 10, + 0.8 + ], + [ + 20, + 6 + ] + ] + } + } + }, + { + "id": "water-offset", + "type": "fill", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "water", + "maxzoom": 8, + "filter": [ + "==", + "$type", + "Polygon" + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "#a0c8f0", + "fill-opacity": 1, + "fill-translate": { + "base": 1, + "stops": [ + [ + 6, + [ + 2, + 0 + ] + ], + [ + 8, + [ + 0, + 0 + ] + ] + ] + } + } + }, + { + "id": "water", + "type": "fill", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "water", + "filter": [ + "all", + [ + "!=", + "intermittent", + 1 + ], + [ + "!=", + "brunnel", + "tunnel" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "hsl(210, 67%, 85%)" + } + }, + { + "id": "water-intermittent", + "type": "fill", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "water", + "filter": [ + "all", + [ + "==", + "intermittent", + 1 + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "hsl(210, 67%, 85%)", + "fill-opacity": 0.7 + } + }, + { + "id": "water-pattern", + "type": "fill", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "water", + "filter": [ + "all" + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-pattern": "wave", + "fill-translate": [ + 0, + 2.5 + ] + } + }, + { + "id": "landcover-ice-shelf", + "type": "fill", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "landcover", + "filter": [ + "==", + "subclass", + "ice_shelf" + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "#fff", + "fill-opacity": { + "base": 1, + "stops": [ + [ + 0, + 0.9 + ], + [ + 10, + 0.3 + ] + ] + } + } + }, + { + "id": "landcover-sand", + "type": "fill", + "metadata": { + "mapbox:group": "1444849382550.77" + }, + "source": "openmaptiles", + "source-layer": "landcover", + "filter": [ + "==", + "class", + "sand" + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "rgba(245, 238, 188, 1)", + "fill-opacity": 1 + } + }, + { + "id": "building", + "type": "fill", + "metadata": { + "mapbox:group": "1444849364238.8171" + }, + "source": "openmaptiles", + "source-layer": "building", + "paint": { + "fill-antialias": true, + "fill-color": "#d9d0c9", + "fill-outline-color": "#c4b6ab", + "fill-opacity": { + "base": 1, + "stops": [ + [ + 13, + 0 + ], + [ + 14, + 1 + ] + ] + } + } + }, + { + "id": "tunnel-service-track-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "service", + "track" + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": "#cfcdca", + "line-dasharray": [ + 0.5, + 0.25 + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 15, + 1 + ], + [ + 16, + 4 + ], + [ + 20, + 11 + ] + ] + } + } + }, + { + "id": "tunnel-motorway-link-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "motorway" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-dasharray": [ + 0.5, + 0.25 + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 2 + ], + [ + 13, + 4.0 + ], + [ + 14, + 5.5 + ], + [ + 15, + 8 + ], + [ + 16, + 10.5 + ], + [ + 17, + 15 + ], + [ + 18, + 20 + ], + [ + 19, + 26 + ] + ] + } + } + }, + { + "id": "tunnel-minor-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "minor" + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": "#cfcdca", + "line-opacity": { + "stops": [ + [ + 12, + 0 + ], + [ + 12.5, + 1 + ] + ] + }, + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 1.5 + ], + [ + 12, + 2 + ], + [ + 13, + 4.0 + ], + [ + 14, + 5.5 + ], + [ + 15, + 8.5 + ], + [ + 16, + 12 + ], + [ + 17, + 18 + ], + [ + 18, + 24 + ], + [ + 19, + 32 + ] + ] + }, + "line-dasharray": [ + 0.5, + 0.25 + ] + } + }, + { + "id": "tunnel-link-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "trunk", + "primary", + "secondary", + "tertiary" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 2 + ], + [ + 13, + 4.0 + ], + [ + 14, + 5.5 + ], + [ + 15, + 8 + ], + [ + 16, + 10.5 + ], + [ + 17, + 15 + ], + [ + 18, + 20 + ], + [ + 19, + 26 + ] + ] + }, + "line-dasharray": [ + 0.5, + 0.25 + ] + } + }, + { + "id": "tunnel-secondary-tertiary-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "secondary", + "tertiary" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 7, + 1.5 + ], + [ + 9, + 2.5 + ], + [ + 11, + 3.5 + ], + [ + 13, + 6.0 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10.5 + ], + [ + 16, + 14.5 + ], + [ + 17, + 21 + ], + [ + 18, + 28 + ], + [ + 19, + 37 + ] + ] + }, + "line-dasharray": [ + 0.5, + 0.25 + ] + } + }, + { + "id": "tunnel-trunk-primary-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "primary", + "trunk" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 1.5 + ], + [ + 8, + 2.5 + ], + [ + 11, + 4 + ], + [ + 13, + 7.0 + ], + [ + 14, + 9.0 + ], + [ + 15, + 12 + ], + [ + 16, + 16.5 + ], + [ + 17, + 23 + ], + [ + 18, + 31 + ], + [ + 19, + 41 + ] + ] + }, + "line-dasharray": [ + 0.5, + 0.25 + ] + } + }, + { + "id": "tunnel-motorway-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "motorway" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-dasharray": [ + 0.5, + 0.25 + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 1.5 + ], + [ + 8, + 2.5 + ], + [ + 11, + 4 + ], + [ + 13, + 7.0 + ], + [ + 14, + 9.0 + ], + [ + 15, + 12 + ], + [ + 16, + 16.5 + ], + [ + 17, + 23 + ], + [ + 18, + 31 + ], + [ + 19, + 41 + ] + ] + } + } + }, + { + "id": "tunnel-path-steps-casing", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "path" + ], + [ + "==", + "subclass", + "steps" + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round" + }, + "paint": { + "line-color": "#cfcdca", + "line-opacity": { + "stops": [ + [ + 12, + 0 + ], + [ + 12.5, + 1 + ] + ] + }, + "line-width": { + "base": 1.2, + "stops": [ + [ + 12, + 0.5 + ], + [ + 13, + 1 + ], + [ + 14, + 2 + ], + [ + 20, + 9.25 + ] + ] + }, + "line-dasharray": [ + 0.5, + 0.25 + ] + } + }, + { + "id": "tunnel-path-steps", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "path" + ], + [ + "==", + "subclass", + "steps" + ] + ], + "layout": { + "line-join": "bevel", + "line-cap": "butt" + }, + "paint": { + "line-color": "#fa8072", + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 13.5, + 0 + ], + [ + 14, + 1.25 + ], + [ + 20, + 5.75 + ] + ] + }, + "line-dasharray": [ + 0.5, + 0.25 + ] + } + }, + { + "id": "tunnel-path", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "path" + ], + [ + "!=", + "subclass", + "steps" + ] + ], + "paint": { + "line-color": [ + "match", + [ + "get", + "subclass" + ], + "cycleway", + "#0000ff", + "bridleway", + "#008000", + "#fa8072" + ], + "line-dasharray": [ + 2, + 1.5 + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 13, + 0.7 + ], + [ + 14, + 1 + ], + [ + 15, + 1.3 + ], + [ + 16, + 1.7 + ], + [ + 17, + 2.2 + ], + [ + 19, + 3 + ] + ] + } + } + }, + { + "id": "tunnel-motorway-link", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "motorway" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 1 + ], + [ + 13, + 2.5 + ], + [ + 14, + 4 + ], + [ + 15, + 6 + ], + [ + 16, + 8.5 + ], + [ + 17, + 12 + ], + [ + 18, + 17 + ], + [ + 19, + 23 + ] + ] + } + } + }, + { + "id": "tunnel-service-track", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "service", + "track" + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": "#fff", + "line-width": { + "base": 1.2, + "stops": [ + [ + 15.5, + 0 + ], + [ + 16, + 2 + ], + [ + 20, + 7.5 + ] + ] + } + } + }, + { + "id": "tunnel-link", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "trunk", + "primary", + "secondary", + "tertiary" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 1 + ], + [ + 13, + 2.5 + ], + [ + 14, + 4 + ], + [ + 15, + 6 + ], + [ + 16, + 8.5 + ], + [ + 17, + 12 + ], + [ + 18, + 17 + ], + [ + 19, + 23 + ] + ] + } + } + }, + { + "id": "tunnel-minor", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "minor" + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": "#fff", + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 0.5 + ], + [ + 12, + 1 + ], + [ + 13, + 2.5 + ], + [ + 14, + 4 + ], + [ + 15, + 6.5 + ], + [ + 16, + 10 + ], + [ + 17, + 15 + ], + [ + 18, + 21 + ], + [ + 19, + 29 + ] + ] + } + } + }, + { + "id": "tunnel-secondary-tertiary", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "secondary", + "tertiary" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 7, + 0.5 + ], + [ + 9, + 1.5 + ], + [ + 11, + 2.5 + ], + [ + 13, + 4.5 + ], + [ + 14, + 6 + ], + [ + 15, + 8.5 + ], + [ + 16, + 12.5 + ], + [ + 17, + 18 + ], + [ + 18, + 25 + ], + [ + 19, + 34 + ] + ] + } + } + }, + { + "id": "tunnel-trunk-primary", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "primary", + "trunk" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 0.5 + ], + [ + 8, + 1.5 + ], + [ + 11, + 3 + ], + [ + 13, + 5.5 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10 + ], + [ + 16, + 14.5 + ], + [ + 17, + 20 + ], + [ + 18, + 28 + ], + [ + 19, + 38 + ] + ] + } + } + }, + { + "id": "tunnel-motorway", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "motorway" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 0.5 + ], + [ + 8, + 1.5 + ], + [ + 11, + 3 + ], + [ + 13, + 5.5 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10 + ], + [ + 16, + 14.5 + ], + [ + 17, + 20 + ], + [ + 18, + 28 + ], + [ + 19, + 38 + ] + ] + } + } + }, + { + "id": "tunnel-railway", + "type": "line", + "metadata": { + "mapbox:group": "1444849354174.1904" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "rail" + ] + ], + "paint": { + "line-color": "#bbb", + "line-dasharray": [ + 2, + 2 + ], + "line-width": { + "base": 1.4, + "stops": [ + [ + 14, + 0.4 + ], + [ + 15, + 0.75 + ], + [ + 20, + 2 + ] + ] + } + } + }, + { + "id": "ferry", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "in", + "class", + "ferry" + ] + ], + "layout": { + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "rgba(108, 159, 182, 1)", + "line-dasharray": [ + 2, + 2 + ], + "line-width": 1.1 + } + }, + { + "id": "aeroway-taxiway-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "aeroway", + "minzoom": 12, + "filter": [ + "all", + [ + "in", + "class", + "taxiway" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "rgba(153, 153, 153, 1)", + "line-opacity": 1, + "line-width": { + "base": 1.5, + "stops": [ + [ + 11, + 2 + ], + [ + 17, + 12 + ] + ] + } + } + }, + { + "id": "aeroway-runway-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "aeroway", + "minzoom": 12, + "filter": [ + "all", + [ + "in", + "class", + "runway" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "rgba(153, 153, 153, 1)", + "line-opacity": 1, + "line-width": { + "base": 1.5, + "stops": [ + [ + 11, + 5 + ], + [ + 17, + 55 + ] + ] + } + } + }, + { + "id": "aeroway-area", + "type": "fill", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "aeroway", + "minzoom": 4, + "filter": [ + "all", + [ + "==", + "$type", + "Polygon" + ], + [ + "in", + "class", + "runway", + "taxiway" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-color": "rgba(255, 255, 255, 1)", + "fill-opacity": { + "base": 1, + "stops": [ + [ + 13, + 0 + ], + [ + 14, + 1 + ] + ] + } + } + }, + { + "id": "aeroway-taxiway", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "aeroway", + "minzoom": 4, + "filter": [ + "all", + [ + "in", + "class", + "taxiway" + ], + [ + "==", + "$type", + "LineString" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "rgba(255, 255, 255, 1)", + "line-opacity": { + "base": 1, + "stops": [ + [ + 11, + 0 + ], + [ + 12, + 1 + ] + ] + }, + "line-width": { + "base": 1.5, + "stops": [ + [ + 11, + 1 + ], + [ + 17, + 10 + ] + ] + } + } + }, + { + "id": "aeroway-runway", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "aeroway", + "minzoom": 4, + "filter": [ + "all", + [ + "in", + "class", + "runway" + ], + [ + "==", + "$type", + "LineString" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "rgba(255, 255, 255, 1)", + "line-opacity": { + "base": 1, + "stops": [ + [ + 11, + 0 + ], + [ + 12, + 1 + ] + ] + }, + "line-width": { + "base": 1.5, + "stops": [ + [ + 11, + 4 + ], + [ + 17, + 50 + ] + ] + } + } + }, + { + "id": "road_area_pier", + "type": "fill", + "metadata": {}, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "Polygon" + ], + [ + "==", + "class", + "pier" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-antialias": true, + "fill-color": "#f8f4f0" + } + }, + { + "id": "road_pier", + "type": "line", + "metadata": {}, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "in", + "class", + "pier" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-color": "#f8f4f0", + "line-width": { + "base": 1.2, + "stops": [ + [ + 15, + 1 + ], + [ + 17, + 4 + ] + ] + } + } + }, + { + "id": "highway-area", + "type": "fill", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "Polygon" + ], + [ + "!in", + "class", + "pier" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "fill-antialias": false, + "fill-color": "hsla(0, 0%, 89%, 0.56)", + "fill-opacity": 0.9, + "fill-outline-color": "#cfcdca" + } + }, + { + "id": "highway-path-steps-casing", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "path" + ], + [ + "in", + "subclass", + "steps" + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round" + }, + "paint": { + "line-color": "#cfcdca", + "line-opacity": { + "stops": [ + [ + 12, + 0 + ], + [ + 12.5, + 1 + ] + ] + }, + "line-width": { + "base": 1.2, + "stops": [ + [ + 12, + 0.5 + ], + [ + 13, + 1 + ], + [ + 14, + 2 + ], + [ + 20, + 9.25 + ] + ] + } + } + }, + { + "id": "highway-motorway-link-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 12, + "filter": [ + "all", + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "motorway" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 2 + ], + [ + 13, + 4.0 + ], + [ + 14, + 5.5 + ], + [ + 15, + 8 + ], + [ + 16, + 10.5 + ], + [ + 17, + 15 + ], + [ + 18, + 20 + ], + [ + 19, + 26 + ] + ] + } + } + }, + { + "id": "highway-link-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 13, + "filter": [ + "all", + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "in", + "class", + "trunk", + "primary", + "secondary", + "tertiary" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 2 + ], + [ + 13, + 4.0 + ], + [ + 14, + 5.5 + ], + [ + 15, + 8 + ], + [ + 16, + 10.5 + ], + [ + 17, + 15 + ], + [ + 18, + 20 + ], + [ + 19, + 26 + ] + ] + } + } + }, + { + "id": "highway-minor-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!=", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "minor", + "service" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-color": "#bbbbbb", + "line-opacity": { + "base": 1, + "stops": [ + [ + 12, + 0 + ], + [ + 12.5, + 1 + ] + ] + }, + "line-width": [ + "interpolate", + [ + "exponential", + 1.4 + ], + [ + "zoom" + ], + 11, + [ + "match", + [ + "get", + "class" + ], + "service", + 0, + 1.5 + ], + 12, + [ + "match", + [ + "get", + "class" + ], + "service", + 0, + 2 + ], + 13, + [ + "match", + [ + "get", + "class" + ], + "service", + 2.5, + 4.0 + ], + 14, + [ + "match", + [ + "get", + "class" + ], + "service", + 3.5, + 5.5 + ], + 15, + [ + "match", + [ + "get", + "class" + ], + "service", + 5.5, + 8.5 + ], + 16, + [ + "match", + [ + "get", + "class" + ], + "service", + 7.5, + 12 + ], + 17, + [ + "match", + [ + "get", + "class" + ], + "service", + 11.5, + 18 + ], + 18, + [ + "match", + [ + "get", + "class" + ], + "service", + 15, + 24 + ], + 19, + [ + "match", + [ + "get", + "class" + ], + "service", + 20, + 32 + ] + ] + } + }, + { + "id": "highway-secondary-tertiary-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "in", + "class", + "secondary", + "tertiary" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 7, + 1.5 + ], + [ + 9, + 2.5 + ], + [ + 11, + 3.5 + ], + [ + 13, + 6.0 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10.5 + ], + [ + 16, + 14.5 + ], + [ + 17, + 21 + ], + [ + 18, + 28 + ], + [ + 19, + 37 + ] + ] + } + } + }, + { + "id": "highway-primary-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 5, + "filter": [ + "all", + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "in", + "class", + "primary" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": { + "stops": [ + [ + 7, + 0 + ], + [ + 8, + 1 + ] + ] + }, + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 1.5 + ], + [ + 8, + 2.5 + ], + [ + 11, + 4 + ], + [ + 13, + 7.0 + ], + [ + 14, + 9.0 + ], + [ + 15, + 12 + ], + [ + 16, + 16.5 + ], + [ + 17, + 23 + ], + [ + 18, + 31 + ], + [ + 19, + 41 + ] + ] + } + } + }, + { + "id": "highway-trunk-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 5, + "filter": [ + "all", + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "in", + "class", + "trunk" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": { + "stops": [ + [ + 5, + 0 + ], + [ + 6, + 1 + ] + ] + }, + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 1.5 + ], + [ + 8, + 2.5 + ], + [ + 11, + 4 + ], + [ + 13, + 7.0 + ], + [ + 14, + 9.0 + ], + [ + 15, + 12 + ], + [ + 16, + 16.5 + ], + [ + 17, + 23 + ], + [ + 18, + 31 + ], + [ + 19, + 41 + ] + ] + } + } + }, + { + "id": "highway-motorway-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 4, + "filter": [ + "all", + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "motorway" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": { + "stops": [ + [ + 4, + 0 + ], + [ + 5, + 1 + ] + ] + }, + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 1.5 + ], + [ + 8, + 2.5 + ], + [ + 11, + 4 + ], + [ + 13, + 7.0 + ], + [ + 14, + 9.0 + ], + [ + 15, + 12 + ], + [ + 16, + 16.5 + ], + [ + 17, + 23 + ], + [ + 18, + 31 + ], + [ + 19, + 41 + ] + ] + } + } + }, + { + "id": "highway-track-casing", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 13, + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!=", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "track" + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round" + }, + "paint": { + "line-color": "rgba(255,255,255,0.6)", + "line-width": { + "base": 1.2, + "stops": [ + [ + 12, + 2.0 + ], + [ + 13, + 2.5 + ], + [ + 15, + 3.0 + ], + [ + 17, + 5.0 + ], + [ + 19, + 6.5 + ] + ] + } + } + }, + { + "id": "highway-track", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 13, + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!=", + "brunnel", + "tunnel" + ], + [ + "==", + "class", + "track" + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round" + }, + "paint": { + "line-color": "#996600", + "line-width": { + "base": 1.2, + "stops": [ + [ + 12, + 0.5 + ], + [ + 13, + 1 + ], + [ + 15, + 1.5 + ], + [ + 17, + 2.5 + ], + [ + 19, + 4 + ] + ] + }, + "line-dasharray": [ + 3, + 1.5 + ] + } + }, + { + "id": "highway-path-casing", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 15, + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "path" + ], + [ + "!=", + "subclass", + "steps" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-color": "rgba(255,255,255,0.35)", + "line-width": { + "base": 1.2, + "stops": [ + [ + 13, + 2.2 + ], + [ + 14, + 2.5 + ], + [ + 15, + 2.8 + ], + [ + 16, + 4.2 + ], + [ + 17, + 4.7 + ], + [ + 19, + 5.5 + ] + ] + } + } + }, + { + "id": "highway-path", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "path" + ], + [ + "!=", + "subclass", + "steps" + ] + ], + "paint": { + "line-color": [ + "match", + [ + "get", + "subclass" + ], + "cycleway", + "#0000ff", + "bridleway", + "#008000", + "#fa8072" + ], + "line-dasharray": [ + 2, + 1.5 + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 13, + 0.7 + ], + [ + 14, + 1 + ], + [ + 15, + 1.3 + ], + [ + 16, + 1.7 + ], + [ + 17, + 2.2 + ], + [ + 19, + 3 + ] + ] + } + } + }, + { + "id": "highway-path-steps", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "path" + ], + [ + "==", + "subclass", + "steps" + ] + ], + "layout": { + "line-join": "bevel", + "line-cap": "butt" + }, + "paint": { + "line-color": "#fa8072", + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 13.5, + 0 + ], + [ + 14, + 1.25 + ], + [ + 20, + 5.75 + ] + ] + }, + "line-dasharray": [ + 0.5, + 0.25 + ] + } + }, + { + "id": "highway-motorway-link", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 12, + "filter": [ + "all", + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "motorway" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 1 + ], + [ + 13, + 2.5 + ], + [ + 14, + 4 + ], + [ + 15, + 6 + ], + [ + 16, + 8.5 + ], + [ + 17, + 12 + ], + [ + 18, + 17 + ], + [ + 19, + 23 + ] + ] + } + } + }, + { + "id": "highway-link", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 13, + "filter": [ + "all", + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "in", + "class", + "trunk", + "primary", + "secondary", + "tertiary" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 1 + ], + [ + 13, + 2.5 + ], + [ + 14, + 4 + ], + [ + 15, + 6 + ], + [ + 16, + 8.5 + ], + [ + 17, + 12 + ], + [ + 18, + 17 + ], + [ + 19, + 23 + ] + ] + } + } + }, + { + "id": "highway-minor", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!=", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "minor", + "service" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-color": "#ffffff", + "line-opacity": 1, + "line-width": [ + "interpolate", + [ + "exponential", + 1.4 + ], + [ + "zoom" + ], + 11, + [ + "match", + [ + "get", + "class" + ], + "service", + 0, + 0.5 + ], + 12, + [ + "match", + [ + "get", + "class" + ], + "service", + 0, + 1 + ], + 13, + [ + "match", + [ + "get", + "class" + ], + "service", + 1, + 2.5 + ], + 14, + [ + "match", + [ + "get", + "class" + ], + "service", + 2, + 4 + ], + 15, + [ + "match", + [ + "get", + "class" + ], + "service", + 3.5, + 6.5 + ], + 16, + [ + "match", + [ + "get", + "class" + ], + "service", + 5.5, + 10 + ], + 17, + [ + "match", + [ + "get", + "class" + ], + "service", + 8.5, + 15 + ], + 18, + [ + "match", + [ + "get", + "class" + ], + "service", + 12, + 21 + ], + 19, + [ + "match", + [ + "get", + "class" + ], + "service", + 17, + 29 + ] + ] + } + }, + { + "id": "highway-minor-unpaved", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 14, + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!=", + "brunnel", + "tunnel" + ], + [ + "in", + "class", + "minor", + "service" + ], + [ + "==", + "surface", + "unpaved" + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round" + }, + "paint": { + "line-color": "#b8a48c", + "line-width": [ + "interpolate", + [ + "exponential", + 1.4 + ], + [ + "zoom" + ], + 14, + [ + "match", + [ + "get", + "class" + ], + "service", + 0.4, + 0.8 + ], + 15, + [ + "match", + [ + "get", + "class" + ], + "service", + 0.7, + 1.3 + ], + 16, + [ + "match", + [ + "get", + "class" + ], + "service", + 1.1, + 2.0 + ], + 17, + [ + "match", + [ + "get", + "class" + ], + "service", + 1.7, + 3.0 + ], + 18, + [ + "match", + [ + "get", + "class" + ], + "service", + 2.4, + 4.2 + ], + 19, + [ + "match", + [ + "get", + "class" + ], + "service", + 3.4, + 5.8 + ] + ], + "line-dasharray": [ + 3, + 3 + ] + } + }, + { + "id": "highway-secondary-tertiary", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "in", + "class", + "secondary", + "tertiary" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 7, + 0.5 + ], + [ + 9, + 1.5 + ], + [ + 11, + 2.5 + ], + [ + 13, + 4.5 + ], + [ + 14, + 6 + ], + [ + 15, + 8.5 + ], + [ + 16, + 12.5 + ], + [ + 17, + 18 + ], + [ + 18, + 25 + ], + [ + 19, + 34 + ] + ] + } + } + }, + { + "id": "highway-primary", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "in", + "class", + "primary" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 0.5 + ], + [ + 8, + 1.5 + ], + [ + 11, + 3 + ], + [ + 13, + 5.5 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10 + ], + [ + 16, + 14.5 + ], + [ + 17, + 20 + ], + [ + 18, + 28 + ], + [ + 19, + 38 + ] + ] + } + } + }, + { + "id": "highway-trunk", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "in", + "class", + "trunk" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 0.5 + ], + [ + 8, + 1.5 + ], + [ + 11, + 3 + ], + [ + 13, + 5.5 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10 + ], + [ + 16, + 14.5 + ], + [ + 17, + 20 + ], + [ + 18, + 28 + ], + [ + 19, + 38 + ] + ] + } + } + }, + { + "id": "highway-motorway", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 5, + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "motorway" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 0.5 + ], + [ + 8, + 1.5 + ], + [ + 11, + 3 + ], + [ + 13, + 5.5 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10 + ], + [ + 16, + 14.5 + ], + [ + 17, + 20 + ], + [ + 18, + 28 + ], + [ + 19, + 38 + ] + ] + } + } + }, + { + "id": "railway-transit", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "class", + "transit" + ], + [ + "!in", + "brunnel", + "tunnel" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "line-color": "hsla(0, 0%, 73%, 0.77)", + "line-width": { + "base": 1.4, + "stops": [ + [ + 14, + 0.4 + ], + [ + 20, + 1 + ] + ] + } + } + }, + { + "id": "railway-transit-hatching", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "class", + "transit" + ], + [ + "!in", + "brunnel", + "tunnel" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "line-color": "hsla(0, 0%, 73%, 0.68)", + "line-dasharray": [ + 0.2, + 8 + ], + "line-width": { + "base": 1.4, + "stops": [ + [ + 14.5, + 0 + ], + [ + 15, + 2 + ], + [ + 20, + 6 + ] + ] + } + } + }, + { + "id": "railway-service", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "class", + "rail" + ], + [ + "has", + "service" + ] + ], + "paint": { + "line-color": "hsla(0, 0%, 73%, 0.77)", + "line-width": { + "base": 1.4, + "stops": [ + [ + 14, + 0.4 + ], + [ + 20, + 1 + ] + ] + } + } + }, + { + "id": "railway-service-hatching", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "class", + "rail" + ], + [ + "has", + "service" + ] + ], + "layout": { + "visibility": "visible" + }, + "paint": { + "line-color": "hsla(0, 0%, 73%, 0.68)", + "line-dasharray": [ + 0.2, + 8 + ], + "line-width": { + "base": 1.4, + "stops": [ + [ + 14.5, + 0 + ], + [ + 15, + 2 + ], + [ + 20, + 6 + ] + ] + } + } + }, + { + "id": "railway", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!has", + "service" + ], + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "rail" + ] + ], + "paint": { + "line-color": "#bbb", + "line-width": { + "base": 1.4, + "stops": [ + [ + 14, + 0.4 + ], + [ + 15, + 0.75 + ], + [ + 20, + 2 + ] + ] + } + } + }, + { + "id": "railway-hatching", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "!has", + "service" + ], + [ + "!in", + "brunnel", + "bridge", + "tunnel" + ], + [ + "==", + "class", + "rail" + ] + ], + "paint": { + "line-color": "#bbb", + "line-dasharray": [ + 0.2, + 8 + ], + "line-width": { + "base": 1.4, + "stops": [ + [ + 14.5, + 0 + ], + [ + 15, + 3 + ], + [ + 20, + 8 + ] + ] + } + } + }, + { + "id": "bridge-motorway-link-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "==", + "class", + "motorway" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 2 + ], + [ + 13, + 4.0 + ], + [ + 14, + 5.5 + ], + [ + 15, + 8 + ], + [ + 16, + 10.5 + ], + [ + 17, + 15 + ], + [ + 18, + 20 + ], + [ + 19, + 26 + ] + ] + } + } + }, + { + "id": "bridge-link-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "in", + "class", + "trunk", + "primary", + "secondary", + "tertiary" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 2 + ], + [ + 13, + 4.0 + ], + [ + 14, + 5.5 + ], + [ + 15, + 8 + ], + [ + 16, + 10.5 + ], + [ + 17, + 15 + ], + [ + 18, + 20 + ], + [ + 19, + 26 + ] + ] + } + } + }, + { + "id": "bridge-secondary-tertiary-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "in", + "class", + "secondary", + "tertiary" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 7, + 1.5 + ], + [ + 9, + 2.5 + ], + [ + 11, + 3.5 + ], + [ + 13, + 6.0 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10.5 + ], + [ + 16, + 14.5 + ], + [ + 17, + 21 + ], + [ + 18, + 28 + ], + [ + 19, + 37 + ] + ] + } + } + }, + { + "id": "bridge-trunk-primary-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "in", + "class", + "primary", + "trunk" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 1.5 + ], + [ + 8, + 2.5 + ], + [ + 11, + 4 + ], + [ + 13, + 7.0 + ], + [ + 14, + 9.0 + ], + [ + 15, + 12 + ], + [ + 16, + 16.5 + ], + [ + 17, + 23 + ], + [ + 18, + 31 + ], + [ + 19, + 41 + ] + ] + } + } + }, + { + "id": "bridge-motorway-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "==", + "class", + "motorway" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#dc2a67", + "trunk", + "#c84e2f", + "primary", + "#a06b00", + "secondary", + "#707d05", + "tertiary", + "#8f8f8f", + "#8f8f8f" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 1.5 + ], + [ + 8, + 2.5 + ], + [ + 11, + 4 + ], + [ + 13, + 7.0 + ], + [ + 14, + 9.0 + ], + [ + 15, + 12 + ], + [ + 16, + 16.5 + ], + [ + 17, + 23 + ], + [ + 18, + 31 + ], + [ + 19, + 41 + ] + ] + } + } + }, + { + "id": "bridge-minor-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "brunnel", + "bridge" + ], + [ + "in", + "class", + "minor", + "service" + ] + ], + "layout": { + "line-cap": "butt", + "line-join": "round" + }, + "paint": { + "line-color": "#999999", + "line-opacity": { + "base": 1, + "stops": [ + [ + 12, + 0 + ], + [ + 12.5, + 1 + ] + ] + }, + "line-width": [ + "interpolate", + [ + "exponential", + 1.4 + ], + [ + "zoom" + ], + 11, + [ + "match", + [ + "get", + "class" + ], + "service", + 0, + 1.5 + ], + 12, + [ + "match", + [ + "get", + "class" + ], + "service", + 0, + 2 + ], + 13, + [ + "match", + [ + "get", + "class" + ], + "service", + 2.5, + 4.0 + ], + 14, + [ + "match", + [ + "get", + "class" + ], + "service", + 3.5, + 5.5 + ], + 15, + [ + "match", + [ + "get", + "class" + ], + "service", + 5.5, + 8.5 + ], + 16, + [ + "match", + [ + "get", + "class" + ], + "service", + 7.5, + 12 + ], + 17, + [ + "match", + [ + "get", + "class" + ], + "service", + 11.5, + 18 + ], + 18, + [ + "match", + [ + "get", + "class" + ], + "service", + 15, + 24 + ], + 19, + [ + "match", + [ + "get", + "class" + ], + "service", + 20, + 32 + ] + ] + } + }, + { + "id": "bridge-path-casing", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "brunnel", + "bridge" + ], + [ + "==", + "class", + "path" + ] + ], + "paint": { + "line-color": "#cfcdca", + "line-width": { + "base": 1.2, + "stops": [ + [ + 15, + 1.2 + ], + [ + 20, + 18 + ] + ] + } + } + }, + { + "id": "bridge-path-steps", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "brunnel", + "bridge" + ], + [ + "==", + "class", + "path" + ], + [ + "==", + "subclass", + "steps" + ] + ], + "layout": { + "line-join": "round", + "line-cap": "butt" + }, + "paint": { + "line-color": "#fa8072", + "line-opacity": 1, + "line-width": { + "base": 1.2, + "stops": [ + [ + 13.5, + 0 + ], + [ + 14, + 1.25 + ], + [ + 20, + 5.75 + ] + ] + }, + "line-dasharray": [ + 0.5, + 0.25 + ] + } + }, + { + "id": "bridge-path", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "brunnel", + "bridge" + ], + [ + "==", + "class", + "path" + ], + [ + "!=", + "subclass", + "steps" + ] + ], + "paint": { + "line-color": [ + "match", + [ + "get", + "subclass" + ], + "cycleway", + "#0000ff", + "bridleway", + "#008000", + "#fa8072" + ], + "line-dasharray": [ + 2, + 1.5 + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 13, + 0.7 + ], + [ + 14, + 1 + ], + [ + 15, + 1.3 + ], + [ + 16, + 1.7 + ], + [ + 17, + 2.2 + ], + [ + 19, + 3 + ] + ] + } + } + }, + { + "id": "bridge-motorway-link", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "==", + "class", + "motorway" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 1 + ], + [ + 13, + 2.5 + ], + [ + 14, + 4 + ], + [ + 15, + 6 + ], + [ + 16, + 8.5 + ], + [ + 17, + 12 + ], + [ + 18, + 17 + ], + [ + 19, + 23 + ] + ] + } + } + }, + { + "id": "bridge-link", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "in", + "class", + "trunk", + "primary", + "secondary", + "tertiary" + ], + [ + "==", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 11, + 1 + ], + [ + 13, + 2.5 + ], + [ + 14, + 4 + ], + [ + 15, + 6 + ], + [ + 16, + 8.5 + ], + [ + 17, + 12 + ], + [ + 18, + 17 + ], + [ + 19, + 23 + ] + ] + } + } + }, + { + "id": "bridge-minor", + "type": "line", + "metadata": { + "mapbox:group": "1444849345966.4436" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "==", + "brunnel", + "bridge" + ], + [ + "in", + "class", + "minor", + "service" + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round" + }, + "paint": { + "line-color": "#ffffff", + "line-opacity": 1, + "line-width": [ + "interpolate", + [ + "exponential", + 1.4 + ], + [ + "zoom" + ], + 11, + [ + "match", + [ + "get", + "class" + ], + "service", + 0, + 0.5 + ], + 12, + [ + "match", + [ + "get", + "class" + ], + "service", + 0, + 1 + ], + 13, + [ + "match", + [ + "get", + "class" + ], + "service", + 1, + 2.5 + ], + 14, + [ + "match", + [ + "get", + "class" + ], + "service", + 2, + 4 + ], + 15, + [ + "match", + [ + "get", + "class" + ], + "service", + 3.5, + 6.5 + ], + 16, + [ + "match", + [ + "get", + "class" + ], + "service", + 5.5, + 10 + ], + 17, + [ + "match", + [ + "get", + "class" + ], + "service", + 8.5, + 15 + ], + 18, + [ + "match", + [ + "get", + "class" + ], + "service", + 12, + 21 + ], + 19, + [ + "match", + [ + "get", + "class" + ], + "service", + 17, + 29 + ] + ] + } + }, + { + "id": "bridge-secondary-tertiary", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "in", + "class", + "secondary", + "tertiary" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 7, + 0.5 + ], + [ + 9, + 1.5 + ], + [ + 11, + 2.5 + ], + [ + 13, + 4.5 + ], + [ + 14, + 6 + ], + [ + 15, + 8.5 + ], + [ + 16, + 12.5 + ], + [ + 17, + 18 + ], + [ + 18, + 25 + ], + [ + 19, + 34 + ] + ] + } + } + }, + { + "id": "bridge-trunk-primary", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "in", + "class", + "primary", + "trunk" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 0.5 + ], + [ + 8, + 1.5 + ], + [ + 11, + 3 + ], + [ + 13, + 5.5 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10 + ], + [ + 16, + 14.5 + ], + [ + 17, + 20 + ], + [ + 18, + 28 + ], + [ + 19, + 38 + ] + ] + } + } + }, + { + "id": "bridge-motorway", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "==", + "class", + "motorway" + ], + [ + "!=", + "ramp", + 1 + ] + ], + "layout": { + "line-join": "round" + }, + "paint": { + "line-color": [ + "match", + [ + "get", + "class" + ], + "motorway", + "#e892a2", + "trunk", + "#f9b29c", + "primary", + "#fcd6a4", + "secondary", + "#f7fabf", + "tertiary", + "#ffffff", + "#ffffff" + ], + "line-width": { + "base": 1.2, + "stops": [ + [ + 6, + 0.5 + ], + [ + 8, + 1.5 + ], + [ + 11, + 3 + ], + [ + 13, + 5.5 + ], + [ + 14, + 7.5 + ], + [ + 15, + 10 + ], + [ + 16, + 14.5 + ], + [ + 17, + 20 + ], + [ + 18, + 28 + ], + [ + 19, + 38 + ] + ] + } + } + }, + { + "id": "bridge-railway", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "==", + "class", + "rail" + ] + ], + "paint": { + "line-color": "#bbb", + "line-width": { + "base": 1.4, + "stops": [ + [ + 14, + 0.4 + ], + [ + 15, + 0.75 + ], + [ + 20, + 2 + ] + ] + } + } + }, + { + "id": "bridge-railway-hatching", + "type": "line", + "metadata": { + "mapbox:group": "1444849334699.1902" + }, + "source": "openmaptiles", + "source-layer": "transportation", + "filter": [ + "all", + [ + "==", + "brunnel", + "bridge" + ], + [ + "==", + "class", + "rail" + ] + ], + "paint": { + "line-color": "#bbb", + "line-dasharray": [ + 0.2, + 8 + ], + "line-width": { + "base": 1.4, + "stops": [ + [ + 14.5, + 0 + ], + [ + 15, + 3 + ], + [ + 20, + 8 + ] + ] + } + } + }, + { + "id": "cablecar", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 13, + "filter": [ + "==", + "subclass", + "cable_car" + ], + "layout": { + "line-cap": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "hsl(0, 0%, 70%)", + "line-width": { + "base": 1, + "stops": [ + [ + 11, + 1 + ], + [ + 19, + 2.5 + ] + ] + } + } + }, + { + "id": "cablecar-dash", + "type": "line", + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 13, + "filter": [ + "==", + "subclass", + "cable_car" + ], + "layout": { + "line-cap": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "hsl(0, 0%, 70%)", + "line-dasharray": [ + 2, + 3 + ], + "line-width": { + "base": 1, + "stops": [ + [ + 11, + 3 + ], + [ + 19, + 5.5 + ] + ] + } + } + }, + { + "id": "boundary-land-level-4", + "type": "line", + "source": "openmaptiles", + "source-layer": "boundary", + "minzoom": 2, + "filter": [ + "all", + [ + ">=", + "admin_level", + 3 + ], + [ + "<=", + "admin_level", + 8 + ], + [ + "!=", + "maritime", + 1 + ] + ], + "layout": { + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "#9e9cab", + "line-dasharray": [ + 3, + 1, + 1, + 1 + ], + "line-width": { + "base": 1.4, + "stops": [ + [ + 4, + 0.4 + ], + [ + 5, + 1 + ], + [ + 12, + 3 + ] + ] + } + } + }, + { + "id": "boundary-land-level-2", + "type": "line", + "source": "openmaptiles", + "source-layer": "boundary", + "filter": [ + "all", + [ + "==", + "admin_level", + 2 + ], + [ + "!=", + "maritime", + 1 + ], + [ + "!=", + "disputed", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "hsl(248, 7%, 66%)", + "line-width": { + "base": 1, + "stops": [ + [ + 0, + 0.6 + ], + [ + 4, + 1.4 + ], + [ + 5, + 2 + ], + [ + 12, + 8 + ] + ] + } + } + }, + { + "id": "boundary-land-disputed", + "type": "line", + "source": "openmaptiles", + "source-layer": "boundary", + "filter": [ + "all", + [ + "!=", + "maritime", + 1 + ], + [ + "==", + "disputed", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "hsl(248, 7%, 70%)", + "line-dasharray": [ + 1, + 3 + ], + "line-width": { + "base": 1, + "stops": [ + [ + 0, + 0.6 + ], + [ + 4, + 1.4 + ], + [ + 5, + 2 + ], + [ + 12, + 8 + ] + ] + } + } + }, + { + "id": "boundary-water", + "type": "line", + "source": "openmaptiles", + "source-layer": "boundary", + "minzoom": 4, + "filter": [ + "all", + [ + "in", + "admin_level", + 2, + 4 + ], + [ + "==", + "maritime", + 1 + ] + ], + "layout": { + "line-cap": "round", + "line-join": "round", + "visibility": "visible" + }, + "paint": { + "line-color": "rgba(154, 189, 214, 1)", + "line-opacity": { + "stops": [ + [ + 6, + 0.6 + ], + [ + 10, + 1 + ] + ] + }, + "line-width": { + "base": 1, + "stops": [ + [ + 0, + 0.6 + ], + [ + 4, + 1.4 + ], + [ + 5, + 2 + ], + [ + 12, + 8 + ] + ] + } + } + }, + { + "id": "housenumber", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "housenumber", + "minzoom": 16, + "layout": { + "text-field": "{housenumber}", + "text-font": [ + "Noto Sans Regular" + ], + "text-size": { + "base": 1, + "stops": [ + [ + 16, + 10 + ], + [ + 18, + 12 + ] + ] + }, + "text-padding": 1 + }, + "paint": { + "text-color": "#666666", + "text-halo-color": "rgba(255,255,255,0.6)", + "text-halo-width": 1 + } + }, + { + "id": "waterway-name", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "waterway", + "minzoom": 13, + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "has", + "name" + ] + ], + "layout": { + "symbol-placement": "line", + "symbol-spacing": 350, + "text-field": "{name:latin} {name:nonlatin}", + "text-font": [ + "Noto Sans Italic" + ], + "text-letter-spacing": 0.2, + "text-max-width": 5, + "text-rotation-alignment": "map", + "text-size": 14 + }, + "paint": { + "text-color": "#74aee9", + "text-halo-color": "rgba(255,255,255,0.7)", + "text-halo-width": 1.5 + } + }, + { + "id": "water-name-lakeline", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "water_name", + "filter": [ + "==", + "$type", + "LineString" + ], + "layout": { + "symbol-placement": "line", + "symbol-spacing": 350, + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Italic" + ], + "text-letter-spacing": 0.2, + "text-max-width": 5, + "text-rotation-alignment": "map", + "text-size": 14 + }, + "paint": { + "text-color": "#74aee9", + "text-halo-color": "rgba(255,255,255,0.7)", + "text-halo-width": 1.5 + } + }, + { + "id": "water-name-ocean", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "water_name", + "filter": [ + "all", + [ + "==", + "$type", + "Point" + ], + [ + "==", + "class", + "ocean" + ] + ], + "layout": { + "symbol-placement": "point", + "symbol-spacing": 350, + "text-field": "{name:latin}", + "text-font": [ + "Noto Sans Italic" + ], + "text-letter-spacing": 0.2, + "text-max-width": 5, + "text-rotation-alignment": "map", + "text-size": 14 + }, + "paint": { + "text-color": "#74aee9", + "text-halo-color": "rgba(255,255,255,0.7)", + "text-halo-width": 1.5 + } + }, + { + "id": "water-name-other", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "water_name", + "filter": [ + "all", + [ + "==", + "$type", + "Point" + ], + [ + "!in", + "class", + "ocean" + ] + ], + "layout": { + "symbol-placement": "point", + "symbol-spacing": 350, + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Italic" + ], + "text-letter-spacing": 0.2, + "text-max-width": 5, + "text-rotation-alignment": "map", + "text-size": { + "stops": [ + [ + 0, + 10 + ], + [ + 6, + 14 + ] + ] + }, + "visibility": "visible" + }, + "paint": { + "text-color": "#74aee9", + "text-halo-color": "rgba(255,255,255,0.7)", + "text-halo-width": 1.5 + } + }, + { + "id": "road_oneway", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 15, + "filter": [ + "all", + [ + "==", + "oneway", + 1 + ], + [ + "in", + "class", + "motorway", + "trunk", + "primary", + "secondary", + "tertiary", + "minor", + "service" + ] + ], + "layout": { + "icon-image": "oneway", + "icon-padding": 2, + "icon-rotate": 90, + "icon-rotation-alignment": "map", + "icon-size": { + "stops": [ + [ + 15, + 0.5 + ], + [ + 19, + 1 + ] + ] + }, + "symbol-placement": "line", + "symbol-spacing": 75 + }, + "paint": { + "icon-opacity": 0.5 + } + }, + { + "id": "road_oneway_opposite", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "transportation", + "minzoom": 15, + "filter": [ + "all", + [ + "==", + "oneway", + -1 + ], + [ + "in", + "class", + "motorway", + "trunk", + "primary", + "secondary", + "tertiary", + "minor", + "service" + ] + ], + "layout": { + "icon-image": "oneway", + "icon-padding": 2, + "icon-rotate": -90, + "icon-rotation-alignment": "map", + "icon-size": { + "stops": [ + [ + 15, + 0.5 + ], + [ + 19, + 1 + ] + ] + }, + "symbol-placement": "line", + "symbol-spacing": 75 + }, + "paint": { + "icon-opacity": 0.5 + } + }, + { + "id": "poi-level-3", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "poi", + "minzoom": 16, + "filter": [ + "all", + [ + "==", + "$type", + "Point" + ], + [ + ">=", + "rank", + 25 + ], + [ + "any", + [ + "!has", + "level" + ], + [ + "==", + "level", + 0 + ] + ] + ], + "layout": { + "icon-image": "{class}_11", + "text-anchor": "top", + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-max-width": 9, + "text-offset": [ + 0, + 0.6 + ], + "text-padding": 2, + "text-size": 12, + "visibility": "visible" + }, + "paint": { + "text-color": "#555555", + "text-halo-blur": 0.5, + "text-halo-color": "#ffffff", + "text-halo-width": 1 + } + }, + { + "id": "poi-level-2", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "poi", + "minzoom": 15, + "filter": [ + "all", + [ + "==", + "$type", + "Point" + ], + [ + "<=", + "rank", + 24 + ], + [ + ">=", + "rank", + 15 + ], + [ + "any", + [ + "!has", + "level" + ], + [ + "==", + "level", + 0 + ] + ] + ], + "layout": { + "icon-image": "{class}_11", + "text-anchor": "top", + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-max-width": 9, + "text-offset": [ + 0, + 0.6 + ], + "text-padding": 2, + "text-size": 12, + "visibility": "visible" + }, + "paint": { + "text-color": "#555555", + "text-halo-blur": 0.5, + "text-halo-color": "#ffffff", + "text-halo-width": 1 + } + }, + { + "id": "poi-level-1", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "poi", + "minzoom": 14, + "filter": [ + "all", + [ + "==", + "$type", + "Point" + ], + [ + "<=", + "rank", + 14 + ], + [ + "has", + "name" + ], + [ + "any", + [ + "!has", + "level" + ], + [ + "==", + "level", + 0 + ] + ] + ], + "layout": { + "icon-image": "{class}_11", + "text-anchor": "top", + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-max-width": 9, + "text-offset": [ + 0, + 0.6 + ], + "text-padding": 2, + "text-size": 12, + "visibility": "visible" + }, + "paint": { + "text-color": "#555555", + "text-halo-blur": 0.5, + "text-halo-color": "#ffffff", + "text-halo-width": 1 + } + }, + { + "id": "poi-railway", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "poi", + "minzoom": 13, + "filter": [ + "all", + [ + "==", + "$type", + "Point" + ], + [ + "has", + "name" + ], + [ + "==", + "class", + "railway" + ], + [ + "==", + "subclass", + "station" + ] + ], + "layout": { + "icon-allow-overlap": false, + "icon-ignore-placement": false, + "icon-image": "{class}_11", + "icon-optional": false, + "text-allow-overlap": false, + "text-anchor": "top", + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-ignore-placement": false, + "text-max-width": 9, + "text-offset": [ + 0, + 0.6 + ], + "text-optional": true, + "text-padding": 2, + "text-size": 12 + }, + "paint": { + "text-color": "#666", + "text-halo-blur": 0.5, + "text-halo-color": "#ffffff", + "text-halo-width": 1 + } + }, + { + "id": "highway-name-path", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "transportation_name", + "minzoom": 15.5, + "filter": [ + "==", + "class", + "path" + ], + "layout": { + "symbol-placement": "line", + "text-field": "{name:latin} {name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-rotation-alignment": "map", + "text-size": { + "base": 1, + "stops": [ + [ + 15, + 10 + ], + [ + 17, + 11 + ], + [ + 19, + 13 + ] + ] + } + }, + "paint": { + "text-color": "#6b4f3a", + "text-halo-color": "#ffffff", + "text-halo-width": 1.5 + } + }, + { + "id": "highway-name-minor", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "transportation_name", + "minzoom": 15, + "filter": [ + "all", + [ + "==", + "$type", + "LineString" + ], + [ + "in", + "class", + "minor", + "service", + "track" + ] + ], + "layout": { + "symbol-placement": "line", + "text-field": "{name:latin} {name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-rotation-alignment": "map", + "text-size": { + "base": 1, + "stops": [ + [ + 15, + 10 + ], + [ + 16, + 11 + ], + [ + 17, + 12 + ], + [ + 19, + 14 + ] + ] + } + }, + "paint": { + "text-color": "#333333", + "text-halo-blur": 0, + "text-halo-width": 1.5, + "text-halo-color": "#ffffff" + } + }, + { + "id": "highway-name-major", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "transportation_name", + "minzoom": 12.2, + "filter": [ + "in", + "class", + "primary", + "secondary", + "tertiary", + "trunk" + ], + "layout": { + "symbol-placement": "line", + "text-field": "{name:latin} {name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-rotation-alignment": "map", + "text-size": { + "base": 1, + "stops": [ + [ + 12, + 10 + ], + [ + 14, + 11 + ], + [ + 16, + 12 + ], + [ + 17, + 13 + ], + [ + 19, + 15 + ] + ] + } + }, + "paint": { + "text-color": "#333333", + "text-halo-blur": 0, + "text-halo-width": 1.5, + "text-halo-color": "#ffffff" + } + }, + { + "id": "highway-shield", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "transportation_name", + "minzoom": 8, + "filter": [ + "all", + [ + "<=", + "ref_length", + 6 + ], + [ + "==", + "$type", + "LineString" + ], + [ + "!in", + "network", + "us-interstate", + "us-highway", + "us-state" + ] + ], + "layout": { + "icon-image": "road_{ref_length}", + "icon-rotation-alignment": "viewport", + "icon-size": 1, + "symbol-placement": { + "base": 1, + "stops": [ + [ + 10, + "point" + ], + [ + 11, + "line" + ] + ] + }, + "symbol-spacing": 200, + "text-field": "{ref}", + "text-font": [ + "Noto Sans Regular" + ], + "text-rotation-alignment": "viewport", + "text-size": 10 + }, + "paint": {} + }, + { + "id": "highway-shield-us-interstate", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "transportation_name", + "minzoom": 7, + "filter": [ + "all", + [ + "<=", + "ref_length", + 6 + ], + [ + "==", + "$type", + "LineString" + ], + [ + "in", + "network", + "us-interstate" + ] + ], + "layout": { + "icon-image": "{network}_{ref_length}", + "icon-rotation-alignment": "viewport", + "icon-size": 1, + "symbol-placement": { + "base": 1, + "stops": [ + [ + 7, + "point" + ], + [ + 7, + "line" + ], + [ + 8, + "line" + ] + ] + }, + "symbol-spacing": 200, + "text-field": "{ref}", + "text-font": [ + "Noto Sans Regular" + ], + "text-rotation-alignment": "viewport", + "text-size": 10 + }, + "paint": { + "text-color": "rgba(0, 0, 0, 1)" + } + }, + { + "id": "highway-shield-us-other", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "transportation_name", + "minzoom": 9, + "filter": [ + "all", + [ + "<=", + "ref_length", + 6 + ], + [ + "==", + "$type", + "LineString" + ], + [ + "in", + "network", + "us-highway", + "us-state" + ] + ], + "layout": { + "icon-image": "{network}_{ref_length}", + "icon-rotation-alignment": "viewport", + "icon-size": 1, + "symbol-placement": { + "base": 1, + "stops": [ + [ + 10, + "point" + ], + [ + 11, + "line" + ] + ] + }, + "symbol-spacing": 200, + "text-field": "{ref}", + "text-font": [ + "Noto Sans Regular" + ], + "text-rotation-alignment": "viewport", + "text-size": 10 + }, + "paint": { + "text-color": "rgba(0, 0, 0, 1)" + } + }, + { + "id": "airport-label-major", + "type": "symbol", + "source": "openmaptiles", + "source-layer": "aerodrome_label", + "minzoom": 10, + "filter": [ + "all", + [ + "has", + "iata" + ] + ], + "layout": { + "icon-image": "airport_11", + "icon-size": 1, + "text-anchor": "top", + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-max-width": 9, + "text-offset": [ + 0, + 0.6 + ], + "text-optional": true, + "text-padding": 2, + "text-size": 12, + "visibility": "visible" + }, + "paint": { + "text-color": "#666", + "text-halo-blur": 0.5, + "text-halo-color": "#ffffff", + "text-halo-width": 1 + } + }, + { + "id": "place-other", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "!in", + "class", + "city", + "town", + "village", + "state", + "country", + "continent" + ], + "layout": { + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Bold" + ], + "text-letter-spacing": 0.1, + "text-max-width": 9, + "text-size": { + "base": 1.2, + "stops": [ + [ + 12, + 10 + ], + [ + 15, + 14 + ] + ] + }, + "text-transform": "uppercase", + "visibility": "visible" + }, + "paint": { + "text-color": "#633", + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 1.2 + } + }, + { + "id": "place-village", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "==", + "class", + "village" + ], + "layout": { + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-max-width": 8, + "text-size": { + "base": 1.2, + "stops": [ + [ + 10, + 12 + ], + [ + 15, + 22 + ] + ] + }, + "visibility": "visible" + }, + "paint": { + "text-color": "#333", + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 1.2 + } + }, + { + "id": "place-town", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "==", + "class", + "town" + ], + "layout": { + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-max-width": 8, + "text-size": { + "base": 1.2, + "stops": [ + [ + 10, + 14 + ], + [ + 15, + 24 + ] + ] + }, + "visibility": "visible" + }, + "paint": { + "text-color": "#333", + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 1.2 + } + }, + { + "id": "place-city", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "all", + [ + "!=", + "capital", + 2 + ], + [ + "==", + "class", + "city" + ] + ], + "layout": { + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-max-width": 8, + "text-size": { + "base": 1.2, + "stops": [ + [ + 7, + 14 + ], + [ + 11, + 24 + ] + ] + }, + "visibility": "visible" + }, + "paint": { + "text-color": "#333", + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 1.2 + } + }, + { + "id": "place-city-capital", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "all", + [ + "==", + "capital", + 2 + ], + [ + "==", + "class", + "city" + ] + ], + "layout": { + "icon-image": "star_11", + "icon-size": 0.8, + "text-anchor": "left", + "text-field": "{name:latin}\n{name:nonlatin}", + "text-font": [ + "Noto Sans Regular" + ], + "text-max-width": 8, + "text-offset": [ + 0.4, + 0 + ], + "text-size": { + "base": 1.2, + "stops": [ + [ + 7, + 14 + ], + [ + 11, + 24 + ] + ] + }, + "visibility": "visible" + }, + "paint": { + "text-color": "#333", + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 1.2 + } + }, + { + "id": "place-state", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "in", + "class", + "state" + ], + "layout": { + "text-field": "{name:latin}", + "text-font": [ + "Noto Sans Bold" + ], + "text-letter-spacing": 0.1, + "text-max-width": 9, + "text-size": { + "base": 1.2, + "stops": [ + [ + 12, + 10 + ], + [ + 15, + 14 + ] + ] + }, + "text-transform": "uppercase", + "visibility": "visible" + }, + "paint": { + "text-color": "#633", + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 1.2 + } + }, + { + "id": "place-country-other", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "all", + [ + "==", + "class", + "country" + ], + [ + ">=", + "rank", + 3 + ], + [ + "!has", + "iso_a2" + ] + ], + "layout": { + "text-field": "{name:latin}", + "text-font": [ + "Noto Sans Italic" + ], + "text-max-width": 6.25, + "text-size": { + "stops": [ + [ + 3, + 11 + ], + [ + 7, + 17 + ] + ] + }, + "text-transform": "uppercase", + "visibility": "visible" + }, + "paint": { + "text-color": "#334", + "text-halo-blur": 1, + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 2 + } + }, + { + "id": "place-country-3", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "all", + [ + "==", + "class", + "country" + ], + [ + ">=", + "rank", + 3 + ], + [ + "has", + "iso_a2" + ] + ], + "layout": { + "text-field": "{name:latin}", + "text-font": [ + "Noto Sans Bold" + ], + "text-max-width": 6.25, + "text-size": { + "stops": [ + [ + 3, + 11 + ], + [ + 7, + 17 + ] + ] + }, + "text-transform": "uppercase", + "visibility": "visible" + }, + "paint": { + "text-color": "#334", + "text-halo-blur": 1, + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 2 + } + }, + { + "id": "place-country-2", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "all", + [ + "==", + "class", + "country" + ], + [ + "==", + "rank", + 2 + ], + [ + "has", + "iso_a2" + ] + ], + "layout": { + "text-field": "{name:latin}", + "text-font": [ + "Noto Sans Bold" + ], + "text-max-width": 6.25, + "text-size": { + "stops": [ + [ + 2, + 11 + ], + [ + 5, + 17 + ] + ] + }, + "text-transform": "uppercase", + "visibility": "visible" + }, + "paint": { + "text-color": "#334", + "text-halo-blur": 1, + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 2 + } + }, + { + "id": "place-country-1", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "filter": [ + "all", + [ + "==", + "class", + "country" + ], + [ + "==", + "rank", + 1 + ], + [ + "has", + "iso_a2" + ] + ], + "layout": { + "text-field": "{name:latin}", + "text-font": [ + "Noto Sans Bold" + ], + "text-max-width": 6.25, + "text-size": { + "stops": [ + [ + 1, + 11 + ], + [ + 4, + 17 + ] + ] + }, + "text-transform": "uppercase", + "visibility": "visible" + }, + "paint": { + "text-color": "#334", + "text-halo-blur": 1, + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 2 + } + }, + { + "id": "place-continent", + "type": "symbol", + "metadata": { + "mapbox:group": "1444849242106.713" + }, + "source": "openmaptiles", + "source-layer": "place", + "maxzoom": 1, + "filter": [ + "==", + "class", + "continent" + ], + "layout": { + "text-field": "{name:latin}", + "text-font": [ + "Noto Sans Bold" + ], + "text-max-width": 6.25, + "text-size": 14, + "text-transform": "uppercase", + "visibility": "visible" + }, + "paint": { + "text-color": "#334", + "text-halo-blur": 1, + "text-halo-color": "rgba(255,255,255,0.8)", + "text-halo-width": 2 + } + } + ] +} \ No newline at end of file diff --git a/pkg/vectormap/vectormap.go b/pkg/vectormap/vectormap.go new file mode 100644 index 0000000..91afce5 --- /dev/null +++ b/pkg/vectormap/vectormap.go @@ -0,0 +1,326 @@ +// Package vectormap publishes vector tiles based maps into cinode. +package vectormap + +import ( + "bytes" + "context" + "embed" + "encoding/json" + "errors" + "fmt" + "io/fs" + "log/slog" + "os" + "path/filepath" + "regexp" + "sort" + "strconv" + "sync" + "time" + + "github.com/cinode/go/pkg/cinodefs" + "github.com/cinode/go/pkg/cinodefs/uploader" + "github.com/cinode/go/pkg/datastore" +) + +//go:embed static_data/vector +var vectorStatic embed.FS + +// tilesDir is the directory with tiles inside the generated site +const tilesDir = "tiles" + +// TileMimeType is the mime type used for stored vector tiles +const TileMimeType = "application/vnd.mapbox-vector-tile" + +// Config is the configuration of the generated vector map +type Config struct { + // AssetsDir contains client-side assets that are copied as-is to the + // root of the generated site (maplibre/, fonts/, sprites/ ...) + AssetsDir string + + // TilesDirs are directories with vector tiles in {z}/{x}/{y}.pbf layout + // (e.g. Planetiler output with `format=files`). When the same tile exists + // in more than one directory, the one from the later directory wins. + // Tiles must not be gzip-compressed since cinode proxy does not set + // Content-Encoding header. + TilesDirs []string + + // Parallelism is the number of concurrent tile uploads + Parallelism int +} + +// Generate builds the whole vector map site: +// +// /index.html - MapLibre GL JS based viewer +// /overzoom.mjs - client-side over-zooming of missing tiles +// /style.json - map style +// /tiles/{z}/{x}/{y}.pbf - vector tiles +// /... - assets from AssetsDir +func Generate( + ctx context.Context, + log *slog.Logger, + cfg Config, + cfs cinodefs.FS, +) error { + if cfg.AssetsDir != "" { + log.InfoContext(ctx, "Uploading assets", "dir", cfg.AssetsDir) + err := uploader.UploadStaticDirectory(ctx, os.DirFS(cfg.AssetsDir), cfs) + if err != nil { + return fmt.Errorf("failed to upload assets: %w", err) + } + } + + staticFS, err := fs.Sub(vectorStatic, "static_data/vector") + if err != nil { + return err + } + if err := uploader.UploadStaticDirectory(ctx, staticFS, cfs); err != nil { + return fmt.Errorf("failed to upload viewer files: %w", err) + } + + return UploadTiles(ctx, log, cfg, cfs, []string{tilesDir}) +} + +type tileFile struct { + src string + z, x, y int +} + +var tileFileRE = regexp.MustCompile(`^(\d+)/(\d+)/(\d+)\.pbf$`) + +// TileRect is an inclusive range of tiles at a single zoom level: +// [minX, minY, maxX, maxY] +type TileRect [4]int + +// TilesCoverage describes which tiles exist, it is stored as +// tiles/coverage.json and used by the viewer to find the best tile to +// over-zoom without probing for missing tiles. Tiles inside rectangles may +// still be missing (e.g. empty tiles), the viewer handles that as well. +type TilesCoverage struct { + // Zooms maps zoom level to bounding rectangles of existing tiles, + // one rectangle per source tiles directory. + Zooms map[int][]TileRect `json:"zooms"` +} + +// collectTiles finds all tiles in given directories, later directories +// override tiles from earlier ones. Result is grouped by zoom level. +func collectTiles(dirs []string) (map[int][]tileFile, *TilesCoverage, error) { + type key struct{ z, x, y int } + all := map[key]string{} + coverage := &TilesCoverage{Zooms: map[int][]TileRect{}} + + for _, dir := range dirs { + dirRects := map[int]TileRect{} + err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { + if err != nil || d.IsDir() { + return err + } + rel, err := filepath.Rel(dir, path) + if err != nil { + return err + } + m := tileFileRE.FindStringSubmatch(filepath.ToSlash(rel)) + if m == nil { + // metadata.json and other non-tile files + return nil + } + z, _ := strconv.Atoi(m[1]) + x, _ := strconv.Atoi(m[2]) + y, _ := strconv.Atoi(m[3]) + all[key{z, x, y}] = path + + r, found := dirRects[z] + if !found { + r = TileRect{x, y, x, y} + } + dirRects[z] = TileRect{min(r[0], x), min(r[1], y), max(r[2], x), max(r[3], y)} + return nil + }) + if err != nil { + return nil, nil, fmt.Errorf("failed to scan tiles dir %s: %w", dir, err) + } + for z, r := range dirRects { + coverage.Zooms[z] = append(coverage.Zooms[z], r) + } + } + + ret := map[int][]tileFile{} + for k, src := range all { + ret[k.z] = append(ret[k.z], tileFile{src: src, z: k.z, x: k.x, y: k.y}) + } + for z := range ret { + sort.Slice(ret[z], func(i, j int) bool { + a, b := ret[z][i], ret[z][j] + if a.x != b.x { + return a.x < b.x + } + return a.y < b.y + }) + } + return ret, coverage, nil +} + +// UploadTiles uploads vector tiles from config's TilesDirs to +// the given path. The destination directory is reset first so that +// the result is always a snapshot of the source directories. +func UploadTiles( + ctx context.Context, + log *slog.Logger, + cfg Config, + cfs cinodefs.FS, + basePath []string, +) error { + tiles, coverage, err := collectTiles(cfg.TilesDirs) + if err != nil { + return err + } + + zooms := make([]int, 0, len(tiles)) + for z := range tiles { + zooms = append(zooms, z) + } + sort.Ints(zooms) + + if err := cfs.ResetDir(ctx, basePath); err != nil { + return err + } + + coverageJSON, err := json.Marshal(coverage) + if err != nil { + return err + } + _, err = cfs.SetEntryFile(ctx, + append(append([]string{}, basePath...), "coverage.json"), + bytes.NewReader(coverageJSON), + ) + if err != nil { + return fmt.Errorf("failed to upload tiles coverage: %w", err) + } + + parallelism := max(cfg.Parallelism, 1) + + for _, z := range zooms { + zLog := log.With("z", z) + zLog.InfoContext(ctx, "Uploading zoom level", "tiles", len(tiles[z])) + + if err := uploadTilesParallel(ctx, zLog, cfs, basePath, tiles[z], parallelism); err != nil { + return err + } + + // Persist each finished zoom level to limit memory usage + if err := cfs.Flush(ctx); err != nil { + return err + } + } + + return nil +} + +func uploadTilesParallel( + ctx context.Context, + log *slog.Logger, + cfs cinodefs.FS, + basePath []string, + tiles []tileFile, + parallelism int, +) error { + ctx, cancel := context.WithCancelCause(ctx) + defer cancel(nil) + + type result struct { + ep *cinodefs.Entrypoint + t tileFile + } + + jobs := make(chan tileFile) + results := make(chan result) + + // Blob creation is independent of the directory tree and can run + // concurrently, modifying the tree is done in a single goroutine below. + wg := sync.WaitGroup{} + for range parallelism { + wg.Go(func() { + for t := range jobs { + ep, err := uploadTileBlob(ctx, cfs, t) + if err != nil { + cancel(err) + return + } + select { + case results <- result{ep: ep, t: t}: + case <-ctx.Done(): + return + } + } + }) + } + + go func() { + defer close(jobs) + for _, t := range tiles { + select { + case jobs <- t: + case <-ctx.Done(): + return + } + } + }() + + go func() { + wg.Wait() + close(results) + }() + + done := 0 + for r := range results { + path := append( + append([]string{}, basePath...), + strconv.Itoa(r.t.z), strconv.Itoa(r.t.x), strconv.Itoa(r.t.y)+".pbf", + ) + if err := cfs.SetEntry(ctx, path, r.ep); err != nil { + cancel(err) + break + } + done++ + if done%1000 == 0 { + log.InfoContext(ctx, "Upload progress", "done", done, "total", len(tiles)) + } + } + + // drain in case of an early exit + for range results { + } + + return context.Cause(ctx) +} + +func uploadTileBlob(ctx context.Context, cfs cinodefs.FS, t tileFile) (*cinodefs.Entrypoint, error) { + data, err := os.ReadFile(t.src) + if err != nil { + return nil, err + } + if len(data) >= 2 && data[0] == 0x1f && data[1] == 0x8b { + return nil, fmt.Errorf( + "tile %s is gzip-compressed, generate tiles without compression"+ + " (e.g. planetiler --tile_compression=none)", t.src, + ) + } + + // Blob names are content-addressed so identical tiles (e.g. water-only + // ones) map to the same blob. When such tiles are uploaded concurrently, + // the datastore rejects all but one writer - retry, by then the blob + // is usually already in place. + delay := 10 * time.Millisecond + for retry := 0; ; retry++ { + ep, err := cfs.CreateFileEntrypoint(ctx, bytes.NewReader(data), cinodefs.SetMimeType(TileMimeType)) + if !errors.Is(err, datastore.ErrUploadInProgress) || retry >= 20 { + return ep, err + } + select { + case <-time.After(delay): + case <-ctx.Done(): + return nil, ctx.Err() + } + delay = min(2*delay, time.Second) + } +} diff --git a/pkg/vectormap/vectormap_test.go b/pkg/vectormap/vectormap_test.go new file mode 100644 index 0000000..bbf68ad --- /dev/null +++ b/pkg/vectormap/vectormap_test.go @@ -0,0 +1,126 @@ +package vectormap + +import ( + "context" + "fmt" + "io" + "log/slog" + "os" + "path/filepath" + "testing" + + "github.com/cinode/go/pkg/blenc" + "github.com/cinode/go/pkg/cinodefs" + "github.com/cinode/go/pkg/datastore" + "github.com/stretchr/testify/require" +) + +func testLog() *slog.Logger { + return slog.New(slog.NewTextHandler(io.Discard, nil)) +} + +// writeFile creates a file at a slash-separated path relative to dir +func writeFile(t *testing.T, dir, relPath, data string) { + t.Helper() + path := filepath.Join(dir, filepath.FromSlash(relPath)) + require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) + require.NoError(t, os.WriteFile(path, []byte(data), 0o644)) +} + +func TestGenerate(t *testing.T) { + ctx := context.Background() + + world := t.TempDir() + region := t.TempDir() + assets := t.TempDir() + + writeFile(t, world, "0/0/0.pbf", "world-0") + writeFile(t, world, "1/0/1.pbf", "world-1") + writeFile(t, world, "metadata.json", "{}") + writeFile(t, region, "1/0/1.pbf", "region-1") + writeFile(t, region, "2/1/1.pbf", "region-2") + writeFile(t, assets, "maplibre/maplibre-gl.mjs", "js") + writeFile(t, assets, "fonts/Noto Sans Regular/0-255.pbf", "glyphs") + + be := blenc.FromDatastore(datastore.InMemory()) + fs, err := cinodefs.New(ctx, be, cinodefs.NewRootStaticDirectory()) + require.NoError(t, err) + + err = Generate(ctx, testLog(), Config{ + TilesDirs: []string{world, region}, + AssetsDir: assets, + Parallelism: 4, + }, fs) + require.NoError(t, err) + require.NoError(t, fs.Flush(ctx)) + + read := func(path ...string) string { + rc, err := fs.OpenEntryData(ctx, path) + require.NoError(t, err) + defer func() { require.NoError(t, rc.Close()) }() + data, err := io.ReadAll(rc) + require.NoError(t, err) + return string(data) + } + + require.Equal(t, "world-0", read("tiles", "0", "0", "0.pbf")) + require.Equal(t, "region-1", read("tiles", "1", "0", "1.pbf"), "later dir must override") + require.Equal(t, "region-2", read("tiles", "2", "1", "1.pbf")) + require.Equal(t, "js", read("maplibre", "maplibre-gl.mjs")) + require.Equal(t, "glyphs", read("fonts", "Noto Sans Regular", "0-255.pbf")) + require.Contains(t, read("index.html"), "maplibre-gl.mjs") + require.Contains(t, read("style.json"), "tiles/{z}/{x}/{y}.pbf") + + require.JSONEq(t, + `{"zooms":{"0":[[0,0,0,0]],"1":[[0,1,0,1],[0,1,0,1]],"2":[[1,1,1,1]]}}`, + read("tiles", "coverage.json"), + ) + + _, err = fs.FindEntry(ctx, []string{"tiles", "metadata.json"}) + require.ErrorIs(t, err, cinodefs.ErrEntryNotFound) + + ep, err := fs.FindEntry(ctx, []string{"tiles", "0", "0", "0.pbf"}) + require.NoError(t, err) + require.Equal(t, TileMimeType, ep.MimeType()) +} + +func TestGenerateRejectsGzipTiles(t *testing.T) { + ctx := context.Background() + dir := t.TempDir() + writeFile(t, dir, "0/0/0.pbf", "\x1f\x8bgzipped") + + be := blenc.FromDatastore(datastore.InMemory()) + fs, err := cinodefs.New(ctx, be, cinodefs.NewRootStaticDirectory()) + require.NoError(t, err) + + err = Generate(ctx, testLog(), Config{TilesDirs: []string{dir}}, fs) + require.ErrorContains(t, err, "gzip") +} + +func TestGenerateDuplicateTilesInParallel(t *testing.T) { + ctx := context.Background() + dir := t.TempDir() + for x := range 16 { + for y := range 16 { + writeFile(t, dir, fmt.Sprintf("4/%d/%d.pbf", x, y), "ocean") + } + } + + be := blenc.FromDatastore(datastore.InMemory()) + fs, err := cinodefs.New(ctx, be, cinodefs.NewRootStaticDirectory()) + require.NoError(t, err) + + err = Generate(ctx, testLog(), Config{ + TilesDirs: []string{dir}, + Parallelism: 16, + }, fs) + require.NoError(t, err) + require.NoError(t, fs.Flush(ctx)) + + rc, err := fs.OpenEntryData(ctx, []string{"tiles", "4", "15", "15.pbf"}) + require.NoError(t, err) + defer func() { require.NoError(t, rc.Close()) }() + data, err := io.ReadAll(rc) + require.NoError(t, err) + require.Equal(t, "ocean", string(data)) +} diff --git a/toolbox/fetch-vector-assets.sh b/toolbox/fetch-vector-assets.sh new file mode 100755 index 0000000..b859faa --- /dev/null +++ b/toolbox/fetch-vector-assets.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# Prepares the client-side assets directory for `maps-vector-uploader` (CINODE_VECTOR_ASSETS_DIR): +# +# /maplibre/ - MapLibre GL JS (ESM build + worker + css) +# /fonts/ - glyph PBFs used by the style (Noto Sans) +# /sprites/ - OSM Bright sprites +# +# Usage: toolbox/fetch-vector-assets.sh +set -euo pipefail + +MAPLIBRE_VERSION="6.16.0" +OSM_BRIGHT_VERSION="v1.11" +FONTS_VERSION="v2.0" + +OUT="${1:?usage: $0 }" +mkdir -p "$OUT" +OUT="$(cd "$OUT" && pwd)" + +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP"' EXIT + +echo "Fetching MapLibre GL JS ${MAPLIBRE_VERSION}" +mkdir -p "$TMP/maplibre" "$OUT/maplibre" +(cd "$TMP/maplibre" && npm pack --silent "maplibre-gl@${MAPLIBRE_VERSION}" >/dev/null && tar xzf ./*.tgz) +for f in maplibre-gl.mjs maplibre-gl-worker.mjs maplibre-gl-shared.mjs maplibre-gl.css; do + cp "$TMP/maplibre/package/dist/$f" "$OUT/maplibre/" +done +cp "$TMP/maplibre/package/LICENSE.txt" "$OUT/maplibre/" + +echo "Fetching OSM Bright ${OSM_BRIGHT_VERSION} sprites" +mkdir -p "$TMP/osm-bright" "$OUT/sprites" +curl -sSfL -o "$TMP/osm-bright.zip" \ + "https://github.com/openmaptiles/osm-bright-gl-style/releases/download/${OSM_BRIGHT_VERSION}/${OSM_BRIGHT_VERSION}.zip" +unzip -q -o "$TMP/osm-bright.zip" -d "$TMP/osm-bright" +cp "$TMP/osm-bright"/sprite*.{json,png} "$OUT/sprites/" + +echo "Fetching Noto Sans fonts ${FONTS_VERSION}" +mkdir -p "$TMP/fonts" "$OUT/fonts" +curl -sSfL -o "$TMP/noto-sans.zip" \ + "https://github.com/openmaptiles/fonts/releases/download/${FONTS_VERSION}/noto-sans.zip" +unzip -q -o "$TMP/noto-sans.zip" -d "$TMP/fonts" +for font in "Noto Sans Regular" "Noto Sans Bold" "Noto Sans Italic"; do + rm -rf "${OUT:?}/fonts/$font" + cp -r "$TMP/fonts/$font" "$OUT/fonts/" +done + +echo "Assets ready in $OUT" From 466220cb55e0b632d6721836e8706e19e04cc00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20=C5=9Awi=C4=99cki?= Date: Wed, 18 Nov 2026 21:57:50 +0100 Subject: [PATCH 2/5] Add vector map docker images * maps-vector-uploader - the uploader with viewer assets bundled at build time (CINODE_VECTOR_ASSETS_DIR points to them by default), * maps-vector-generator - the whole vector map pipeline in one image: Planetiler (the base image), osmium, the uploader with assets and scripts run as a plain sequence of commands: - prepare-osm-extract downloads extracts and polygons of regions (with retries) and merges them with osmium, skipping the merge when nothing has changed; tiles along borders of neighbouring regions then contain data of all of them, - generate-vector-tiles runs Planetiler for a local extract. The generator is built for linux/amd64 and linux/arm64 only since those are the only platforms of the Planetiler image. Co-Authored-By: Claude Opus 5.5 --- .dockerignore | 3 + .github/workflows/images.yml | 5 + build/docker/Dockerfile.maps-vector-generator | 59 +++++++++++ build/docker/Dockerfile.maps-vector-uploader | 52 ++++++++++ toolbox/generate-vector-tiles.sh | 47 +++++++++ toolbox/prepare-osm-extract.sh | 98 +++++++++++++++++++ 6 files changed, 264 insertions(+) create mode 100644 build/docker/Dockerfile.maps-vector-generator create mode 100644 build/docker/Dockerfile.maps-vector-uploader create mode 100755 toolbox/generate-vector-tiles.sh create mode 100755 toolbox/prepare-osm-extract.sh diff --git a/.dockerignore b/.dockerignore index 86a05f8..28180ae 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,9 @@ deploy/ build/ helm/ toolbox/ +!toolbox/fetch-vector-assets.sh +!toolbox/generate-vector-tiles.sh +!toolbox/prepare-osm-extract.sh .git/ .github/ .vscode/ diff --git a/.github/workflows/images.yml b/.github/workflows/images.yml index 2e59595..ea9eae2 100644 --- a/.github/workflows/images.yml +++ b/.github/workflows/images.yml @@ -28,6 +28,11 @@ jobs: app: - name: maps-tile-uploader platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/riscv64 + - name: maps-vector-uploader + platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/riscv64 + # Based on the Planetiler image which is only available for those platforms + - name: maps-vector-generator + platforms: linux/amd64,linux/arm64 - name: maps-tile-server platforms: linux/amd64,linux/arm64 env: diff --git a/build/docker/Dockerfile.maps-vector-generator b/build/docker/Dockerfile.maps-vector-generator new file mode 100644 index 0000000..1adbc98 --- /dev/null +++ b/build/docker/Dockerfile.maps-vector-generator @@ -0,0 +1,59 @@ +# syntax=docker/dockerfile:1 +# Complete vector map pipeline in one image: Planetiler generating the tiles, +# maps-vector-uploader with the viewer assets publishing them to cinode +ARG GO_VERSION=1.27 + +# Base image with go compiler and tested source code +FROM --platform=$BUILDPLATFORM docker.io/library/golang:${GO_VERSION} AS build + +# Compile and test with non-root user +RUN useradd -ms /bin/bash go +USER go +RUN git config --global --add safe.directory /home/go/app + +# Fetch and verify dependencies +WORKDIR /home/go/app +COPY go.mod go.sum ./ +RUN go mod download -x +RUN go mod verify + +# Bring in and test the source code +COPY . . + +# Build binary +ENV CGO_ENABLED=0 +ARG TARGETOS TARGETARCH TARGETVARIANT +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} \ + go build \ + -v \ + -ldflags="-w -s" \ + -o "/home/go/maps-vector-uploader" \ + "./cmd/maps-vector-uploader" + +# Client-side assets of the map viewer (MapLibre GL JS, fonts, sprites), +# they are platform-independent so are fetched once on the build platform +FROM --platform=$BUILDPLATFORM docker.io/library/node:22-bookworm AS assets +RUN apt-get update \ + && apt-get install -y --no-install-recommends unzip \ + && rm -rf /var/lib/apt/lists/* +COPY toolbox/fetch-vector-assets.sh /usr/local/bin/fetch-vector-assets.sh +RUN fetch-vector-assets.sh /assets + +FROM ghcr.io/onthegomap/planetiler:0.10.2 +# osmium merges OSM extracts of neighbouring regions +RUN apt-get update \ + && apt-get install -y --no-install-recommends osmium-tool \ + && rm -rf /var/lib/apt/lists/* +COPY --from=build /home/go/maps-vector-uploader /usr/local/bin/maps-vector-uploader +COPY --from=assets /assets /usr/share/maps-vector-uploader/assets +COPY --chmod=755 toolbox/prepare-osm-extract.sh /usr/local/bin/prepare-osm-extract +COPY --chmod=755 toolbox/generate-vector-tiles.sh /usr/local/bin/generate-vector-tiles +ENV CINODE_VECTOR_ASSETS_DIR=/usr/share/maps-vector-uploader/assets +# Generated files are owned by the default non-root user +USER ubuntu:ubuntu +# Steps are run as commands, e.g.: +# prepare-osm-extract [ ...] +# generate-vector-tiles [planetiler args...] +# maps-vector-uploader +ENTRYPOINT [] +CMD [ "/bin/bash" ] diff --git a/build/docker/Dockerfile.maps-vector-uploader b/build/docker/Dockerfile.maps-vector-uploader new file mode 100644 index 0000000..79d3e7b --- /dev/null +++ b/build/docker/Dockerfile.maps-vector-uploader @@ -0,0 +1,52 @@ +# syntax=docker/dockerfile:1 +ARG GO_VERSION=1.27 + +# Base image with go compiler and tested source code +FROM --platform=$BUILDPLATFORM docker.io/library/golang:${GO_VERSION} AS build + +# Compile and test with non-root user +RUN useradd -ms /bin/bash go +USER go +RUN git config --global --add safe.directory /home/go/app + +# Fetch and verify dependencies +WORKDIR /home/go/app +COPY go.mod go.sum ./ +RUN go mod download -x +RUN go mod verify + +# Bring in and test the source code +COPY . . +# RUN go vet -v ./... +# RUN go test -v ./... + +# Build binary +ENV CGO_ENABLED=0 +ARG TARGETOS TARGETARCH TARGETVARIANT APP_NAME +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} \ + go build \ + -v \ + -ldflags="-w -s" \ + -o "/home/go/maps-vector-uploader" \ + "./cmd/maps-vector-uploader" + +# Client-side assets of the map viewer (MapLibre GL JS, fonts, sprites), +# they are platform-independent so are fetched once on the build platform +FROM --platform=$BUILDPLATFORM docker.io/library/node:22-bookworm AS assets +RUN apt-get update \ + && apt-get install -y --no-install-recommends unzip \ + && rm -rf /var/lib/apt/lists/* +COPY toolbox/fetch-vector-assets.sh /usr/local/bin/fetch-vector-assets.sh +RUN fetch-vector-assets.sh /assets + +# Force distroless base to use current platform (most likely linux/amd64) +# which is needed since distroless/static is not available for linux/arm/v6 +FROM --platform=$BUILDPLATFORM gcr.io/distroless/static AS distroless + +FROM scratch +COPY --from=distroless / / +COPY --from=build /home/go/maps-vector-uploader /usr/sbin/maps-vector-uploader +COPY --from=assets /assets /usr/share/maps-vector-uploader/assets +ENV CINODE_VECTOR_ASSETS_DIR=/usr/share/maps-vector-uploader/assets +USER nonroot:nonroot +ENTRYPOINT [ "/usr/sbin/maps-vector-uploader" ] diff --git a/toolbox/generate-vector-tiles.sh b/toolbox/generate-vector-tiles.sh new file mode 100755 index 0000000..4a6f51c --- /dev/null +++ b/toolbox/generate-vector-tiles.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# Generates vector tiles from an OSM extract with Planetiler +# +# Usage: generate-vector-tiles.sh [planetiler args...] +# +# Tiles are written to $DATA_DIR/tiles/ (DATA_DIR defaults to /data), +# previous tiles are replaced only after a successful run. Additional sources +# (water polygons, Natural Earth) are downloaded to $DATA_DIR/sources once. +# +# Planetiler is started with PLANETILER (defaults to the launcher of the +# maps-vector-generator image), java options can be set with JAVA_TOOL_OPTIONS. +set -euo pipefail + +if [ $# -lt 4 ]; then + sed -n '2,/^set /{/^#/s/^# \{0,1\}//p}' "$0" >&2 + exit 1 +fi + +NAME="$1" +OSM_FILE="$2" +MIN_ZOOM="$3" +MAX_ZOOM="$4" +shift 4 + +DATA="${DATA_DIR:-/data}" +OUT="$DATA/tiles/$NAME" +TMP="$DATA/tmp/$NAME" +read -r -a PLANETILER <<<"${PLANETILER:-java -cp @/app/jib-classpath-file com.onthegomap.planetiler.Main}" + +mkdir -p "$DATA/sources" "$DATA/tiles" "$DATA/tmp" + +echo "Generating tiles '$NAME' (z$MIN_ZOOM-z$MAX_ZOOM)" +rm -rf "$OUT.new" "$TMP" +"${PLANETILER[@]}" \ + --osm_path="$OSM_FILE" \ + --download \ + --download_dir="$DATA/sources" \ + --tmpdir="$TMP" \ + --output="$OUT.new?format=files" \ + --tile_compression=none \ + --minzoom="$MIN_ZOOM" \ + --maxzoom="$MAX_ZOOM" \ + "$@" + +rm -rf "$OUT" "$TMP" +mv "$OUT.new" "$OUT" +echo "Tiles '$NAME' ready" diff --git a/toolbox/prepare-osm-extract.sh b/toolbox/prepare-osm-extract.sh new file mode 100755 index 0000000..3467c8a --- /dev/null +++ b/toolbox/prepare-osm-extract.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# Downloads OSM extracts of regions and combines them into a single extract +# +# Usage: prepare-osm-extract.sh [ ...] +# +# Each region is given by its OSM extract (.osm.pbf) and the polygon of its +# area (.poly), e.g. from https://download.geofabrik.de/. The result is +# written to $DATA_DIR/osm/.osm.pbf and $DATA_DIR/osm/.poly +# (DATA_DIR defaults to /data). +# +# Extracts of neighbouring regions overlap a bit along shared borders, they +# are merged with osmium which keeps a single copy of every OSM object, so +# that tiles along borders contain data of all regions. Polygons are merged +# into a single multi-polygon. +# +# Downloaded files are kept in $DATA_DIR/osm and only fetched again when a +# newer version is published, the merge is skipped if nothing has changed. +set -euo pipefail + +if [ $# -lt 3 ] || [ $(( ($# - 1) % 2 )) -ne 0 ]; then + sed -n '2,/^set /{/^#/s/^# \{0,1\}//p}' "$0" >&2 + exit 1 +fi + +NAME="$1" +shift + +DATA="${DATA_DIR:-/data}" +OSM="$DATA/osm" +OUT_PBF="$OSM/$NAME.osm.pbf" +OUT_POLY="$OSM/$NAME.poly" +STAMP="$OSM/$NAME.inputs" + +mkdir -p "$OSM" + +fetch() { + echo "Fetching $1" + # Download servers (e.g. Geofabrik mirrors) occasionally refuse connections + # or drop them, retry instead of failing the whole run + (cd "$OSM" && wget --no-verbose --timestamping \ + --tries=5 --retry-connrefused --waitretry=30 "$1") +} + +PBFS=() +POLYS=() +while [ $# -gt 0 ]; do + fetch "$1" + fetch "$2" + PBFS+=("$OSM/$(basename "$1")") + POLYS+=("$OSM/$(basename "$2")") + shift 2 +done + +# Inputs with their versions, the merge is redone when any of them changes +inputs() { + stat -c '%n %s %Y' "${PBFS[@]}" "${POLYS[@]}" +} + +if [ -e "$OUT_PBF" ] && [ -e "$OUT_POLY" ] && [ -f "$STAMP" ] && inputs | cmp -s - "$STAMP"; then + echo "Extract '$NAME' is up to date" + exit 0 +fi + +rm -f "$STAMP" +if [ ${#PBFS[@]} -eq 1 ]; then + ln -sfn "$(basename "${PBFS[0]}")" "$OUT_PBF" +else + echo "Merging ${#PBFS[@]} extracts into '$NAME'" + osmium merge --overwrite --no-progress -o "$OUT_PBF.tmp" -f pbf "${PBFS[@]}" + mv -f "$OUT_PBF.tmp" "$OUT_PBF" +fi + +# Sections of all polygons in one file, renamed so that names are unique, +# holes (sections starting with '!') stay holes +{ + echo "$NAME" + i=0 + for poly in "${POLYS[@]}"; do + i=$((i + 1)) + awk -v prefix="$i-" ' + NR == 1 { next } # polygon name + !in_section && $1 == "END" { next } # end of the file + !in_section { + hole = substr($1, 1, 1) == "!" + print (hole ? "!" prefix substr($1, 2) : prefix $1) + in_section = 1 + next + } + $1 == "END" { in_section = 0 } + { print } + ' "$poly" + done + echo "END" +} > "$OUT_POLY.tmp" +mv -f "$OUT_POLY.tmp" "$OUT_POLY" + +inputs > "$STAMP" +echo "Extract '$NAME' ready" From 32b5f6e7cdae1df83e39307306c3cc0dbdf719db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20=C5=9Awi=C4=99cki?= Date: Wed, 18 Nov 2026 21:57:50 +0100 Subject: [PATCH 3/5] helm: add mapType switch between raster and vector maps All current resources belong to the raster map pipeline and are only rendered with mapType=raster (the default, so existing deployments are not affected). PostgreSQL is now an optional dependency (postgres.enabled) since the vector map doesn't need it; the chart fails with a clear message if it's left enabled for the vector map. Co-Authored-By: Claude Opus 5.5 --- helm/osm-machinery/Chart.lock | 4 ++-- helm/osm-machinery/Chart.yaml | 1 + helm/osm-machinery/templates/_helpers.tpl | 16 +++++++++++++++- .../cinode-upload-config-configmap.yaml | 2 ++ .../templates/cinode-upload-config-secrets.yaml | 2 ++ .../templates/cinode-upload-cronjob.yaml | 2 ++ helm/osm-machinery/templates/postgresql-pv.yaml | 2 ++ .../templates/tile-server-deployment.yaml | 2 ++ .../templates/tile-server-ingress.yaml | 2 ++ helm/osm-machinery/templates/tile-server-pv.yaml | 2 ++ .../osm-machinery/templates/tile-server-pvc.yaml | 2 ++ .../templates/tile-server-scripts-configmap.yaml | 2 ++ .../osm-machinery/templates/tile-server-svc.yaml | 2 ++ .../templates/tile-server-sync-cronjob.yaml | 2 ++ helm/osm-machinery/values.yaml | 10 ++++++++++ 15 files changed, 50 insertions(+), 3 deletions(-) diff --git a/helm/osm-machinery/Chart.lock b/helm/osm-machinery/Chart.lock index 10123d4..24b84fa 100644 --- a/helm/osm-machinery/Chart.lock +++ b/helm/osm-machinery/Chart.lock @@ -2,5 +2,5 @@ dependencies: - name: postgresql repository: https://charts.bitnami.com/bitnami version: 18.12.20 -digest: sha256:477ebd3d918850bf767b8ad6dd0fc48ba5a13f872fb436fa377ffcc4218bbdb3 -generated: "2026-11-18T10:54:29.069789046+01:00" +digest: sha256:48918387ca41774379c15c8440edde946da59bdb4d4ec8b3c0191cda066fc27d +generated: "2026-11-18T17:00:25.897520146+01:00" diff --git a/helm/osm-machinery/Chart.yaml b/helm/osm-machinery/Chart.yaml index ee6c40b..91e58e7 100644 --- a/helm/osm-machinery/Chart.yaml +++ b/helm/osm-machinery/Chart.yaml @@ -25,3 +25,4 @@ dependencies: version: "^18" repository: "https://charts.bitnami.com/bitnami" alias: postgres + condition: postgres.enabled diff --git a/helm/osm-machinery/templates/_helpers.tpl b/helm/osm-machinery/templates/_helpers.tpl index 2e27d36..4e5fb58 100644 --- a/helm/osm-machinery/templates/_helpers.tpl +++ b/helm/osm-machinery/templates/_helpers.tpl @@ -22,4 +22,18 @@ Settings of the selected import tuning profile (global.importTuning) as JSON {{- fail (printf "unknown global.importTuning.profile '%s', available profiles: %s" $t.profile (keys $t.profiles | sortAlpha | join ", ")) }} {{- end }} {{- $p | toJson }} -{{- end }} \ No newline at end of file +{{- end }} + +{{/* +Validated type of the generated map: "raster" or "vector" +*/}} +{{- define "osm-machinery.mapType" }} +{{- $mapType := $.Values.mapType | default "raster" }} +{{- if not (has $mapType (list "raster" "vector")) }} +{{- fail (printf "mapType must be either 'raster' or 'vector', got '%s'" $mapType) }} +{{- end }} +{{- if and (eq $mapType "vector") $.Values.postgres.enabled }} +{{- fail "mapType 'vector' does not use PostgreSQL, set postgres.enabled=false" }} +{{- end }} +{{- $mapType }} +{{- end }} diff --git a/helm/osm-machinery/templates/cinode-upload-config-configmap.yaml b/helm/osm-machinery/templates/cinode-upload-config-configmap.yaml index 3f491c7..c9a282d 100644 --- a/helm/osm-machinery/templates/cinode-upload-config-configmap.yaml +++ b/helm/osm-machinery/templates/cinode-upload-config-configmap.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} apiVersion: v1 kind: ConfigMap metadata: @@ -22,3 +23,4 @@ data: maxZoom: {{ .maxZoom | default $.Values.cinodeUpload.defaultRegionMaxZoom }} {{- end }} {{- end }} +{{- end }} diff --git a/helm/osm-machinery/templates/cinode-upload-config-secrets.yaml b/helm/osm-machinery/templates/cinode-upload-config-secrets.yaml index 08b45c0..70f5e95 100644 --- a/helm/osm-machinery/templates/cinode-upload-config-secrets.yaml +++ b/helm/osm-machinery/templates/cinode-upload-config-secrets.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} {{- $dsSetSecret := not $.Values.cinodeUpload.datastore.existingSecret | and ( not ( empty $.Values.cinodeUpload.datastore.value ) ) | ternary @@ -42,3 +43,4 @@ type: Opaque data: {{ $.Values.cinodeUpload.writerInfo.secretKey | quote }}: {{ $.Values.cinodeUpload.writerInfo.value | b64enc | quote }} {{- end }} +{{- end }} diff --git a/helm/osm-machinery/templates/cinode-upload-cronjob.yaml b/helm/osm-machinery/templates/cinode-upload-cronjob.yaml index c4d2500..a617433 100644 --- a/helm/osm-machinery/templates/cinode-upload-cronjob.yaml +++ b/helm/osm-machinery/templates/cinode-upload-cronjob.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} {{- if $.Values.cinodeUpload.enabled -}} --- apiVersion: batch/v1 @@ -91,3 +92,4 @@ spec: - name: tmp emptyDir: {} {{- end -}} +{{- end }} diff --git a/helm/osm-machinery/templates/postgresql-pv.yaml b/helm/osm-machinery/templates/postgresql-pv.yaml index 6134819..0778db1 100644 --- a/helm/osm-machinery/templates/postgresql-pv.yaml +++ b/helm/osm-machinery/templates/postgresql-pv.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} {{- if $.Values.postgres.primary.persistence.hostPath | default false }} --- apiVersion: v1 @@ -22,3 +23,4 @@ spec: hostPath: path: {{ $.Values.postgres.primary.persistence.hostPath | quote }} {{- end }} +{{- end }} diff --git a/helm/osm-machinery/templates/tile-server-deployment.yaml b/helm/osm-machinery/templates/tile-server-deployment.yaml index badeca0..34fe7ae 100644 --- a/helm/osm-machinery/templates/tile-server-deployment.yaml +++ b/helm/osm-machinery/templates/tile-server-deployment.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} {{- if $.Values.tileServer.webServer.enabled }} {{- $scripts := list "expire-server.py" "tile-server-entrypoint.sh" -}} --- @@ -92,3 +93,4 @@ spec: path: {{ $s | quote }} {{- end }} {{- end }} +{{- end }} diff --git a/helm/osm-machinery/templates/tile-server-ingress.yaml b/helm/osm-machinery/templates/tile-server-ingress.yaml index 9c09b35..93a2441 100644 --- a/helm/osm-machinery/templates/tile-server-ingress.yaml +++ b/helm/osm-machinery/templates/tile-server-ingress.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} {{- if $.Values.tileServer.webServer.ingress.enabled }} --- apiVersion: networking.k8s.io/v1 @@ -22,3 +23,4 @@ spec: name: http {{- end }} {{- end }} +{{- end }} diff --git a/helm/osm-machinery/templates/tile-server-pv.yaml b/helm/osm-machinery/templates/tile-server-pv.yaml index 3fd272a..7874300 100644 --- a/helm/osm-machinery/templates/tile-server-pv.yaml +++ b/helm/osm-machinery/templates/tile-server-pv.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} {{- if $.Values.tileServer.persistence.hostPath | default false }} --- apiVersion: v1 @@ -14,3 +15,4 @@ spec: hostPath: path: {{ $.Values.tileServer.persistence.hostPath | quote }} {{- end }} +{{- end }} diff --git a/helm/osm-machinery/templates/tile-server-pvc.yaml b/helm/osm-machinery/templates/tile-server-pvc.yaml index 48f091c..717b020 100644 --- a/helm/osm-machinery/templates/tile-server-pvc.yaml +++ b/helm/osm-machinery/templates/tile-server-pvc.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} --- apiVersion: v1 kind: PersistentVolumeClaim @@ -11,3 +12,4 @@ spec: resources: requests: storage: {{ $.Values.tileServer.persistence.size | quote }} +{{- end }} diff --git a/helm/osm-machinery/templates/tile-server-scripts-configmap.yaml b/helm/osm-machinery/templates/tile-server-scripts-configmap.yaml index 4a8b42c..3cb23bc 100644 --- a/helm/osm-machinery/templates/tile-server-scripts-configmap.yaml +++ b/helm/osm-machinery/templates/tile-server-scripts-configmap.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} apiVersion: v1 kind: ConfigMap metadata: @@ -7,3 +8,4 @@ data: {{ base $path }}: | {{- tpl ($.Files.Get $path) $ | nindent 4 }} {{- end }} +{{- end }} diff --git a/helm/osm-machinery/templates/tile-server-svc.yaml b/helm/osm-machinery/templates/tile-server-svc.yaml index 4b3e46b..b1956a2 100644 --- a/helm/osm-machinery/templates/tile-server-svc.yaml +++ b/helm/osm-machinery/templates/tile-server-svc.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} --- apiVersion: v1 kind: Service @@ -15,3 +16,4 @@ spec: port: 8642 targetPort: 8642 name: expiry +{{- end }} diff --git a/helm/osm-machinery/templates/tile-server-sync-cronjob.yaml b/helm/osm-machinery/templates/tile-server-sync-cronjob.yaml index 51be285..fc3c343 100644 --- a/helm/osm-machinery/templates/tile-server-sync-cronjob.yaml +++ b/helm/osm-machinery/templates/tile-server-sync-cronjob.yaml @@ -1,3 +1,4 @@ +{{- if eq (include "osm-machinery.mapType" $) "raster" }} {{- if $.Values.tileServer.syncJob.enabled -}} {{- $scripts := list "tile-server-sync-cronjob-entrypoint.sh" -}} --- @@ -79,3 +80,4 @@ spec: # Do not restart failed jobs - we will reschedule quickly anyway restartPolicy: Never {{- end -}} +{{- end }} diff --git a/helm/osm-machinery/values.yaml b/helm/osm-machinery/values.yaml index 55f7b8c..2eb6a21 100644 --- a/helm/osm-machinery/values.yaml +++ b/helm/osm-machinery/values.yaml @@ -74,7 +74,17 @@ global: wal_level: minimal max_wal_senders: 0 +# Type of the generated map: +# * raster - PNG tiles rendered by the tile server from OSM data imported +# into PostgreSQL, uploaded to cinode by cinodeUpload +# * vector - vector tiles generated with Planetiler, see vectorMap, +# requires postgres.enabled=false +mapType: raster + postgres: + # PostgreSQL is only used by the raster map + enabled: true + # Bitnami publishes free images only with the rolling "latest" tag, the # image is pinned by digest to a known PostgreSQL / PostGIS version, it # has to be updated manually: From ead42c982c03fa79b904571bc26cd6be483ada79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20=C5=9Awi=C4=99cki?= Date: Wed, 18 Nov 2026 21:57:50 +0100 Subject: [PATCH 4/5] helm: add vector map generation, upload and viewer With mapType=vector the chart runs a single CronJob whose container (maps-vector-generator image) runs the steps one after another: downloads and merges extracts of enabled regions (pbf + poly), generates low zoom world tiles and then tiles of all regions at once limited to their polygons, and uploads them with maps-vector-uploader. Downloaded data, generated tiles, the default local datastore and the map link live on a persistent data volume which is kept when the release is removed, so consecutive runs only fetch newer extracts and update the same map. The datastore and writer info can also be given as values or existing secrets like for the raster map. An optional viewer (cinode web proxy) serves the map from the datastore once the first upload is done, exposed with a service and optionally an ingress. The new image is included in the release script. Co-Authored-By: Claude Opus 5.5 --- README.md | 23 ++++ helm/osm-machinery/templates/_helpers.tpl | 41 +++++++ .../templates/vector-map-cronjob.yaml | 92 +++++++++++++++ .../templates/vector-map-pvc.yaml | 36 ++++++ .../templates/vector-map-secrets.yaml | 21 ++++ .../templates/vector-map-viewer.yaml | 110 ++++++++++++++++++ helm/osm-machinery/values.yaml | 95 +++++++++++++++ toolbox/release-chart-version.sh | 1 + 8 files changed, 419 insertions(+) create mode 100644 helm/osm-machinery/templates/vector-map-cronjob.yaml create mode 100644 helm/osm-machinery/templates/vector-map-pvc.yaml create mode 100644 helm/osm-machinery/templates/vector-map-secrets.yaml create mode 100644 helm/osm-machinery/templates/vector-map-viewer.yaml diff --git a/README.md b/README.md index db1aea0..1c06e96 100644 --- a/README.md +++ b/README.md @@ -109,3 +109,26 @@ MapLibre supports a single max zoom per source. When a tile doesn't exist existing ancestor tile (using `tiles/coverage.json` to skip non-existing ones) and rescales its geometry on the client. Above the highest generated zoom (14), MapLibre over-zooms natively. + +### Running in Kubernetes + +The `osm-machinery` helm chart generates either map type, selected with +`mapType`: + +* `raster` (default) - PostgreSQL + tile server, uploaded by + `maps-tile-uploader`, +* `vector` - a single CronJob running the steps one after another: + downloading extracts (`pbf` + `poly`) of enabled regions and merging them + into one extract with osmium, generating tiles with Planetiler (low zoom + levels for the whole world, then all regions at once, limited to their + polygons) and uploading them with `maps-vector-uploader`, plus an + optional viewer (cinode web proxy). Merging the extracts first makes tiles + along borders of neighbouring regions contain data of all of them. + Everything runs in the `maps-vector-generator` image. Requires + `postgres.enabled=false`. + +See `vectorMap` in [values.yaml](helm/osm-machinery/values.yaml) for all +options. By default the map is stored in a local datastore on the data +volume and the map link is created on the first run; use +`vectorMap.datastore` and `vectorMap.writerInfo` to publish to a real +datastore. diff --git a/helm/osm-machinery/templates/_helpers.tpl b/helm/osm-machinery/templates/_helpers.tpl index 4e5fb58..b7a8deb 100644 --- a/helm/osm-machinery/templates/_helpers.tpl +++ b/helm/osm-machinery/templates/_helpers.tpl @@ -37,3 +37,44 @@ Validated type of the generated map: "raster" or "vector" {{- end }} {{- $mapType }} {{- end }} + +{{/* +Regions with vector tiles: enabled and with own OSM extract +*/}} +{{- define "osm-machinery.vectorRegions" }} +{{- $regions := list }} +{{- range $.Values.regions }} +{{- if and .enabled .pbf (not .skipDownload) }} +{{- if not .poly }} +{{- fail (printf "vector map requires polygon (poly) of region '%s'" .name) }} +{{- end }} +{{- $regions = append $regions . }} +{{- end }} +{{- end }} +{{- dict "regions" $regions | toJson }} +{{- end }} + +{{/* +Env variable taken from a value or an existing secret, renders nothing +when neither is set. Params: env, cfg, defaultSecret +*/}} +{{- define "osm-machinery.secretEnv" }} +{{- if or .cfg.existingSecret .cfg.value }} +- name: {{ .env | quote }} + valueFrom: + secretKeyRef: + {{- if .cfg.existingSecret }} + name: {{ .cfg.secretName | required (printf "secretName is required for %s when existingSecret is set to true" .env) | quote }} + {{- else }} + name: {{ .cfg.secretName | default .defaultSecret | quote }} + {{- end }} + key: {{ .cfg.secretKey | quote }} +{{- end }} +{{- end }} + +{{/* +Extra Planetiler arguments of the vector map, quoted for the shell +*/}} +{{- define "osm-machinery.planetilerArgs" }} +{{- range $.Values.vectorMap.planetiler.extraArgs }} {{ . | squote }}{{ end }} +{{- end }} diff --git a/helm/osm-machinery/templates/vector-map-cronjob.yaml b/helm/osm-machinery/templates/vector-map-cronjob.yaml new file mode 100644 index 0000000..9945931 --- /dev/null +++ b/helm/osm-machinery/templates/vector-map-cronjob.yaml @@ -0,0 +1,92 @@ +{{- if eq (include "osm-machinery.mapType" $) "vector" }} +{{- $v := $.Values.vectorMap }} +{{- $regions := (include "osm-machinery.vectorRegions" $ | fromJson).regions }} +{{- if not $regions }} +{{- fail "vector map requires at least one enabled region with own OSM extract (pbf)" }} +{{- end }} +{{- $defaultSecret := print $.Release.Name "-vector-map-secret" }} +{{- $tilesDirs := list }} +{{- $minRegionZoom := 0 }} +{{- if $v.world.enabled }} +{{- $tilesDirs = append $tilesDirs "/data/tiles/world" }} +{{- $minRegionZoom = add1 ($v.world.maxZoom | int) }} +{{- end }} +{{- $tilesDirs = append $tilesDirs "/data/tiles/regions" }} +--- +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ print $.Release.Name "-vector-map" | quote }} +spec: + schedule: {{ $v.schedule | quote }} + suspend: {{ $v.suspend }} + + # Tiles generation and upload use the same data volume and modify the + # same cinode link so they must never run concurrently + concurrencyPolicy: Forbid + + jobTemplate: + spec: + backoffLimit: 1 + template: + metadata: + labels: + app: {{ print $.Release.Name "-vector-map" | quote }} + spec: + securityContext: {{- $v.securityContext | toYaml | nindent 12 }} + restartPolicy: Never + containers: + - name: generate + {{- include "osm-machinery.image" $v.image | indent 14 }} + # Steps run one after another. Extracts of all regions are + # merged first, so that tiles along shared borders are generated + # from data of all neighbouring regions + command: + - /bin/bash + - -c + - | + set -euo pipefail + prepare-osm-extract regions {{- range $regions }} {{ .pbf | squote }} {{ .poly | squote }}{{ end }} + {{- if $v.world.enabled }} + generate-vector-tiles world /data/osm/regions.osm.pbf 0 {{ $v.world.maxZoom | int }} --bounds=world {{- include "osm-machinery.planetilerArgs" $ }} + {{- end }} + generate-vector-tiles regions /data/osm/regions.osm.pbf {{ $minRegionZoom }} {{ $v.maxZoom | int }} --polygon=/data/osm/regions.poly {{- include "osm-machinery.planetilerArgs" $ }} + maps-vector-uploader + env: + - name: JAVA_TOOL_OPTIONS + value: {{ print $v.planetiler.javaOpts " -Djava.io.tmpdir=/tmp" | quote }} + {{- $ds := include "osm-machinery.secretEnv" (dict "env" "CINODE_DATASTORE" "cfg" $v.datastore "defaultSecret" $defaultSecret) }} + {{- if $ds }} + {{- $ds | indent 16 }} + {{- else }} + - name: CINODE_DATASTORE + value: "file:///data/datastore" + {{- end }} + {{- $wi := include "osm-machinery.secretEnv" (dict "env" "CINODE_MAPTILES_WRITERINFO" "cfg" $v.writerInfo "defaultSecret" $defaultSecret) }} + {{- if $wi }} + {{- $wi | indent 16 }} + {{- else }} + - name: CINODE_MAPTILES_WRITERINFO_FILE + value: /data/link/writerinfo + {{- end }} + - name: CINODE_MAPTILES_ENTRYPOINT_FILE + value: /data/link/entrypoint + - name: CINODE_VECTOR_TILES_DIRS + value: {{ join ":" $tilesDirs | quote }} + - name: CINODE_VECTOR_PARALLELISM + value: {{ $v.uploader.parallelism | quote }} + resources: {{- $v.resources | toYaml | nindent 16 }} + securityContext: {{- $v.containerSecurityContext | toYaml | nindent 16 }} + volumeMounts: + - name: data + mountPath: /data + - name: tmp + mountPath: /tmp + + volumes: + - name: data + persistentVolumeClaim: + claimName: {{ print $.Release.Name "-vector-data" | quote }} + - name: tmp + emptyDir: {} +{{- end }} diff --git a/helm/osm-machinery/templates/vector-map-pvc.yaml b/helm/osm-machinery/templates/vector-map-pvc.yaml new file mode 100644 index 0000000..6dbb2c3 --- /dev/null +++ b/helm/osm-machinery/templates/vector-map-pvc.yaml @@ -0,0 +1,36 @@ +{{- if eq (include "osm-machinery.mapType" $) "vector" }} +{{- $p := $.Values.vectorMap.persistence }} +{{- if $p.hostPath }} +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ print $.Release.Name "-vector-data-pv" | quote }} +spec: + capacity: + storage: {{ $p.size | quote }} + volumeMode: Filesystem + accessModes: {{ $p.accessModes | toYaml | nindent 4 }} + persistentVolumeReclaimPolicy: Retain + storageClassName: {{ $p.storageClass | required "unique storageClass required for hostPath volume" | quote }} + hostPath: + path: {{ $p.hostPath | quote }} +{{- end }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ print $.Release.Name "-vector-data" | quote }} + annotations: + # The volume holds the map link (writer info), losing it would change + # the map address, so it is kept when the release is removed + helm.sh/resource-policy: keep +spec: + {{- if $p.storageClass }} + storageClassName: {{ $p.storageClass | quote }} + {{- end }} + accessModes: {{ $p.accessModes | toYaml | nindent 4 }} + resources: + requests: + storage: {{ $p.size | quote }} +{{- end }} diff --git a/helm/osm-machinery/templates/vector-map-secrets.yaml b/helm/osm-machinery/templates/vector-map-secrets.yaml new file mode 100644 index 0000000..5f70ded --- /dev/null +++ b/helm/osm-machinery/templates/vector-map-secrets.yaml @@ -0,0 +1,21 @@ +{{- if eq (include "osm-machinery.mapType" $) "vector" }} +{{- $defaultSecret := print $.Release.Name "-vector-map-secret" }} +{{- $secrets := dict }} +{{- range $cfg := list $.Values.vectorMap.datastore $.Values.vectorMap.writerInfo }} +{{- if and $cfg.value (not $cfg.existingSecret) }} +{{- $name := $cfg.secretName | default $defaultSecret }} +{{- $data := get $secrets $name | default dict }} +{{- $_ := set $data $cfg.secretKey ($cfg.value | b64enc) }} +{{- $_ := set $secrets $name $data }} +{{- end }} +{{- end }} +{{- range $name, $data := $secrets }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ $name | quote }} +type: Opaque +data: {{- $data | toYaml | nindent 2 }} +{{- end }} +{{- end }} diff --git a/helm/osm-machinery/templates/vector-map-viewer.yaml b/helm/osm-machinery/templates/vector-map-viewer.yaml new file mode 100644 index 0000000..beba022 --- /dev/null +++ b/helm/osm-machinery/templates/vector-map-viewer.yaml @@ -0,0 +1,110 @@ +{{- if and (eq (include "osm-machinery.mapType" $) "vector") $.Values.vectorMap.viewer.enabled }} +{{- $v := $.Values.vectorMap }} +{{- $name := print $.Release.Name "-vector-viewer" }} +{{- $ds := include "osm-machinery.secretEnv" (dict "env" "CINODE_MAIN_DATASTORE" "cfg" $v.datastore "defaultSecret" (print $.Release.Name "-vector-map-secret")) }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ $name | quote }} +spec: + replicas: 1 + selector: + matchLabels: + app: {{ $name | quote }} + template: + metadata: + labels: + app: {{ $name | quote }} + spec: + securityContext: {{- $v.securityContext | toYaml | nindent 8 }} + initContainers: + # The map link is created by the first run of the vector map job + - name: wait-for-map + {{- include "osm-machinery.image" $v.viewer.waitImage | indent 10 }} + command: + - sh + - -c + - | + until [ -s /data/link/entrypoint ]; do + echo "Waiting for the first vector map upload" + sleep 10 + done + securityContext: {{- $v.containerSecurityContext | toYaml | nindent 12 }} + volumeMounts: + - name: data + mountPath: /data + readOnly: true + containers: + - name: web-proxy + {{- include "osm-machinery.image" $v.viewer.image | indent 10 }} + env: + - name: CINODE_ENTRYPOINT_FILE + value: /data/link/entrypoint + {{- if $ds }} + {{- $ds | indent 12 }} + {{- else }} + - name: CINODE_MAIN_DATASTORE + value: "file:///data/datastore" + {{- end }} + - name: CINODE_LISTEN_PORT + value: "8080" + ports: + - name: http + containerPort: 8080 + readinessProbe: + httpGet: + path: /index.html + port: http + resources: {{- $v.viewer.resources | toYaml | nindent 12 }} + securityContext: {{- $v.containerSecurityContext | toYaml | nindent 12 }} + volumeMounts: + - name: data + mountPath: /data + readOnly: true + - name: tmp + mountPath: /tmp + volumes: + - name: data + persistentVolumeClaim: + claimName: {{ print $.Release.Name "-vector-data" | quote }} + - name: tmp + emptyDir: {} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ $name | quote }} +spec: + selector: + app: {{ $name | quote }} + ports: + - name: http + protocol: TCP + port: 80 + targetPort: http +{{- if $v.viewer.ingress.enabled }} +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $name | quote }} +spec: + {{- if $v.viewer.ingress.className }} + ingressClassName: {{ $v.viewer.ingress.className | quote }} + {{- end }} + rules: + {{- range $host := $v.viewer.ingress.hosts }} + - host: {{ $host | quote }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ $name | quote }} + port: + name: http + {{- end }} +{{- end }} +{{- end }} diff --git a/helm/osm-machinery/values.yaml b/helm/osm-machinery/values.yaml index 2eb6a21..064ede8 100644 --- a/helm/osm-machinery/values.yaml +++ b/helm/osm-machinery/values.yaml @@ -245,6 +245,101 @@ cinodeUpload: secretName: "" secretKey: writerinfo +vectorMap: + # Steps run one after another in a single CronJob: download of region + # extracts (pbf + poly) merged into one extract, tiles generation (world, + # then all regions at once) and upload. To run it right away: + # kubectl create job --from=cronjob/-vector-map + # + # Every enabled region with own extract (pbf) needs its polygon (poly), + # tiles are only generated inside those polygons. Extracts of neighbouring + # regions overlap a bit, merging them first makes tiles along borders + # contain data of all regions. + schedule: "0 0 * * 0" + suspend: false + + # Low zoom levels for the whole world (Natural Earth, water polygons), + # OSM features at those levels only come from the regions + world: + enabled: true + maxZoom: 6 + + # Max zoom of region tiles, MapLibre over-zooms vector tiles beyond that + # level on the client + maxZoom: 14 + + # Image with Planetiler, maps-vector-uploader and the viewer assets + image: + registry: ghcr.io + repository: cinode/maps-vector-generator + tag: "0.0.13" + + # Resources of the whole run, Planetiler is the most demanding step + resources: {} + + planetiler: + # Java heap limit, larger regions need more (Poland: ~8g) + javaOpts: "-Xmx2g" + extraArgs: [] + + uploader: + parallelism: 4 + + # Target datastore, when empty a local datastore on the data volume is used + datastore: + value: "" + existingSecret: false + secretName: "" + secretKey: datastore + + # Writer info of the map, when empty a new link is created on the first + # run and its writer info is kept on the data volume + writerInfo: + value: "" + existingSecret: false + secretName: "" + secretKey: writerinfo + + securityContext: + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + fsGroupChangePolicy: "OnRootMismatch" + + containerSecurityContext: + readOnlyRootFilesystem: true + allowPrivilegeEscalation: false + + # Cinode web proxy serving the map from the datastore, the map link is + # read from the data volume when the first upload finishes + viewer: + enabled: true + image: + registry: ghcr.io + repository: cinode/web_proxy + tag: "0.0.11" + # Small image with a shell used to wait for the first upload + waitImage: + registry: docker.io + repository: library/busybox + tag: "1.37" + resources: {} + ingress: + enabled: false + className: "" + hosts: + - cinode-maps + + # Volume with downloaded sources, generated tiles, the local datastore + # and the map link + persistence: + size: 20Gi + storageClass: "" + # To use a local directory, set hostPath and a unique storageClass + hostPath: "" + accessModes: + - ReadWriteOnce + regions: - enabled: true name: europe-luxembourg diff --git a/toolbox/release-chart-version.sh b/toolbox/release-chart-version.sh index 79c6ae3..604658a 100755 --- a/toolbox/release-chart-version.sh +++ b/toolbox/release-chart-version.sh @@ -42,6 +42,7 @@ fi for image in \ maps-tile-uploader \ + maps-vector-generator \ maps-tile-server \ ; do # Update image tags in values.yaml From 83fe08015840214fadc1bac6cba310b15a45b139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20=C5=9Awi=C4=99cki?= Date: Wed, 18 Nov 2026 21:57:50 +0100 Subject: [PATCH 5/5] Add minikube presets for raster and vector maps minikube-test.sh takes a preset (raster, vector-luxembourg, vector-poland, vector-border), starts minikube when needed, builds images with the local docker and loads them into minikube (works with any minikube container runtime), deploys the chart and for vector maps starts the generation right away. minikube-view.sh follows the vector map generation and serves the map once the first upload is done, restarting port forwarding when it drops; ADDRESS=0.0.0.0 makes it reachable from other devices in the local network. Co-Authored-By: Claude Opus 5.5 --- README.md | 40 +++++++ toolbox/minikube-test.sh | 108 +++++++++++++----- toolbox/minikube-view.sh | 54 +++++++++ toolbox/minikube/values-raster.yaml | 2 + toolbox/minikube/values-vector-border.yaml | 31 +++++ .../minikube/values-vector-luxembourg.yaml | 30 +++++ toolbox/minikube/values-vector-poland.yaml | 27 +++++ 7 files changed, 266 insertions(+), 26 deletions(-) create mode 100755 toolbox/minikube-view.sh create mode 100644 toolbox/minikube/values-raster.yaml create mode 100644 toolbox/minikube/values-vector-border.yaml create mode 100644 toolbox/minikube/values-vector-luxembourg.yaml create mode 100644 toolbox/minikube/values-vector-poland.yaml diff --git a/README.md b/README.md index 1c06e96..abcae42 100644 --- a/README.md +++ b/README.md @@ -132,3 +132,43 @@ options. By default the map is stored in a local datastore on the data volume and the map link is created on the first run; use `vectorMap.datastore` and `vectorMap.writerInfo` to publish to a real datastore. + +## Local testing in minikube + +`toolbox/minikube-test.sh` starts minikube (if needed), builds images +from the working tree, loads them into minikube and deploys the chart with +one of the presets from [toolbox/minikube](toolbox/minikube): + +```bash +# Raster map (default) +toolbox/minikube-test.sh + +# Vector map of Luxembourg - quick test, a few minutes +toolbox/minikube-test.sh vector-luxembourg + +# Vector map of Poland - realistic dataset, ~30 min, needs a bigger minikube +MINIKUBE_MEMORY=10g toolbox/minikube-test.sh vector-poland + +# Vector map of two neighbouring regions (Lubuskie, Brandenburg) - checks +# that tiles along the border contain data of both, ~10 min +toolbox/minikube-test.sh vector-border +``` + +For vector presets the map generation starts right away. +`toolbox/minikube-view.sh` follows it and, once the first upload is done, +serves the map on : + +```bash +toolbox/minikube-view.sh + +# Also reachable from other devices in the local network, e.g. a phone +ADDRESS=0.0.0.0 toolbox/minikube-view.sh +``` + +Running `minikube-test.sh` again deploys the current code and starts a new +generation, the same map link is updated. Downloaded data is kept on the +data volume, which also holds the map link and is kept when the release +is removed. To start from scratch remove the release +(`helm uninstall cinode-maps --kube-context minikube`) and the volume +(`minikube kubectl -- delete pvc cinode-maps-vector-data`) or the whole +minikube (`minikube delete`). diff --git a/toolbox/minikube-test.sh b/toolbox/minikube-test.sh index 81c5dc9..96b9575 100755 --- a/toolbox/minikube-test.sh +++ b/toolbox/minikube-test.sh @@ -1,15 +1,58 @@ #!/bin/bash +# Deploys osm-machinery with locally built images to minikube +# +# Usage: toolbox/minikube-test.sh [preset] +# +# Presets (toolbox/minikube/values-.yaml): +# raster - raster map (PostgreSQL + tile server), the default +# vector-luxembourg - vector map of Luxembourg, quick test +# vector-poland - vector map of Poland, realistic dataset +# +# Images are built from the working tree with the local docker. +# +# Minikube is started if it is not running yet, its size can be set with +# MINIKUBE_MEMORY (default 4g), MINIKUBE_CPUS (4) and MINIKUBE_DISK (40g). +# +# For vector presets the map generation is started right away, use +# toolbox/minikube-view.sh to watch it and to open the map. set -euo pipefail cd "$(dirname "$0")/.." -if ! minikube status | grep -q "Running"; then - echo "Minikube is not running" +PRESET="${1:-raster}" +VALUES_FILE="toolbox/minikube/values-${PRESET}.yaml" +if [ ! -f "$VALUES_FILE" ]; then + echo "Unknown preset '$PRESET', available presets:" + for f in toolbox/minikube/values-*.yaml; do + f="${f#toolbox/minikube/values-}" + echo " ${f%.yaml}" + done exit 1 fi -eval "$(minikube docker-env)" +case "$PRESET" in + vector*) + MAP_TYPE=vector + RELEASE=cinode-maps + ;; + *) + MAP_TYPE=raster + RELEASE=cinode-maps-tile-server + ;; +esac + +if ! minikube status 2>/dev/null | grep -q "Running"; then + echo "Starting minikube" + minikube start \ + --memory="${MINIKUBE_MEMORY:-4g}" \ + --cpus="${MINIKUBE_CPUS:-4}" \ + --disk-size="${MINIKUBE_DISK:-40g}" +fi + +kubectl() { + minikube kubectl -- "$@" +} if git diff --quiet; then TAGNAME="devel-$(git rev-parse --short HEAD)" @@ -17,32 +60,45 @@ else TAGNAME="devel-$(git rev-parse --short HEAD)-dirty-$(date +%s)" fi -for image in \ - maps-tile-uploader \ - maps-tile-server \ -; do - docker build -t cinode/$image:$TAGNAME -f build/docker/Dockerfile.${image} . -done - -VALUES_CONTENT="--- -cinodeUpload: - image: - tag: $TAGNAME - registry: docker.io - repository: cinode/maps-tile-uploader - pullPolicy: Never -tileServer: - image: - tag: $TAGNAME - registry: docker.io - repository: cinode/maps-tile-server - pullPolicy: Never -" +image_values() { + local key="$1" image="$2" + # Built with the local docker and loaded into minikube, which works + # regardless of minikube's container runtime + docker build --load -t "cinode/$image:$TAGNAME" -f "build/docker/Dockerfile.$image" . + minikube image load "cinode/$image:$TAGNAME" + IMAGE_ARGS+=( + --set "$key.image.registry=docker.io" + --set "$key.image.repository=cinode/$image" + --set "$key.image.tag=$TAGNAME" + --set "$key.image.pullPolicy=Never" + ) +} + +IMAGE_ARGS=() +if [ "$MAP_TYPE" = vector ]; then + image_values vectorMap maps-vector-generator +else + image_values cinodeUpload maps-tile-uploader + image_values tileServer maps-tile-server +fi + +if ! ls helm/osm-machinery/charts/*.tgz >/dev/null 2>&1; then + helm dependency build ./helm/osm-machinery +fi helm \ upgrade --install \ - cinode-maps-tile-server \ + "$RELEASE" \ ./helm/osm-machinery \ --kube-context minikube \ --values ./helm/osm-machinery/values.yaml \ - --values <( echo "$VALUES_CONTENT" ) + --values "$VALUES_FILE" \ + "${IMAGE_ARGS[@]}" + +if [ "$MAP_TYPE" = vector ]; then + JOB="$RELEASE-vector-map-$(date +%Y%m%d-%H%M%S)" + kubectl create job --from="cronjob/$RELEASE-vector-map" "$JOB" + echo + echo "Vector map generation started in job $JOB, to follow it and open the map run:" + echo " toolbox/minikube-view.sh" +fi diff --git a/toolbox/minikube-view.sh b/toolbox/minikube-view.sh new file mode 100755 index 0000000..d139638 --- /dev/null +++ b/toolbox/minikube-view.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Waits for the vector map deployed with toolbox/minikube-test.sh and +# serves it on http://localhost:$PORT (default 8080) +# +# To open the map on other devices in the local network (e.g. a phone), set +# ADDRESS=0.0.0.0 to listen on all network interfaces. +set -euo pipefail + +RELEASE=cinode-maps +PORT="${PORT:-8080}" +ADDRESS="${ADDRESS:-localhost}" + +kubectl() { + minikube kubectl -- "$@" +} + +echo "Waiting for the first map upload, full logs of the map generation:" +echo " minikube kubectl -- logs -f -l app=$RELEASE-vector-map --all-containers --prefix" +echo + +until kubectl rollout status "deploy/$RELEASE-vector-viewer" --timeout=1s >/dev/null 2>&1; do + POD="$(kubectl get pods -l "app=$RELEASE-vector-map" \ + --sort-by=.metadata.creationTimestamp -o name | tail -1)" + if [ -n "$POD" ]; then + echo "$(date +%T) $POD: $(kubectl get "$POD" --no-headers | awk '{print $3}')" + + JOB="$(kubectl get "$POD" -o jsonpath='{.metadata.labels.job-name}')" + FAILED="$(kubectl get job "$JOB" -o jsonpath='{.status.conditions[?(@.type=="Failed")].status}' 2>/dev/null || true)" + if [ "$FAILED" = True ]; then + echo "Map generation failed in job $JOB:" + kubectl logs "$POD" --all-containers --prefix --tail=20 + exit 1 + fi + fi + sleep 20 +done + +echo +echo "Map available at http://localhost:$PORT/" +if [ "$ADDRESS" != localhost ]; then + for ip in $(hostname -I); do + case "$ip" in + *:*) ;; # skip IPv6 + *) echo " also at http://$ip:$PORT/" ;; + esac + done +fi +# kubectl port-forward exits on "lost connection to pod" errors which happen +# when the browser cancels pending tile requests, restart it until Ctrl+C +while true; do + minikube kubectl -- port-forward --address "$ADDRESS" "svc/$RELEASE-vector-viewer" "$PORT:80" || true + echo "Port forwarding stopped, restarting" + sleep 1 +done diff --git a/toolbox/minikube/values-raster.yaml b/toolbox/minikube/values-raster.yaml new file mode 100644 index 0000000..492d261 --- /dev/null +++ b/toolbox/minikube/values-raster.yaml @@ -0,0 +1,2 @@ +# Raster map (PostgreSQL + tile server) with default regions (Luxembourg) +mapType: raster diff --git a/toolbox/minikube/values-vector-border.yaml b/toolbox/minikube/values-vector-border.yaml new file mode 100644 index 0000000..2dc4d7a --- /dev/null +++ b/toolbox/minikube/values-vector-border.yaml @@ -0,0 +1,31 @@ +# Vector map of two regions sharing a border (Lubuskie in Poland and +# Brandenburg in Germany) - checks that tiles along the border contain data +# of both regions, +# the run takes ~10 minutes and Planetiler needs ~3.5GB of memory +mapType: vector + +postgres: + enabled: false + +vectorMap: + # Runs are started on demand by minikube-test.sh + suspend: true + planetiler: + javaOpts: "-Xmx3g" + extraArgs: + - --threads=4 + uploader: + parallelism: 4 + persistence: + size: 30Gi + +regions: + - enabled: true + name: europe-poland-lubuskie + pbf: https://download.geofabrik.de/europe/poland/lubuskie-latest.osm.pbf + poly: https://download.geofabrik.de/europe/poland/lubuskie.poly + + - enabled: true + name: europe-germany-brandenburg + pbf: https://download.geofabrik.de/europe/germany/brandenburg-latest.osm.pbf + poly: https://download.geofabrik.de/europe/germany/brandenburg.poly diff --git a/toolbox/minikube/values-vector-luxembourg.yaml b/toolbox/minikube/values-vector-luxembourg.yaml new file mode 100644 index 0000000..b25e85f --- /dev/null +++ b/toolbox/minikube/values-vector-luxembourg.yaml @@ -0,0 +1,30 @@ +# Vector map of Luxembourg - small dataset for quick tests, +# the whole run takes a few minutes and Planetiler needs ~2.5GB of memory +mapType: vector + +postgres: + enabled: false + +vectorMap: + # Runs are started on demand by minikube-test.sh + suspend: true + planetiler: + # World sources (Natural Earth, water polygons) need ~2GB of heap + javaOpts: "-Xmx2g" + extraArgs: + - --threads=2 + uploader: + parallelism: 2 + persistence: + size: 10Gi + +regions: + - enabled: true + name: europe-luxembourg + pbf: https://download.geofabrik.de/europe/luxembourg-latest.osm.pbf + poly: https://download.geofabrik.de/europe/luxembourg.poly + geoBBox: + minLon: 5.726280 + minLat: 49.435092 + maxLon: 6.554718 + maxLat: 50.190968 diff --git a/toolbox/minikube/values-vector-poland.yaml b/toolbox/minikube/values-vector-poland.yaml new file mode 100644 index 0000000..6a2dde2 --- /dev/null +++ b/toolbox/minikube/values-vector-poland.yaml @@ -0,0 +1,27 @@ +# Vector map of Poland - realistic dataset, the run takes ~1h and Planetiler +# needs ~8GB of memory (start minikube with MINIKUBE_MEMORY=10g) +mapType: vector + +postgres: + enabled: false + +vectorMap: + # Runs are started on demand by minikube-test.sh + suspend: true + planetiler: + javaOpts: "-Xmx7g" + uploader: + parallelism: 4 + persistence: + size: 30Gi + +regions: + - enabled: true + name: europe-poland + pbf: https://download.geofabrik.de/europe/poland-latest.osm.pbf + poly: https://download.geofabrik.de/europe/poland.poly + geoBBox: + minLat: 49.0061 + minLon: 14.1213 + maxLat: 54.8357 + maxLon: 24.1533