-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (49 loc) · 1.4 KB
/
index.js
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
const GLOBAL_OPTIONS = {
color: "blue",
bindPopup: false,
popupContent: "",
};
const addCircularPointToPolyline = (coordinates, map, options) => {
try {
if (coordinates == null) {
throw new Error("[x] Missing required parameter [coordinates].");
}
if (!Array.isArray(coordinates)) {
throw new Error("[x] Coordinates parameter must be an array.");
}
if (!coordinates.length) {
throw new Error("[x] Coordinates can not be an empty array.");
}
if (options.color != null) {
GLOBAL_OPTIONS.color = options.color;
}
if (options.bindPopup) {
GLOBAL_OPTIONS.bindPopup = options.bindPopup;
}
if (options.popupContent) {
GLOBAL_OPTIONS.popupContent = options.popupContent;
}
coordinates.forEach((coordinate) => {
let marker = window.L.marker(
[coordinate.latitude, coordinate.longitude],
{
icon: getPointIcon(),
}
);
if (GLOBAL_OPTIONS.bindPopup) {
marker.bindPopup(GLOBAL_OPTIONS.popupContent);
}
marker.addTo(map);
});
} catch (e) {
console.error(e);
}
};
const getPointIcon = () => {
return window.L.divIcon({
className: "polyline-point",
bgPos: [5, 5],
html: `<div style='background-color:${GLOBAL_OPTIONS.color};width:16px; height:16px; border-radius: 50%'; display: inline-block></div>`,
});
};
export { addCircularPointToPolyline };