Skip to content

Commit

Permalink
Button: Fix URL param passing; Update URL template to use ?map
Browse files Browse the repository at this point in the history
  • Loading branch information
tordans committed Aug 7, 2024
1 parent 1195b93 commit 058d88a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/regions/utils/atlasUrl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const atlasUrl = (region: string, center: [number, number] | number[]) => {
if (region === 'berlin') {
// We have a special case for Berlin where we use a different region with has additional public data from the city administration associated
return `https://radverkehrsatlas.de/regionen/parkraum-berlin?lat=${center[1]}&lng=${center[0]}`
return `https://radverkehrsatlas.de/regionen/parkraum-berlin?map=12/${center[0]}/${center[1]}`
}
return `https://radverkehrsatlas.de/regionen/parkraum?lat=${center[1]}&lng=${center[0]}`
return `https://radverkehrsatlas.de/regionen/parkraum?map=12/${center[0]}/${center[1]}`
}
16 changes: 6 additions & 10 deletions src/pages/regions/[region].astro
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ const { data } = Astro.props
const mapLink = document.getElementById('map')
const params = new URLSearchParams(window.location.search)
const lat = params.get('lat')
const lng = params.get('lat')
const zoom = params.get('zoom')
if (lat && lng && zoom) {
const newUrl = document
.getElementById('map')
.dataset.urlTemplate.replace('2000', lat)
.replace('1000', lng)
.concat('&zoom=', zoom)
mapLink.href = newUrl
}
const lng = params.get('lng')
const zoom = params.get('zoom') || '12'
const newUrl = new URL(document.getElementById('map').dataset.urlTemplate)
newUrl.searchParams.delete('map')
newUrl.searchParams.set('map', `${zoom}/${lng}/${lat}`)
mapLink.href = newUrl.toString()
})
</script>

Expand Down

0 comments on commit 058d88a

Please sign in to comment.