forked from r-spatial/leafgl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddGlifyPoints.js
116 lines (104 loc) · 3.02 KB
/
addGlifyPoints.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
LeafletWidget.methods.addGlifyPoints = function(data, cols, popup, opacity, radius, group, layerId,
hover, hoverWait, sensitivity, sensitivityHover, pane) {
const map = this;
// colors
var clrs;
if (cols.length === 1) {
clrs = cols[0];
} else {
clrs = function(index, point) { return cols[index]; };
}
// radius
var rad;
if (typeof(radius) === "number") {
rad = radius;
} else {
rad = function(index, point) { return radius[index]; };
}
/*
var pop;
if (popup) {
if (popup === true) {
pop = function (e, feature) {
var popUp = '<pre>'+JSON.stringify(feature.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>';
if (map.hasLayer(pointslayer.layer)) {
L.popup({ maxWidth: 2000 })
.setLatLng(e.latlng)
.setContent(popUp)
.openOn(map);
}
};
} else {
pop = function (e, feature) {
if (map.hasLayer(pointslayer.layer)) {
L.popup({ maxWidth: 2000 })
.setLatLng(e.latlng)
.setContent(feature.properties[[popup]].toString())
.openOn(map);
}
};
}
} else {
pop = null;
}
var pointslayer = L.glify.points({
map: map,
click: pop,
data: data,
color: clrs,
opacity: opacity,
size: size,
className: group
});
map.layerManager.addLayer(pointslayer.layer, null, null, group);
*/
var mouse_event_pts = function(e, point, addpopup, popup, event) {
var etype = event === "hover" ? "_glify_mouseover" : "_glify_click";
if (map.hasLayer(pointslayer.layer)) {
var idx = data.findIndex(k => k==point);
var content = popup ? popup[idx].toString() : null;
if (HTMLWidgets.shinyMode) {
Shiny.setInputValue(map.id + etype, {
id: layerId ? layerId[idx] : idx+1,
lat: point[0],
lng: point[1],
data: content
});
}
if (addpopup) {
var pops = L.popup({ maxWidth: 2000 })
.setLatLng(e.latlng)
.setContent(content);
map.layerManager.removeLayer("leafglpopups");
map.layerManager.addLayer(pops, "popup", "leafglpopups");
}
}
}
var pop = function (e, point, xy) {
mouse_event_pts(e, point, popup !== null, popup, "click");
};
var hov = function (e, point, xy) {
mouse_event_pts(e, point, hover !== null, hover, "hover");
};
var pointslayer = L.glify.points({
map: map,
click: pop,
hover: hov,
hoverWait: hoverWait,
sensitivityHover: sensitivityHover,
sensitivity: sensitivity,
data: data,
color: clrs,
opacity: opacity,
size: rad,
className: group,
pane: pane
});
map.layerManager.addLayer(pointslayer.layer, "glify", layerId, group);
};
LeafletWidget.methods.removeGlPoints = function(layerId) {
this.layerManager.removeLayer("glify", layerId);
};
LeafletWidget.methods.clearGlLayers = function() {
this.layerManager.clearLayers("glify");
};