-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_widget.html
More file actions
71 lines (61 loc) · 2.15 KB
/
map_widget.html
File metadata and controls
71 lines (61 loc) · 2.15 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
<script>
const imageUrl = 'https://lh3.googleusercontent.com/8aWWVAIbTr7EgIDQdyWsxNOKgDMkguFl-uZn70LMbFtAHnrzwMXDLA2f2ALOpyuZl0Cbm7h2nd4xUyJ6f354-aqfed7Ad4QF_CXIwCvkZ9rWt0Jb-owMs1z16x61ZwvJRA=w1280';
const API_KEY= 'AIzaSyBI90GBOe6w7jkbMdpIVMlH2owo5qDy5Go';
const SPREADSHEET_ID = '1W-2DvHw0ekdfr5hng2LKxgJe9O80sTjXH0Yrnbi15hU';
const imageOptions = { opacity: 1 };
var bounds = [
[0, 0],
[1, 1]
];
const center = [bounds[1][0] / 2, bounds[1][1] / 2];
const map = L.map('map', { minZoom: 8, maxZoom: 14, crs: L.CRS.Simple, attributionControl: false }).setView(center, 8);
const markers = L.markerClusterGroup();
function initialize() {
const img = new Image();
img.onload = function() {
console.log(`Image dimensions: ${this.width} x ${this.height}`);
console.log(`Aspect Ratio: ${w/h}`);
bounds = [0, 0],[1, w/h]
main();
}
img.src = imageUrl;
}
function main() {
const publicSpreadsheetUrl = `https://sheets.googleapis.com/v4/spreadsheets/${SPREADSHEET_ID}/values/Sheet1?key=${API_KEY}`;
console.log(publicSpreadsheetUrl);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
opacity: 0,
attribution: "Map data © <a href='https://openstreetmap.org'>OpenStreetMap</a> contributors",
}).addTo(map);
L.control.mousePosition({
separator: ', ',
emptyString: 'Unknown',
lngFirst: true,
numDigits: 3,
lngFormatter: function(lng) {
return lng + '°E';
},
latFormatter: function(lat) {
return lat + '°N';
}
}).addTo(map);
Tabletop.init({
key: publicSpreadsheetUrl,
callback: function(data, tabletop) {
for (let i = 0; i < data.length; i++) {
const marker = L.marker([data[i].lat, data[i].lng]).addTo(map);
marker.bindPopup(data[i].name);
}
},
simpleSheet: true
});
map.on('click', function(e) {
console.log('You clicked the map at ' + e.latlng.toString());
});
L.imageOverlay(imageUrl, bounds, imageOptions).addTo(map);
map.fitBounds(bounds);
}
window.onload = function() {
initialize();
}
</script>