forked from r-spatial/leafgl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddGlifyPolygons.js
72 lines (61 loc) · 1.79 KB
/
addGlifyPolygons.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
LeafletWidget.methods.addGlifyPolygons = function(data, cols, popup, label, opacity, group, layerId, pane) {
var map = this;
var clrs;
if (cols.length === 1) {
clrs = cols[0];
} else {
clrs = function(index, feature) { return cols[index]; };
}
var click_event = function(e, feature, addpopup, popup) {
if (map.hasLayer(shapeslayer.layer)) {
var idx = data.features.findIndex(k => k==feature);
if (HTMLWidgets.shinyMode) {
Shiny.setInputValue(map.id + "_glify_click", {
id: layerId ? layerId[idx] : idx+1,
group: Object.values(shapeslayer.layer._eventParents)[0].groupname,
lat: e.latlng.lat,
lng: e.latlng.lng,
data: feature.properties
});
}
if (addpopup) {
var content = popup === true ? json2table(feature.properties) : popup[idx].toString();
L.popup({ maxWidth: 2000 })
.setLatLng(e.latlng)
.setContent(content)
.openOn(map);
//.openPopup();
}
}
};
var pop = function (e, feature) {
click_event(e, feature, popup !== null, popup);
};
// var label = "testtest";
let tooltip = new L.Tooltip();
var hover_event = function(e, feature, addlabel, label) {
if (map.hasLayer(shapeslayer.layer)) {
if (addlabel) {
tooltip
.setLatLng(e.latlng)
.setContent(feature.properties[[label]].toString())
.addTo(map);
}
}
}
var hvr = function(e, feature) {
hover_event(e, feature, label !== null, label);
}
var shapeslayer = L.glify.shapes({
map: map,
click: pop,
hover: hvr,
data: data,
color: clrs,
opacity: opacity,
className: group,
border: true,
pane: pane
});
map.layerManager.addLayer(shapeslayer.layer, "glify", layerId, group);
};