Skip to content

Commit 546eb3d

Browse files
committed
fix javascript linting issues
1 parent 3e1083a commit 546eb3d

File tree

1 file changed

+74
-37
lines changed

1 file changed

+74
-37
lines changed

src/main.js

Lines changed: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const addMonumentsByBounds = false
2020
const map = L.map('map', { zoomControl: false }).setView(center, zoomLevelInitial)
2121
const markerClusterGroup = L.markerClusterGroup({
2222
zoomToBoundsOnClick: true,
23-
disableClusteringAtZoom: 19,
23+
disableClusteringAtZoom: 19
2424
})
2525
let zoomControl = L.control.zoom({ position: 'bottomright' }).addTo(map)
2626

@@ -29,14 +29,14 @@ const defaultIcon = L.icon({
2929
iconUrl: markerDefault,
3030
iconSize: [30, 36],
3131
iconAnchor: [15, 36],
32-
tooltipAnchor: [0, -37],
32+
tooltipAnchor: [0, -37]
3333
})
3434

3535
const selectedIcon = L.icon({
3636
iconUrl: markerSelected,
3737
iconSize: [30, 36],
3838
iconAnchor: [15, 36],
39-
tooltipAnchor: [0, -37],
39+
tooltipAnchor: [0, -37]
4040
})
4141

4242
// State variables
@@ -56,14 +56,17 @@ function isValidUrl(string) {
5656
try {
5757
const url = new URL(string)
5858
return url.protocol === 'http:' || url.protocol === 'https:'
59-
} catch {
59+
}
60+
catch {
6061
return false
6162
}
6263
}
6364

6465
function findMarkerById(id) {
6566
const marker = markerMap.get(id)
66-
if (marker && typeof marker.setIcon === 'function') return marker
67+
if (marker && typeof marker.setIcon === 'function') {
68+
return marker
69+
}
6770
console.warn(`Marker with ID ${id} is not a valid Leaflet marker.`)
6871
return null
6972
}
@@ -73,15 +76,21 @@ function setSelectedMarker(marker) {
7376
console.error('Invalid marker passed to setSelectedMarker:', marker)
7477
return
7578
}
76-
if (previousSelectedMarker) previousSelectedMarker.setIcon(defaultIcon)
79+
if (previousSelectedMarker) {
80+
previousSelectedMarker.setIcon(defaultIcon)
81+
}
7782
marker.setIcon(selectedIcon)
7883
previousSelectedMarker = marker
7984
}
8085

