forked from mapbox/weekend-picks-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markers.js
88 lines (71 loc) · 2.56 KB
/
markers.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
var picks = {};
picks.removed = []; // List of markers that have been removed from map (filtered)
picks.symbols = []; // List of all unique symbols
picks.selected = null;
picks.start = function(url) {
// Create marker layer
picks.layer = mmg().factory(simplestyle_factory).url(url, function(feat, l) {
// Add interaction
mmg_interaction(l);
// Create a list of all unique marker symbols
$.each(
$.map(picks.layer.markers(), function(m) {
return m.data.properties['marker-symbol'];
}), function(index, s) {
if ($.inArray(s, picks.symbols) < 0) picks.symbols.push(s);
});
// Set up all button
var all = $('#null');
all.click(function() {
if (picks.selected) {
// Deselect other button
$('#' + picks.selected).removeClass('selected');
// Select all button
all.addClass('selected');
picks.selected = null;
picks.show(picks.selected);
}
});
// Create a symbol based filter
var container = $('#markerfilters');
$.each(picks.symbols, function(index, s) {
var el = $(document.createElement('a'))
.addClass('markerfilter')
.attr('id', s)
.css('background-image', 'url(http://a.tiles.mapbox.com/v3/marker/pin-l-'+s+'+000000.png)');
el.click(function(a) {
if (picks.selected == s) {
picks.selected = null;
$('#null').addClass('selected');
el.removeClass('selected');
} else {
$('#' + picks.selected).removeClass('selected');
el.addClass('selected');
picks.selected = s;
}
picks.show(picks.selected);
return false;
});
container.append(el);
});
});
MM_map.addLayer(picks.layer);
}
// Set all markers with specified symbol to be shown
picks.show = function(s) {
// re-add removed markers
$.each(picks.removed, function(index, m) {
picks.layer.add(m);
});
picks.removed = [];
if (s) {
// show markers in category
picks.removed = $.grep(picks.layer.markers(), function(m) {
return m.data.properties['marker-symbol'] != s;
});
$.each(picks.removed, function(index, m) {
picks.layer.remove(m);
});
}
picks.layer.draw();
}