|
249 | 249 |
|
250 | 250 | fetch(`{{ point_endpoint|safe }}`.replace('{lat}', lat).replace('{lon}', lng)) |
251 | 251 | .then(res => { |
| 252 | + if (res.status === 204) return null; |
252 | 253 | if (res.ok) return res.json(); |
253 | 254 |
|
254 | 255 | return res.json().then(errorData => { |
|
259 | 260 | }) |
260 | 261 | }) |
261 | 262 | .then(data => { |
262 | | - const formatPopupContent = (data) => { |
263 | | - let html = '<div style="max-width: 250px;">'; |
264 | | - |
265 | | - html += `<p><strong>Coordinates:</strong> ${lat}, ${lng}</p>`; |
| 263 | + if (data === null) { |
| 264 | + popup.setContent(`<p>No data at ${lat}, ${lng}</p>`); |
| 265 | + return; |
| 266 | + } |
266 | 267 |
|
267 | | - // single band case - just show the value |
268 | | - if (data.band_names.length === 1) { |
269 | | - const value = data.values[0] !== null ? data.values[0] : 'No data'; |
270 | | - html += `<p><strong>Value:</strong> ${value}</p>`; |
| 268 | + const renderBandTable = (bandNames, values) => { |
| 269 | + if (bandNames.length === 1) { |
| 270 | + const value = values[0] !== null ? values[0] : 'No data'; |
| 271 | + return `<p><strong>Value:</strong> ${value}</p>`; |
271 | 272 | } |
272 | | - // multiple bands case - show in a table |
273 | | - else { |
274 | | - html += '<table style="width: 100%; border-collapse: collapse;">'; |
275 | | - html += '<tr><th style="text-align: left; padding: 1px; border-bottom: 1px solid #ddd;">Band</th>' + |
276 | | - '<th style="text-align: right; padding: 1px; border-bottom: 1px solid #ddd;">Value</th></tr>'; |
277 | | - |
278 | | - for (let i = 0; i < data.band_names.length; i++) { |
279 | | - const value = data.values[i] !== null ? data.values[i] : 'No data'; |
280 | | - html += `<tr> |
281 | | - <td style="text-align: left; padding: 1px;">${data.band_names[i]}</td> |
282 | | - <td style="text-align: right; padding: 1px;">${value}</td> |
283 | | - </tr>`; |
284 | | - } |
| 273 | + let html = '<table style="width: 100%; border-collapse: collapse;">'; |
| 274 | + html += '<tr>' |
| 275 | + + '<th style="text-align: left; padding: 1px; border-bottom: 1px solid #ddd;">Band</th>' |
| 276 | + + '<th style="text-align: right; padding: 1px; border-bottom: 1px solid #ddd;">Value</th>' |
| 277 | + + '</tr>'; |
| 278 | + for (let i = 0; i < bandNames.length; i++) { |
| 279 | + const value = values[i] !== null ? values[i] : 'No data'; |
| 280 | + html += `<tr> |
| 281 | + <td style="text-align: left; padding: 1px;">${bandNames[i]}</td> |
| 282 | + <td style="text-align: right; padding: 1px;">${value}</td> |
| 283 | + </tr>`; |
| 284 | + } |
| 285 | + html += '</table>'; |
| 286 | + return html; |
| 287 | + }; |
285 | 288 |
|
286 | | - html += '</table>'; |
| 289 | + const formatPopupContent = (data) => { |
| 290 | + let html = `<div style="max-width: 250px;"> |
| 291 | + <p><strong>Coordinates:</strong> ${lat}, ${lng}</p>`; |
| 292 | + |
| 293 | + if (data.values !== undefined) { |
| 294 | + // TilerFactory shape: flat band list |
| 295 | + html += renderBandTable(data.band_names, data.values); |
| 296 | + } else if (data.assets !== undefined) { |
| 297 | + // MosaicTilerFactory shape: one entry per asset |
| 298 | + for (const asset of data.assets) { |
| 299 | + html += renderBandTable(asset.band_names, asset.values); |
| 300 | + } |
287 | 301 | } |
288 | 302 |
|
289 | 303 | html += '</div>'; |
|
0 commit comments