Repository navigation
Expand file tree
/
Copy pathui.js
More file actions
46 lines (38 loc) · 1.67 KB
/
Copy pathui.js
File metadata and controls
46 lines (38 loc) · 1.67 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
if (typeof mapbox === 'undefined') mapbox = {};
mapbox.ui = function(map) {
var ui = {
zoomer: wax.mm.zoomer().map(map).smooth(true),
pointselector: wax.mm.pointselector().map(map),
boxselector: wax.mm.boxselector().map(map),
hash: wax.mm.hash().map(map),
zoombox: wax.mm.zoombox().map(map),
fullscreen: wax.mm.fullscreen().map(map),
legend: wax.mm.legend().map(map),
attribution: wax.mm.attribution().map(map)
};
function unique(x) {
var u = {}, l = [];
for (var i = 0; i < x.length; i++) u[x[i]] = true;
for (var a in u) { if (a) l.push(a); }
return l;
}
ui.refresh = function() {
if (!map) return console && console.error('ui not attached to map');
var attributions = [], legends = [];
for (var i = 0; i < map.layers.length; i++) {
if (map.layers[i].enabled && map.layers[i].tilejson) {
var attribution = map.layers[i].tilejson().attribution;
if (attribution) attributions.push(attribution);
var legend = map.layers[i].tilejson().legend;
if (legend) legends.push(legend);
}
}
var unique_attributions = unique(attributions);
var unique_legends = unique(legends);
ui.attribution.content(unique_attributions.length ? unique_attributions.join('<br />') : '');
ui.legend.content(unique_legends.length ? unique_legends.join('<br />') : '');
ui.attribution.element().style.display = unique_attributions.length ? '' : 'none';
ui.legend.element().style.display = unique_legends.length ? '' : 'none';
};
return ui;
};