-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaf-ilayer.js
51 lines (43 loc) · 1.57 KB
/
leaf-ilayer.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
import Ember from 'ember';
import LeafBaseComponent from '../components/leaf-base';
import MapPromiseMixin from '../mixins/leaf-map-promise';
import LayerGroupPromiseMixin from '../mixins/leaf-layer-group-promise';
export default LeafBaseComponent.extend(MapPromiseMixin, LayerGroupPromiseMixin, {
layer: null,
clickable: Ember.computed.notEmpty('layerEvents'),
actionPayload: null,
layerEvents: [],
layerEventsArray: Ember.computed('layerEvents', function() {
var events = this.get('layerEvents');
return Ember.typeOf(events) === 'string' ? events.w() : events;
}).readOnly(),
layerEventHandler: Ember.computed(function() {
return function(event) {
if (this.get('clickable')) {
this.sendAction('layer' + Ember.String.capitalize(event.type), this.get('actionPayload') || this, event);
}
}.bind(this);
}),
attach: function() {
var self = this;
return this.get('layerGroupPromise').then(function(layerGroup) {
var layer = self.get('layer');
var eventHandler = self.get('layerEventHandler');
layerGroup.addLayer(layer);
self.get('layerEventsArray').forEach(function(eventName){
layer.on(eventName, eventHandler);
});
});
},
detach: function() {
var self = this;
return this.get('layerGroupPromise').then(function(layerGroup) {
var layer = self.get('layer');
var eventHandler = self.get('layerEventHandler');
self.get('layerEventsArray').forEach(function(eventName){
layer.off(eventName, eventHandler);
});
layerGroup.removeLayer(layer);
});
}
});