Skip to content

Commit a4da2e4

Browse files
committed
include absolute URL in martin response
www (maplibre-gl-js) was (mostly[^1]) happy with relative URLs in the style.json, but maplibre-native wasn't able to construct them. [^1]: tilejson and sprites worked with relative URLs, but glyphs didn't, so I fixed it with a style-transform handler, but I guess the good news is my hand was forced to fix this on the service side and thus I can get rid of that www client-side glyph hack.
1 parent 3072f80 commit a4da2e4

3 files changed

Lines changed: 6 additions & 22 deletions

File tree

dagger/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ func martinBinary() *dagger.File {
217217
const martinFeatures = "fonts,mbtiles,pmtiles,styles,sprites"
218218

219219
// To build from source (e.g. for debugging a fork), set this to true
220-
const buildFromSource = false
220+
const buildFromSource = true
221221
if buildFromSource {
222222
return rustContainer("git").
223223
WithEnvVariable("CACHE_BUSTER", time.Now().String()).
224-
WithExec([]string{"git", "clone", "--branch", "mkirk/fix-forwarding-header", "--depth=1", "https://github.com/michaelkirk/martin.git", "/martin"}).
224+
WithExec([]string{"git", "clone", "--branch", "mkirk/relative-source-urls", "--depth=1", "https://github.com/michaelkirk/martin.git", "/martin"}).
225225
WithWorkdir("/martin").
226226
WithExec([]string{"cargo", "build", "--release", "--locked", "--no-default-features", "--features", martinFeatures}).
227227
File("target/release/martin")

services/frontend/www-app/src/components/BaseMap.vue

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import maplibregl, {
2020
MapOptions,
2121
Marker,
2222
SourceSpecification,
23-
StyleSpecification,
2423
} from 'maplibre-gl';
2524
import 'maplibre-gl/dist/maplibre-gl.css';
2625
import Prefs from 'src/utils/Prefs';
@@ -51,6 +50,7 @@ async function loadMap(): Promise<maplibregl.Map> {
5150
5251
const mapOptions: MapOptions = {
5352
container: mapContainerId,
53+
style: '/tileserver/styles/basic/style.json', // style URL
5454
center: initialCenter, // starting position [lng, lat]
5555
zoom: initialZoom, // starting zoom
5656
attributionControl: false,
@@ -78,22 +78,6 @@ async function loadMap(): Promise<maplibregl.Map> {
7878
}
7979
8080
map = new maplibregl.Map(mapOptions);
81-
map.setStyle('/tileserver/style/basic.json', {
82-
transformStyle: (
83-
_previous: StyleSpecification | undefined,
84-
next: StyleSpecification,
85-
): StyleSpecification => {
86-
// MapLibre requires sprite URLs to be absolute, but our style uses relative URLs for
87-
// portability across domains.
88-
//
89-
// For some reason font and tile sources are happy with relative URLs, but sprite URLs are not,
90-
// so we only transform the sprite URL.
91-
if (typeof next.sprite === 'string' && next.sprite.startsWith('/')) {
92-
return { ...next, sprite: window.location.origin + next.sprite };
93-
}
94-
return next;
95-
},
96-
});
9781
return map;
9882
}
9983

services/tileserver/martin-dev-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
pmtiles:
22
sources:
3-
areamap: ../../data/Seattle/Seattle.pmtiles
3+
areamap: ../../data/Bogota/Bogota.pmtiles
44
mbtiles:
55
sources:
6-
landcover: ../../data/Seattle/landcover.mbtiles
7-
terrain: ../../data/Seattle/terrain.mbtiles
6+
landcover: ../../data/Bogota/landcover.mbtiles
7+
terrain: ../../data/Bogota/terrain.mbtiles
88
styles:
99
paths: ['./assets/styles']
1010
sprites:

0 commit comments

Comments
 (0)