-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathReactMapMiddlePresenter.js
113 lines (101 loc) · 2.97 KB
/
ReactMapMiddlePresenter.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* eslint-disable */
define(
[
'underscore',
'mps',
'map/presenters/PresenterClass',
'map/services/LayerSpecService'
],
function(_, mps, PresenterClass, layerSpecService) {
'use strict';
var StatusModel = Backbone.Model.extend({
defaults: {
layers: [],
recentImagery: null
}
});
var ReactMapMiddlePresenter = PresenterClass.extend({
init: function(view) {
this.view = view;
this.status = new StatusModel();
this._super();
mps.publish('Place/register', [this]);
},
_subscriptions: [
{
'Place/go': function(place) {
this.status.set('layerSpec', place.layerSpec);
this.status.set('recentImagery', place.params.recentImagery);
var isRecentImageryActivated = !!this.status
.get('layerSpec')
.getLayer({ slug: 'sentinel_tiles' });
if (
isRecentImageryActivated &&
!!this.status.get('recentImagery')
) {
this.view.fillParams(
JSON.parse(atob(place.params.recentImagery))
);
}
}
},
{
'LayerNav/change': function(layerSpec) {
this.status.set('layerSpec', layerSpec);
var isRecentImageryActivated = !!this.status
.get('layerSpec')
.getLayer({ slug: 'sentinel_tiles' });
if (isRecentImageryActivated) {
this.setRecentImagery(this.view.getParams());
}
}
},
{
'Layer/add': function(slug) {
if (slug === 'sentinel_tiles') {
window.dispatchEvent(new Event('isRecentImageryActivated'));
}
}
},
{
'ReactMap/zoom-go-back': function(slug) {
mps.publish('Map/set-zoom', [this.view.previousZoom]);
}
}
],
toggleLayer: function(layerSlug) {
var where = [{ slug: layerSlug }];
layerSpecService.toggle(
where,
_.bind(function(layerSpec) {
mps.publish('LayerNav/change', [layerSpec]);
mps.publish('Place/update', [{ go: false }]);
}, this)
);
},
updateLayer: function(name, params) {
this.setRecentImagery(this.view.getParams());
mps.publish('Layer/update', [name]);
},
setRecentImagery: function(value) {
if (!!value) {
value = btoa(JSON.stringify(value));
}
this.status.set('recentImagery', value);
this.publishRecentImagery();
},
publishRecentImagery: function() {
mps.publish('Place/update', [{ go: false }]);
},
getPlaceParams: function() {
return {
recentImagery: this.status.get('recentImagery')
};
},
notificate: function(id) {
mps.publish('Notification/open', [id]);
}
});
return ReactMapMiddlePresenter;
}
);