-
Notifications
You must be signed in to change notification settings - Fork 1
/
layer-interaction.js
86 lines (86 loc) · 2.54 KB
/
layer-interaction.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
function LayerInteraction(tiles, map, order, hoverCallback, clickCallback){
this.map = map;
this.tiles = tiles;
this.layer = new wax.leaf.connector(tiles);
this.interaction = wax.leaf.interaction();
this.hidden = true;
this.order = order;
this.clickCallback = clickCallback !== undefined ? clickCallback : undefined;
this.hoverCallback = hoverCallback !== undefined ? hoverCallback : undefined;
this.show();
};
LayerInteraction.prototype = {};
LayerInteraction.objects = {};
LayerInteraction.prototype.setHidden = function(){
this.hidden = !this.hidden;
};
LayerInteraction.prototype.hide = function(){
if(!this.hidden){
this.rmInteraction();
this.rmLayer();
this.setHidden();
}
};
LayerInteraction.prototype.show = function(){
if(this.hidden){
this.addLayer();
this.setInteraction();
this.setHidden();
}
};
LayerInteraction.prototype.onHover = function(o){
if (o.e.type === 'mousemove') {
if(this.hoverCallback !== undefined){
this.hoverCallback(o.data);
} else {
console.log(o.data);
}
}
};
LayerInteraction.prototype.onClick = function(o){
if(o.e.type === 'click'){
if(this.clickCallback !== undefined){
this.clickCallback(o.data);
} else {
var marker = new L.Marker(this.map.mouseEventToLatLng(o.e));
this.map.addLayer(marker);
marker.bindPopup(o.formatter({ format: 'teaser' }, o.data)).openPopup();
}
}
};
LayerInteraction.prototype.setInteraction = function(){
var me = this;
if(me.tiles.grids !== undefined){
me.interaction.map(me.map)
.tilejson(me.tiles)
.on('on', function(o){
me.onHover(o);
me.onClick(o);
});
}
};
LayerInteraction.prototype.rmInteraction = function(){
this.interaction.remove();
};
LayerInteraction.prototype.rmLayer = function(){
this.map.removeLayer(this.layer);
};
LayerInteraction.prototype.addLayer = function(){
this.map.addLayer(this.layer);
};
LayerInteraction.redrawVisibleLayers = function(){
_.each(_.keys(LayerInteraction.objects), function(key){
LayerInteraction.objects[key].rmLayer();
LayerInteraction.objects[key].rmInteraction();
});
var values = _.values(LayerInteraction.objects);
values = _.sortBy(values, function(obj){
return obj.order;
});
_.each(values, function(obj){
if(!obj.hidden){
obj.addLayer();
obj.setInteraction();
}
});
};