-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/gee recent imagery #3331
Changes from 37 commits
06116bd
48b6baa
3f595f7
6d66bca
16d4251
12f84ac
524b6cf
1b473af
d20bf72
cee3a79
30cae08
10f8e2f
ce557b9
1393971
5effe0c
ae906a1
971f03a
aa7b5db
e3f974b
71f3002
1cd6cac
92e32a8
2d19473
cb790db
d48a293
74fc679
489e772
850c0eb
7a20f08
64fa30e
562c258
62900dd
dd7e3aa
d2918dd
5db2e47
1eddc21
6e2b39f
f5b872d
9434f02
72b1157
47475c3
fbb4d7e
a8b44ac
00293e9
089c40b
f6dd01b
96af7f8
0243dce
d9e61e3
841e676
4dc5477
623e905
1a1a9e6
16a7d60
ced029e
e4a0dfb
5e5b68e
c48422a
165f73b
05e5daa
c24aea4
2e0fcdf
75ced66
36c5498
5199fa4
f8b9b49
134cc92
9b3a6b9
f4c66b3
96774fd
0308580
afa2b00
4c5018a
aade8c4
fccdb49
59b4f00
31831ef
67ae5ce
45e2082
6219ecc
f49a1cf
06e7435
ec9e06b
30b8f45
065c275
65d9e72
7120a34
07e74fd
eeef9c0
c032cd6
769aa99
524823a
94cf921
5be9191
5ea848a
3a09048
7340aab
700c000
f8797cd
f77e931
b370b60
cd80c2a
ec7da10
7d4f802
d750752
051c6ce
e30a32a
176e5d8
1e97776
bcf5044
fc67b85
7362952
61a61ec
d8502cd
4aaad0c
681ef4a
5924ff2
16efcb4
51b88c2
053e371
512575e
47bb76e
d70c932
8b36ab9
cc00512
2c007d0
e8c4201
97e938d
0a10a73
61c4eb7
3bea097
30d05c2
17314eb
9bea9a7
814061a
f942867
91bad73
cb6ef87
4add537
c0727f9
38e12c2
07b2321
5999327
854a1aa
4754f42
a80cbe2
ebee66c
0c4d835
31c3495
65e4f15
9328a58
e419968
d5cacf8
b4cd627
49c093d
53e15fb
6aeebe6
d58d461
26e9ceb
0ce9c3c
2d5f7fb
97224f2
7ae40ca
2c5defb
851c6a6
679cc18
460a8fb
20c47db
3dde8e1
5fccbd0
f859b0e
08208e7
60a36c9
a7ebe8d
221a9aa
2311f79
f729883
5442b3d
2a805bb
754c7c2
1e9fc1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* 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.setSentinel(this.view.getParams()); | ||
} | ||
} | ||
}, | ||
{ | ||
'Layer/add': function(slug) { | ||
if (slug === 'sentinel_tiles') { | ||
window.dispatchEvent(new Event('isRecentImageryActivated')); | ||
} | ||
} | ||
} | ||
], | ||
|
||
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.setSentinel(this.view.getParams()); | ||
mps.publish('Layer/update', [name]); | ||
}, | ||
|
||
setSentinel: function(value) { | ||
if (!!value) { | ||
value = btoa(JSON.stringify(value)); | ||
} | ||
|
||
this.status.set('recentImagery', value); | ||
this.publishSentinel(); | ||
}, | ||
|
||
publishSentinel: function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
mps.publish('Place/update', [{ go: false }]); | ||
}, | ||
|
||
getPlaceParams: function() { | ||
return { | ||
recentImagery: this.status.get('recentImagery') | ||
}; | ||
} | ||
}); | ||
|
||
return ReactMapMiddlePresenter; | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
define([ | ||
'Class', | ||
'uri', | ||
'bluebird', | ||
'map/services/DataService' | ||
], function(Class, UriTemplate, Promise, ds) { | ||
|
||
/* eslint-disable */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this service for the sentinel tiles inside the backbone app? Is this due to the react implementation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After review, delete this file. It has no friends. |
||
define(['Class', 'uri', 'bluebird', 'map/services/DataService'], function( | ||
Class, | ||
UriTemplate, | ||
Promise, | ||
ds | ||
) { | ||
'use strict'; | ||
|
||
var GET_REQUEST_SENTINEL_TILES_ID = 'SentinelService:getTiles'; | ||
|
||
var APIURL = 'https://staging-api.globalforestwatch.org/v1'; | ||
var APIURL = 'https://production-api.globalforestwatch.org/v1'; | ||
|
||
var APIURLS = { | ||
'getTiles': '/sentinel-tiles?lat={lat}&lon={lon}&start={start}&end={end}' | ||
getTiles: '/sentinel-tiles?lat={lat}&lon={lon}&start={start}&end={end}' | ||
}; | ||
|
||
var SentinelService = Class.extend({ | ||
|
@@ -21,46 +21,48 @@ define([ | |
}, | ||
|
||
getTiles: function(lat, lon, start, end) { | ||
return new Promise(function(resolve, reject) { | ||
var url = new UriTemplate(APIURLS.getTiles).fillFromObject({ | ||
lat: lat, | ||
lon: lon, | ||
start: start, | ||
end: end | ||
}); | ||
return new Promise( | ||
function(resolve, reject) { | ||
var url = new UriTemplate(APIURLS.getTiles).fillFromObject({ | ||
lat: lat, | ||
lon: lon, | ||
start: start, | ||
end: end | ||
}); | ||
|
||
var requestId = GET_REQUEST_SENTINEL_TILES_ID + '_' + lat + '_' + lon; | ||
this.defineRequest( | ||
requestId, | ||
APIURL + url, | ||
{ type: 'persist', duration: 1, unit: 'days' } | ||
); | ||
var requestId = GET_REQUEST_SENTINEL_TILES_ID + '_' + lat + '_' + lon; | ||
this.defineRequest(requestId, APIURL + url, { | ||
type: 'persist', | ||
duration: 1, | ||
unit: 'days' | ||
}); | ||
|
||
var requestConfig = { | ||
resourceId: requestId, | ||
success: function(res, status) { | ||
resolve(res.data, status); | ||
}, | ||
error: function(errors) { | ||
reject(errors); | ||
} | ||
}; | ||
var requestConfig = { | ||
resourceId: requestId, | ||
success: function(res, status) { | ||
resolve(res.data, status); | ||
}, | ||
error: function(errors) { | ||
reject(errors); | ||
} | ||
}; | ||
|
||
this.abortRequest(requestId); | ||
this.currentRequest[requestId] = ds.request(requestConfig); | ||
}.bind(this)); | ||
this.abortRequest(requestId); | ||
this.currentRequest[requestId] = ds.request(requestConfig); | ||
}.bind(this) | ||
); | ||
}, | ||
|
||
defineRequest: function (id, url, cache) { | ||
defineRequest: function(id, url, cache) { | ||
ds.define(id, { | ||
cache: cache, | ||
url: url, | ||
type: 'GET', | ||
dataType: 'json', | ||
contentType: 'application/json; charset=utf-8', | ||
decoder: function ( data, status, xhr, success, error ) { | ||
if ( status === "success" ) { | ||
success( data, xhr ); | ||
decoder: function(data, status, xhr, success, error) { | ||
if (status === 'success') { | ||
success(data, xhr); | ||
} | ||
} | ||
}); | ||
|
@@ -75,9 +77,7 @@ define([ | |
this.currentRequest[request] = null; | ||
} | ||
} | ||
|
||
}); | ||
|
||
return new SentinelService(); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable */ | ||
define( | ||
[ | ||
'underscore', | ||
'handlebars', | ||
'enquire', | ||
'moment', | ||
'mps', | ||
'cookie', | ||
'picker', | ||
'pickadate', | ||
'map/presenters/ReactMapMiddlePresenter' | ||
], | ||
function( | ||
_, | ||
Handlebars, | ||
enquire, | ||
moment, | ||
mps, | ||
Cookies, | ||
picker, | ||
pickadate, | ||
Presenter | ||
) { | ||
'use strict'; | ||
|
||
var SelectedDates = Backbone.Model.extend({}); | ||
|
||
var ReactMapMiddleView = Backbone.View.extend({ | ||
el: '#react-map', | ||
|
||
initialize: function(map) { | ||
this.presenter = new Presenter(this); | ||
this.map = map; | ||
this.previousZoom; | ||
this.selectedDates = new SelectedDates({ | ||
startDateUC: moment().format('DD-MM-YYYY'), | ||
endDateUC: moment() | ||
.subtract(3, 'month') | ||
.format('DD-MM-YYYY') | ||
}); | ||
this.params = {}; | ||
}, | ||
|
||
toggleLayer: function(slug, params) { | ||
this.params = params; | ||
this.presenter.toggleLayer(slug); | ||
}, | ||
|
||
updateLayer: function(slug, params) { | ||
this.params = params; | ||
this.presenter.updateLayer(slug); | ||
}, | ||
|
||
getParams: function(e) { | ||
return this.params; | ||
}, | ||
|
||
fillParams: function(params) { | ||
this.params = params; | ||
} | ||
}); | ||
|
||
return ReactMapMiddleView; | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to recent imagery for consitency