-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,77 @@ | ||
import { onMount } from "solid-js"; | ||
import { For, createSignal, createEffect, onMount, Component } from "solid-js"; | ||
import "maplibre-gl/dist/maplibre-gl.css"; | ||
import "./App.css"; | ||
import maplibregl from "maplibre-gl"; | ||
import { LayerSpecification } from "maplibre-gl"; | ||
import { layersWithCustomTheme } from "protomaps-themes-base"; | ||
import { StyleSpecification } from "maplibre-gl"; | ||
import { Theme, layersWithCustomTheme } from "protomaps-themes-base"; | ||
|
||
const THEMES = ["contrast"]; | ||
const THEMES = ["contrast", "bright"]; | ||
|
||
const themeToLayers = new Map<string, Theme>(); | ||
|
||
for (let themeName of THEMES) { | ||
let theme = await import(`../../themes/${themeName}.ts`); | ||
themeToLayers.set(themeName, theme.default); | ||
} | ||
|
||
const getStyle = (index: number):StyleSpecification => { | ||
let themeName = THEMES[index]; | ||
let layers = layersWithCustomTheme( | ||
"protomaps", | ||
themeToLayers.get(themeName)!, | ||
"en", | ||
); | ||
return { | ||
version: 8, | ||
glyphs: | ||
"https://bdon.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf", | ||
sources: { | ||
protomaps: { | ||
type: "vector", | ||
url: "https://api.protomaps.com/tiles/v4.json?key=1003762824b9687f", | ||
}, | ||
}, | ||
layers: layers, | ||
}; | ||
}; | ||
|
||
const ThemeRow: Component<{name: string, theme: Theme}> = (props) => { | ||
return ( | ||
<div class="themeRow" style={{"background-color":props.theme.background,"color":props.theme.city_label}}> | ||
{props.name} | ||
</div> | ||
) | ||
} | ||
|
||
function App() { | ||
let map: maplibregl.Map; | ||
|
||
const [selectedIndex, setSelectedIndex] = createSignal(0); | ||
onMount(async () => { | ||
maplibregl.setRTLTextPlugin( | ||
"https://unpkg.com/@mapbox/[email protected]/mapbox-gl-rtl-text.min.js", | ||
true, | ||
); | ||
|
||
let layers: LayerSpecification[] = []; | ||
|
||
for (let themeName of THEMES) { | ||
let theme = await import(`../../themes/${themeName}.ts`); | ||
layers = layersWithCustomTheme("protomaps", theme.default, "en"); | ||
} | ||
|
||
new maplibregl.Map({ | ||
map = new maplibregl.Map({ | ||
container: "map", | ||
style: { | ||
version: 8, | ||
glyphs: | ||
"https://protomaps.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf", | ||
sources: { | ||
protomaps: { | ||
type: "vector", | ||
url: "https://api.protomaps.com/tiles/v4.json?key=1003762824b9687f", | ||
}, | ||
}, | ||
layers: layers, | ||
}, | ||
style: getStyle(selectedIndex()), | ||
}); | ||
}); | ||
|
||
createEffect(() => { | ||
map.setStyle(getStyle(selectedIndex())); | ||
}); | ||
|
||
const selectTheme = (i: number) => { | ||
setSelectedIndex(i); | ||
} | ||
|
||
return ( | ||
<div id="container"> | ||
<div class="sidebar"> | ||
<For each={THEMES}>{(themeName,i) => <div onClick={() => selectTheme(i())}><ThemeRow name={themeName} theme={themeToLayers.get(themeName)!}/></div>}</For> | ||
</div> | ||
<div id="map"></div> | ||
</div> | ||
); | ||
|