8186
// Map-related functions
8287
function addMonumentsToMap(data, fetchAdditionalMonuments, zoomLevel) {
83-
if (currentLayer) currentLayer.removeLayer(currentLayer)
84-
else currentLayer = markerClusterGroup
88+
if (currentLayer) {
89+
currentLayer.removeLayer(currentLayer)
90+
}
91+
else {
92+
currentLayer = markerClusterGroup
93+
}
8594

8695
const geojsonGroup = L.geoJSON(data, {
8796
onEachFeature(feature, layer) {
@@ -96,9 +105,9 @@ function addMonumentsToMap(data, fetchAdditionalMonuments, zoomLevel) {
96105
pointToLayer(feature, latlng) {
97106
return L.marker(latlng, { icon: defaultIcon }).bindTooltip(feature.properties.label, {
98107
permanent: false,
99-
direction: 'top',
108+
direction: 'top'
100109
})
101-
},
110+
}
102111
})
103112

104113
currentLayer.addLayer(geojsonGroup)
@@ -120,24 +129,31 @@ function handleWindowSize() {
120129
async function fetchJsonData(url) {
121130
try {
122131
const response = await fetch(url, { method: 'GET' })
123-
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`)
132+
if (!response.ok) {
133+
throw new Error(`HTTP error! Status: ${response.status}`)
134+
}
124135
return await response.json()
125-
} catch (error) {
136+
}
137+
catch (error) {
126138
console.error('Fetch error:', error)
127139
return null
128140
}
129141
}
130142

131-
async function fetchBlob(url, monumentFunction) {
132-
if (!url || typeof url !== 'string') return
143+
function fetchBlob(url, monumentFunction) {
144+
if (!url || typeof url !== 'string') {
145+
return
146+
}
133147

134148
const container = document.querySelector('#detailImage')
135149
container.innerHTML = ''
136150

137151
const imageElement = document.createElement('img')
138152
imageElement.src = url
139153

140-
imageElement.onload = () => { imageElement.classList.add('loaded') }
154+
imageElement.onload = () => {
155+
imageElement.classList.add('loaded')
156+
}
141157
// imageElement.onerror = () => { container.classList.add('hidden') }
142158
imageElement.setAttribute('alt', monumentFunction || 'Denkmalschutz')
143159

@@ -160,7 +176,7 @@ async function fetchMonumentPointsByBounds() {
160176
xmin: bounds.getWest(),
161177
ymin: bounds.getSouth(),
162178
xmax: bounds.getEast(),
163-
ymax: bounds.getNorth(),
179+
ymax: bounds.getNorth()
164180
}
165181

166182
const url = `${process.env.PARCEL_BASE_API_URL}/monument/v1/bounds?xmin=${bbox.xmin}&ymin=${bbox.ymin}&xmax=${bbox.xmax}&ymax=${bbox.ymax}`
@@ -170,7 +186,9 @@ async function fetchMonumentPointsByBounds() {
170186
if (previousSelectedMarker) {
171187
const previousMarkerId = previousSelectedMarker.feature.id
172188
const newSelectedMarker = findMarkerById(previousMarkerId)
173-
if (newSelectedMarker) setSelectedMarker(newSelectedMarker)
189+
if (newSelectedMarker) {
190+
setSelectedMarker(newSelectedMarker)
191+
}
174192
}
175193
}
176194

@@ -182,15 +200,19 @@ async function fetchMonumentPointsByPosition(lat, lng) {
182200
if (previousSelectedMarker) {
183201
const previousMarkerId = previousSelectedMarker.feature.id
184202
const newSelectedMarker = findMarkerById(previousMarkerId)
185-
if (newSelectedMarker) setSelectedMarker(newSelectedMarker)
203+
if (newSelectedMarker) {
204+
setSelectedMarker(newSelectedMarker)
205+
}
186206
}
187207
}
188208

189209
async function fetchMonumentDetailBySlug(slug) {
190210
const url = `${process.env.PARCEL_BASE_API_URL}/monument/v1/details?slug=${slug}`
191211
const data = await fetchJsonData(url)
192212

193-
if (!data || !data[0]) return
213+
if (!data || !data[0]) {
214+
return
215+
}
194216

195217
const geoJsonData = {
196218
type: 'FeatureCollection',
@@ -199,9 +221,9 @@ async function fetchMonumentDetailBySlug(slug) {
199221
type: 'Feature',
200222
id: data[0].id,
201223
geometry: data[0].geojson,
202-
properties: { label: data[0].label, slug: data[0].slug },
203-
},
204-
],
224+
properties: { label: data[0].label, slug: data[0].slug }
225+
}
226+
]
205227
}
206228

207229
if (isValidUrl(data[0].photo_link)) {
@@ -218,18 +240,22 @@ async function fetchMonumentDetailBySlug(slug) {
218240
await fetchMonumentPointsByBounds()
219241
matchingMarker = findMarkerById(data[0].id)
220242
}
221-
if (matchingMarker) setSelectedMarker(matchingMarker)
222-
223-
return data
243+
if (matchingMarker) {
244+
setSelectedMarker(matchingMarker)
245+
}
224246
}
225247

226248
async function fetchMonumentDetailById(id) {
227249
const url = `${process.env.PARCEL_BASE_API_URL}/monument/v1/details?monument_id=${id}`
228250
const data = await fetchJsonData(url)
229251

230-
if (!data || !data[0]) return
252+
if (!data || !data[0]) {
253+
return
254+
}
231255

232-
if (isValidUrl(data[0].photo_link)) fetchBlob(data[0].photo_link, data[0].monument_function)
256+
if (isValidUrl(data[0].photo_link)) {
257+
fetchBlob(data[0].photo_link, data[0].monument_function)
258+
}
233259

234260
navigateTo(data[0].slug)
235261
renderMonumentMeta(data[0])
@@ -249,7 +275,9 @@ function renderMonumentMeta(data) {
249275
<li class="last-of-type:pb-2 pt-2"><strong>Beschreibung</strong><br>${description}</li>
250276
`
251277

252-
if (monument_scope) detailOutput += `<li class="last-of-type:pb-2 pt-2"><strong>Schutzumfang</strong><br>${monument_scope}</li>`
278+
if (monument_scope) {
279+
detailOutput += `<li class="last-of-type:pb-2 pt-2"><strong>Schutzumfang</strong><br>${monument_scope}</li>`
280+
}
253281
if (last_update) {
254282
const date = new Date(last_update)
255283
const formattedDate = `${String(date.getDate()).padStart(2, '0')}.${String(date.getMonth() + 1).padStart(2, '0')}.${date.getFullYear()}`
@@ -274,7 +302,9 @@ function cleanMonumentMeta() {
274302
}
275303

276304
function navigateTo(screen, updateHistory = true) {
277-
if (updateHistory) history.pushState({ screen }, '', screen === 'home' ? '/' : `/${screen}`)
305+
if (updateHistory) {
306+
history.pushState({ screen }, '', screen === 'home' ? '/' : `/${screen}`)
307+
}
278308
updateScreen(screen)
279309
}
280310

@@ -289,7 +319,7 @@ window.onload = async () => {
289319
L.tileLayer('https://tiles.oklabflensburg.de/sgm/{z}/{x}/{y}.png', {
290320
maxZoom: 20,
291321
tileSize: 256,
292-
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="dc:rights">OpenStreetMap</a> contributors',
322+
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="dc:rights">OpenStreetMap</a> contributors'
293323
}).addTo(map)
294324

295325
map.on('moveend', fetchMonumentPointsByBounds)
@@ -314,25 +344,29 @@ window.onload = async () => {
314344
map.setView([position.coords.latitude, position.coords.longitude], 16)
315345
},
316346
(error) => {
317-
console.error('Error obtaining geolocation:', error.message);
347+
console.error('Error obtaining geolocation:', error.message)
318348
}
319-
);
320-
} else {
321-
console.error('Geolocation is not supported by this browser.');
349+
)
350+
}
351+
else {
352+
console.error('Geolocation is not supported by this browser.')
322353
}
323354
}
324355
})
325356

326357
const path = decodeURIComponent(window.location.pathname)
327358
const screen = path === '/' ? 'home' : path.slice(1)
328-
if (!history.state) history.replaceState({ screen }, '', path)
359+
if (!history.state) {
360+
history.replaceState({ screen }, '', path)
361+
}
329362

330363
updateScreen(screen)
331364

332365
if (screen === 'home') {
333366
map.setView(center, zoomLevelInitial)
334367
fetchMonumentPointsByBounds()
335-
} else {
368+
}
369+
else {
336370
const data = await fetchMonumentDetailBySlug(screen)
337371
if (data && data[0] && data[0].geojson && data[0].geojson.coordinates) {
338372
const [lng, lat] = data[0].geojson.coordinates
@@ -346,7 +380,10 @@ window.addEventListener('popstate', (event) => {
346380
if (screen === 'home') {
347381
cleanMonumentMeta()
348382
fetchMonumentPointsByBounds()
349-
} else fetchMonumentDetailBySlug(screen)
383+
}
384+
else {
385+
fetchMonumentDetailBySlug(screen)
386+
}
350387
})
351388

352389
window.addEventListener('resize', handleWindowSize)

0 commit comments

Comments
 (0)