@@ -5,8 +5,13 @@ import protomapsLayers from "protomaps-themes-base";
55import { language_script_pairs } from "protomaps-themes-base" ;
66import { viewport } from "@mapbox/geo-viewport" ;
77import { bbox } from "@turf/bbox" ;
8+ import { mask } from "@turf/mask" ;
9+ import { simplify } from "@turf/simplify" ;
810
911const region = JSON . parse ( fs . readFileSync ( "region.geojson" ) ) ;
12+ const simplifiedRegion = simplify ( region , { tolerance : 0.01 } ) . features [ 0 ] . geometry ;
13+
14+ fs . writeFileSync ( "dist/region-mask.geojson" , JSON . stringify ( mask ( region ) ) ) ;
1015
1116// Determine tile URL
1217let tileJson ;
@@ -22,6 +27,24 @@ if (process.env.TILE_JSON) {
2227for ( const theme of [ "light" , "dark" , "white" , "grayscale" , "black" ] ) {
2328 for ( const { lang, full_name, script } of language_script_pairs ) {
2429 const layers = protomapsLayers ( "protomaps" , theme , lang , script ) ;
30+ const bgIdx = layers . findIndex ( ( { id } ) => id === "places_subplace" ) ;
31+ const bgColor = layers . find ( ( { id } ) => id === "background" ) . paint [
32+ "background-color"
33+ ] ;
34+ layers . splice ( bgIdx , 0 , {
35+ id : "mask-fill" ,
36+ type : "fill" ,
37+ source : "mask" ,
38+ paint : { "fill-color" : bgColor } ,
39+ } ) ;
40+ layers . forEach ( ( l ) => {
41+ if ( l . id . startsWith ( "place" ) || l . id === "pois" ) {
42+ if ( l . filter [ 0 ] === "==" && typeof l . filter [ 0 ] === "string" ) {
43+ l . filter = [ l . filter [ 0 ] , [ "get" , l . filter [ 1 ] ] , l . filter [ 2 ] ] ;
44+ }
45+ l . filter = [ "all" , l . filter , [ "within" , simplifiedRegion ] ] ;
46+ }
47+ } ) ;
2548
2649 const style = {
2750 version : 8 ,
@@ -32,6 +55,13 @@ for (const theme of ["light", "dark", "white", "grayscale", "black"]) {
3255 '© <a href="https://openstreetmap.org">OpenStreetMap</a>' ,
3356 url : tileJson ,
3457 } ,
58+ mask : {
59+ type : "geojson" ,
60+ data : new URL (
61+ "./region-mask.geojson" ,
62+ tileJson . replace ( / ^ p m t i l e s : \/ \/ / , "" ) ,
63+ ) ,
64+ } ,
3565 } ,
3666 layers : layers ,
3767 sprite : `https://protomaps.github.io/basemaps-assets/sprites/v4/${ theme } ` ,
0 commit comments