-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
81 lines (56 loc) · 1.48 KB
/
Copy pathapp.js
File metadata and controls
81 lines (56 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const map = L.map('map', {
preferCanvas: true
}).setView([39.5, -98.35], 4);
L.tileLayer(
'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png',
{
attribution:
'© OpenStreetMap contributors © CARTO',
subdomains: 'abcd',
maxZoom: 20,
updateWhenIdle: true
}
).addTo(map);
//Cloudflare worker proxy because CORS
const API_URL =
'https://cold-limit-e359.jakebutler.workers.dev/';
async function loadPourpoints() {
try {
const response = await fetch(API_URL);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
console.log(data);
const layer = L.geoJSON(data, {
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, {
radius: 5,
fillColor: '#0077ff',
color: '#ffffff',
weight: 1,
fillOpacity: 0.8
});
},
onEachFeature: function(feature, layer) {
const props = feature.properties || {};
let html = '<div>';
for (const [key, value] of Object.entries(props)) {
html += `<b>${key}</b>: ${value}<br>`;
}
html += '</div>';
layer.bindPopup(html);
}
}).addTo(map);
map.fitBounds(layer.getBounds(), {
padding: [20, 20]
});
} catch (err) {
console.error(err);
alert(
'Failed to load pourpoints.\n' +
'You may need a CORS proxy.'
);
}
}
loadPourpoints();