-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarker.js
More file actions
77 lines (70 loc) · 2.01 KB
/
marker.js
File metadata and controls
77 lines (70 loc) · 2.01 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
function getMarker(item, geocoder) {
const searchQuery = item["Address"] + " " + item["City"];
return new Promise((resolve, reject) => {
geocoder.geocode(searchQuery, function (results) {
var r = results[0];
if (r) {
return resolve(L.marker(r.center).bindPopup(r.name));
} else {
// Fallback to only city if street address not found
const backupSearchQuery = item["City"];
geocoder.geocode(backupSearchQuery, function (results) {
var r = results[0];
if (r) {
return resolve(L.marker(r.center).bindPopup(r.name));
} else {
return reject(searchQuery);
}
});
}
});
});
}
let index = -1;
function getMarkerWithGoogleSheetsData(item, geocoder) {
return new Promise((resolve, reject) => {
if (item["Koordinater"]) {
const coordinates = item["Koordinater"].split(",");
if (coordinates[0] && coordinates[1]) {
item["Lat"] = coordinates[0];
item["Lng"] = coordinates[1];
return resolve(
putDetailedMarkerOnMap(item, { lat: item["Lat"], lng: item["Lng"] })
);
}
}
const searchQuery = item["Adress"];
index++;
sleep(1000 * index).then(() => {
geocoder.geocode(searchQuery, function (results) {
var r = results[0];
if (r) {
item.Lat = r.center.lat;
item.Lng = r.center.lng;
return resolve(putDetailedMarkerOnMap(item, r.center));
} else {
return reject(searchQuery);
}
});
});
});
}
function putDetailedMarkerOnMap(item, coordinates) {
return new Promise((resolve, reject) => {
return resolve(
L.marker(coordinates).bindPopup(
"<b>" +
item["Namn"] +
"</b><br/>" +
item["Adress"] +
"<br/><br/>" +
item["Kategori"] +
"<br/><br/>" +
item["Information"]
)
);
});
}
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}