@@ -163,7 +163,19 @@ async function fetchMonumentPointsByBounds() {
163163 ymax : bounds . getNorth ( ) ,
164164 }
165165
166- const url = `${ process . env . PARCEL_BASE_API_URL } /monument/v1/geometries?xmin=${ bbox . xmin } &ymin=${ bbox . ymin } &xmax=${ bbox . xmax } &ymax=${ bbox . ymax } `
166+ const url = `${ process . env . PARCEL_BASE_API_URL } /monument/v1/bounds?xmin=${ bbox . xmin } &ymin=${ bbox . ymin } &xmax=${ bbox . xmax } &ymax=${ bbox . ymax } `
167+ const data = await fetchJsonData ( url )
168+ addMonumentsToMap ( data , addMonumentsByBounds , zoomLevelInitial )
169+
170+ if ( previousSelectedMarker ) {
171+ const previousMarkerId = previousSelectedMarker . feature . id
172+ const newSelectedMarker = findMarkerById ( previousMarkerId )
173+ if ( newSelectedMarker ) setSelectedMarker ( newSelectedMarker )
174+ }
175+ }
176+
177+ async function fetchMonumentPointsByPosition ( lat , lng ) {
178+ const url = `${ process . env . PARCEL_BASE_API_URL } /monument/v1/radius?lat=${ lat } &lng=${ lng } `
167179 const data = await fetchJsonData ( url )
168180 addMonumentsToMap ( data , addMonumentsByBounds , zoomLevelInitial )
169181
@@ -175,7 +187,7 @@ async function fetchMonumentPointsByBounds() {
175187}
176188
177189async function fetchMonumentDetailBySlug ( slug ) {
178- const url = `${ process . env . PARCEL_BASE_API_URL } /monument/v1/detail ?slug=${ slug } `
190+ const url = `${ process . env . PARCEL_BASE_API_URL } /monument/v1/details ?slug=${ slug } `
179191 const data = await fetchJsonData ( url )
180192
181193 if ( ! data || ! data [ 0 ] ) return
@@ -223,7 +235,6 @@ async function fetchMonumentDetailById(id) {
223235 renderMonumentMeta ( data [ 0 ] )
224236}
225237
226- // UI-related functions
227238function renderMonumentMeta ( data ) {
228239 const { slug, street, housenumber, postcode, city, last_update, monument_type, description, monument_function, object_number, monument_scope } = data
229240
@@ -294,6 +305,24 @@ window.onload = async () => {
294305 document . querySelector ( '#sidebar' ) . classList . toggle ( 'translate-y-full' )
295306 } )
296307
308+ document . getElementById ( 'geoLocation' ) . addEventListener ( 'change' , function ( event ) {
309+ if ( event . target . name === 'myLocation' && event . target . checked ) {
310+ if ( navigator . geolocation ) {
311+ navigator . geolocation . getCurrentPosition (
312+ ( position ) => {
313+ fetchMonumentPointsByPosition ( position . coords . latitude , position . coords . longitude )
314+ map . setView ( [ position . coords . latitude , position . coords . longitude ] , 16 )
315+ } ,
316+ ( error ) => {
317+ console . error ( 'Error obtaining geolocation:' , error . message ) ;
318+ }
319+ ) ;
320+ } else {
321+ console . error ( 'Geolocation is not supported by this browser.' ) ;
322+ }
323+ }
324+ } )
325+
297326 const path = decodeURIComponent ( window . location . pathname )
298327 const screen = path === '/' ? 'home' : path . slice ( 1 )
299328 if ( ! history . state ) history . replaceState ( { screen } , '' , path )
0 commit comments