Skip to content

Commit 5f19039

Browse files
committed
Update preview images based on current map view
1 parent 8577058 commit 5f19039

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@
5252
"imageAlt": "luftbilder.berlin.codefor.de screenshot",
5353
"twitter": "@codeforbe"
5454
}
55-
}
55+
}

src/App.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
2-
<Nav :brand="brand" :maps="maps" :map="map" @changeMap="changeMap" @changeCenter="changeCenter"/>
3-
<Map :map="map" :center="center" :zoom="zoom" />
2+
<Nav :brand="brand" :maps="maps" :map="map" :center="center" :zoom="zoom" @changeMap="changeMap" @changeCenter="changeCenter"/>
3+
<Map :map="map" :center="center" :zoom="zoom" @changeCenter="changeCenter" @changeZoom="changeZoom"/>
44
</template>
55

66
<script>
@@ -28,6 +28,9 @@
2828
},
2929
changeCenter(center) {
3030
this.center = center
31+
},
32+
changeZoom(zoom) {
33+
this.zoom = zoom
3134
}
3235
}
3336
}

src/components/Map.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
this.leafletMap = L.map('map')
2525
this.changeView()
2626
this.changeMap()
27+
this.leafletMap.on('moveend', () => {
28+
const c = this.leafletMap.getCenter()
29+
const [currentLat, currentLon] = this.center;
30+
if (currentLat !== c.lat && currentLon !== c.lng) {
31+
this.$emit('changeCenter', [c.lat, c.lng])
32+
}
33+
})
34+
this.leafletMap.on('zoomend', () => {
35+
const z = this.leafletMap.getZoom()
36+
if (z !== this.zoom) {
37+
this.$emit('changeZoom', z)
38+
}
39+
})
2740
},
2841
changeMap: function() {
2942
if (this.leafletLayer) {

src/components/Nav.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
brand: Object,
5050
maps: Array,
5151
map: Object,
52+
center: Array,
53+
zoom: Number,
5254
},
5355
components: {
5456
Info
@@ -92,8 +94,18 @@
9294
changeMap: function(index) {
9395
this.$emit('changeMap', index)
9496
},
97+
latLonToTile: function(lat, lon, z) {
98+
const rad = Math.PI / 180
99+
const n = Math.pow(2, z)
100+
const x = Math.floor((lon + 180) / 360 * n)
101+
const latRad = lat * rad
102+
const y = Math.floor((1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2 * n)
103+
return { x, y }
104+
},
95105
getBackgroundImage: function(map) {
96-
return map.url.replace(/\{z\}\/\{x\}\/\{y\}/i, '16/35198/21494')
106+
const [lat, lon] = this.center.map(x => parseFloat(x))
107+
const { x, y } = this.latLonToTile(lat, lon, this.zoom)
108+
return map.url.replace(/\{z\}\/\{x\}\/\{y\}/i, `${this.zoom}/${x}/${y}`)
97109
},
98110
getYear: function(map) {
99111
return map.name.split(' ')[1]

0 commit comments

Comments
 (0)