This commit is contained in:
Zsolt Ero
2024-06-12 13:08:39 +02:00
parent 1ce5c85b9c
commit 087ab649b1
7 changed files with 34 additions and 15 deletions

BIN
website/assets/berlin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

BIN
website/assets/berlin.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

View File

Before

Width:  |  Height:  |  Size: 288 KiB

After

Width:  |  Height:  |  Size: 288 KiB

View File

@@ -1,3 +1,17 @@
const london3d = {
center: [-0.114, 51.506],
zoom: 14.2,
bearing: 55.2,
pitch: 60,
}
const berlin = {
center: [13.388, 52.517],
zoom: 9.5,
bearing: 0,
pitch: 0,
}
function initMap() { function initMap() {
if (window.map) return if (window.map) return
@@ -5,10 +19,10 @@ function initMap() {
const map = new maplibregl.Map({ const map = new maplibregl.Map({
style: 'https://tiles.openfreemap.org/styles/liberty', style: 'https://tiles.openfreemap.org/styles/liberty',
center: [-0.114, 51.506], center: berlin.center,
zoom: 14.2, zoom: berlin.zoom,
bearing: 55.2, bearing: berlin.bearing,
pitch: 60, pitch: berlin.pitch,
container: mapDiv, container: mapDiv,
boxZoom: false, boxZoom: false,
// doubleClickZoom: false, // doubleClickZoom: false,
@@ -42,21 +56,25 @@ mapDiv.onclick = function () {
// initMap() // initMap()
let movedTo2d = false // let movedTo2d = false
function selectStyle(event, style) { function selectStyle(event, style) {
initMap() initMap()
toggleButtonSelection(event.target) toggleButtonSelection(event.target)
const styleUrl = 'https://tiles.openfreemap.org/styles/' + style const styleUrl = 'https://tiles.openfreemap.org/styles/' + style.split('-')[0]
map.setStyle(styleUrl) map.setStyle(styleUrl)
if (!movedTo2d) { if (style === 'liberty-3d') {
map.setCenter({ lng: 13.388, lat: 52.517 }) map.setCenter(london3d.center)
map.setPitch(0) map.setPitch(london3d.pitch)
map.setBearing(0) map.setBearing(london3d.bearing)
map.setZoom(9.5) map.setZoom(london3d.zoom)
movedTo2d = true } else if (map.getBearing() !== 0) {
map.setCenter(berlin.center)
map.setPitch(berlin.pitch)
map.setBearing(berlin.bearing)
map.setZoom(berlin.zoom)
} }
document.getElementById('style-url-code').innerText = styleUrl document.getElementById('style-url-code').innerText = styleUrl

View File

@@ -169,7 +169,7 @@ code {
#map-container { #map-container {
width: 100%; width: 100%;
height: 500px; height: 500px;
margin-bottom: 2em; margin-bottom: 24px;
position: relative; position: relative;
} }
@@ -178,7 +178,7 @@ code {
height: 100%; height: 100%;
position: absolute; position: absolute;
z-index: 1; z-index: 1;
background-image: url('mapbg.jpg'); background-image: url('berlin.webp');
background-size: cover; background-size: cover;
background-position: center; background-position: center;
background-repeat: no-repeat; background-repeat: no-repeat;

View File

@@ -13,6 +13,7 @@
<button onclick="selectStyle(event, 'positron')" class="btn">Positron</button> <button onclick="selectStyle(event, 'positron')" class="btn">Positron</button>
<button onclick="selectStyle(event, 'bright')" class="btn">Bright</button> <button onclick="selectStyle(event, 'bright')" class="btn">Bright</button>
<button onclick="selectStyle(event, 'liberty')" class="btn selected">Liberty</button> <button onclick="selectStyle(event, 'liberty')" class="btn selected">Liberty</button>
<button onclick="selectStyle(event, 'liberty-3d')" class="btn">3D</button>
</div> </div>
<p>Use the following style in a MapLibre map:</p> <p>Use the following style in a MapLibre map:</p>

View File

@@ -49,7 +49,7 @@ def copy_assets():
'favicon.ico', 'favicon.ico',
'github.svg', 'github.svg',
'x.svg', 'x.svg',
'mapbg.jpg', 'berlin.webp',
]: ]:
shutil.copyfile(ASSETS_DIR / file, OUT_DIR / file) shutil.copyfile(ASSETS_DIR / file, OUT_DIR / file)