diff --git a/forest_monitor/core.py b/forest_monitor/core.py index 75fb0b6..4a07534 100644 --- a/forest_monitor/core.py +++ b/forest_monitor/core.py @@ -14,8 +14,8 @@ class ForestMonitor(): ee.Initialize(settings.EE_CREDENTIALS) # image collection - TREE_CANOPY = ee.ImageCollection('projects/servir-mekong/yearly_primitives_smoothed/tree_canopy') - TREE_HEIGHT = ee.ImageCollection('projects/servir-mekong/yearly_primitives_smoothed/tree_height') + TREE_CANOPY = ee.ImageCollection('projects/servir-mekong/UMD/tree_canopy') + TREE_HEIGHT = ee.ImageCollection('projects/servir-mekong/UMD/tree_height') PRIMARY_FOREST = ee.ImageCollection('projects/servir-mekong/yearly_primitives_smoothed/primary_forest') # geometries @@ -125,7 +125,7 @@ def _apply_tree_canopy_definition(img): return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @@ -134,7 +134,7 @@ def tree_height(self, get_image = False, for_download = False, year = None, - tree_height_definition = 5, + tree_height_definition = 5, ): if not year: @@ -170,7 +170,7 @@ def _apply_tree_height_definition(img): return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @@ -201,14 +201,14 @@ def primary_forest(self, get_image=False, year=None): return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @staticmethod def _get_combined_img_coll(): - years = ee.List.sequence(2000, 2018) + years = ee.List.sequence(2000, 2019) date_ymd = ee.Date.fromYMD def addBands(year): @@ -280,7 +280,7 @@ def forest_gain(self, return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @@ -328,7 +328,7 @@ def forest_loss(self, return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @@ -390,7 +390,7 @@ def forest_change(self, return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @@ -431,7 +431,7 @@ def forest_extend(self, return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @@ -587,7 +587,7 @@ def download_to_drive(self, print ('past %d seconds' % (i * settings.EE_TASK_POLL_FREQUENCY)) i += 1 time.sleep(settings.EE_TASK_POLL_FREQUENCY) - + # Make a copy (or copies) in the user's Drive if the task succeeded state = task.status()['state'] if state == ee.batch.Task.State.COMPLETED: diff --git a/landcover_viewer/core.py b/landcover_viewer/core.py index ebad8b8..2428337 100644 --- a/landcover_viewer/core.py +++ b/landcover_viewer/core.py @@ -525,7 +525,7 @@ def get_landcover(self, classes=range(0, 21), year=2016, download=False): return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @@ -558,7 +558,7 @@ def get_primitive(self, index=0, year=2016, download=False): return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @@ -579,7 +579,7 @@ def get_probability(self, year=2017, download=False): }) return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } # ------------------------------------------------------------------------- @@ -738,5 +738,5 @@ def get_composite(self, year=2017): return { 'eeMapId': str(map_id['mapid']), - 'eeMapToken': str(map_id['token']) + 'eeMapURL': str(map_id['tile_fetcher'].url_format) } diff --git a/landcoverportal/static/app/controllers/forest-monitor-controller.js b/landcoverportal/static/app/controllers/forest-monitor-controller.js index aebdb03..e1ba0b6 100644 --- a/landcoverportal/static/app/controllers/forest-monitor-controller.js +++ b/landcoverportal/static/app/controllers/forest-monitor-controller.js @@ -661,7 +661,7 @@ // Callbacks for Parameters (forest canopy, change, loss etc) var parameterChangeSuccessCallback = function (name, data, slider, message) { MapService.removeGeoJson(map); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, name); + var mapType = MapService.getMapType(name, data.eeMapURL); loadMap(name, mapType); slider.slider('setValue', 1); showSuccessAlert(message); diff --git a/landcoverportal/static/app/controllers/landcover-controller.js b/landcoverportal/static/app/controllers/landcover-controller.js index 6408e64..751fcfa 100644 --- a/landcoverportal/static/app/controllers/landcover-controller.js +++ b/landcoverportal/static/app/controllers/landcover-controller.js @@ -270,6 +270,7 @@ $scope.showLoader = false; }; + /** * Starts the Google Earth Engine application. The main entry point. */ @@ -315,7 +316,7 @@ }; LandCoverService.getLandCoverMap(parameters) .then(function (data) { - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type); + var mapType = MapService.getMapType(type, data.eeMapURL); loadMap(type, mapType); $timeout(function () { showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear); @@ -799,7 +800,7 @@ var type = 'primitivemap'; MapService.removeGeoJson(map); MapService.clearLayer(map, type); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type); + var mapType = MapService.getMapType(type, data.eeMapURL); loadMap(type, mapType); $timeout(function () { showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear); @@ -831,7 +832,7 @@ var type = 'probabilitymap'; MapService.removeGeoJson(map); MapService.clearLayer(map, type); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type); + var mapType = MapService.getMapType(type, data.eeMapURL); var checked = $('#probability-map-checkbox').prop('checked'); loadMap(type, mapType); if (checked) { @@ -866,7 +867,7 @@ var type = 'compositemap'; MapService.removeGeoJson(map); MapService.clearLayer(map, type); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type); + var mapType = MapService.getMapType(type, data.eeMapURL); var checked = $('#composite-map-checkbox').prop('checked'); loadMap(type, mapType); if (checked) { diff --git a/landcoverportal/static/app/controllers/myanmar-fra-controller.js b/landcoverportal/static/app/controllers/myanmar-fra-controller.js index d670dac..d35b72f 100644 --- a/landcoverportal/static/app/controllers/myanmar-fra-controller.js +++ b/landcoverportal/static/app/controllers/myanmar-fra-controller.js @@ -265,7 +265,7 @@ LandCoverService.getLandCoverMap(parameters) .then(function (data) { - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type); + var mapType = MapService.getMapType(type, data.eeMapURL); loadMap(type, mapType); $timeout(function () { showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear); @@ -710,7 +710,7 @@ .then(function (data) { MapService.removeGeoJson(map); MapService.clearLayer(map, 'primitivemap'); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap'); + var mapType = MapService.getMapType('primitivemap', data.eeMapURL); loadMap('primitivemap', mapType); $timeout(function () { showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear); diff --git a/landcoverportal/static/app/controllers/myanmar-ipcc-controller.js b/landcoverportal/static/app/controllers/myanmar-ipcc-controller.js index b889469..a2322c2 100644 --- a/landcoverportal/static/app/controllers/myanmar-ipcc-controller.js +++ b/landcoverportal/static/app/controllers/myanmar-ipcc-controller.js @@ -267,7 +267,7 @@ LandCoverService.getLandCoverMap(parameters) .then(function (data) { - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type); + var mapType = MapService.getMapType(type, data.eeMapURL); loadMap(type, mapType); $timeout(function () { showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear); @@ -712,7 +712,7 @@ .then(function (data) { MapService.removeGeoJson(map); MapService.clearLayer(map, 'primitivemap'); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap'); + var mapType = MapService.getMapType('primitivemap', data.eeMapURL); loadMap('primitivemap', mapType); $timeout(function () { showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear); diff --git a/landcoverportal/static/app/controllers/myanmar-national-controller.js b/landcoverportal/static/app/controllers/myanmar-national-controller.js index 03ad3c1..9ec3f43 100644 --- a/landcoverportal/static/app/controllers/myanmar-national-controller.js +++ b/landcoverportal/static/app/controllers/myanmar-national-controller.js @@ -259,7 +259,7 @@ LandCoverService.getLandCoverMap(parameters) .then(function (data) { - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type); + var mapType = MapService.getMapType(type, data.eeMapURL); loadMap(type, mapType); $timeout(function () { showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear); @@ -694,7 +694,7 @@ .then(function (data) { MapService.removeGeoJson(map); MapService.clearLayer(map, 'primitivemap'); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap'); + var mapType = MapService.getMapType('primitivemap', data.eeMapURL); loadMap('primitivemap', mapType); $timeout(function () { showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear); diff --git a/landcoverportal/static/app/controllers/myanmar-national-portal-controller.js b/landcoverportal/static/app/controllers/myanmar-national-portal-controller.js index 29f4839..ffd2676 100644 --- a/landcoverportal/static/app/controllers/myanmar-national-portal-controller.js +++ b/landcoverportal/static/app/controllers/myanmar-national-portal-controller.js @@ -294,7 +294,7 @@ LandCoverService.getLandCoverMap(parameters) .then(function (data) { - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type); + var mapType = MapService.getMapType(type, data.eeMapURL); loadMap(type, mapType); $timeout(function () { showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear); @@ -729,7 +729,7 @@ .then(function (data) { MapService.removeGeoJson(map); MapService.clearLayer(map, 'primitivemap'); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap'); + var mapType = MapService.getMapType('primitivemap', data.eeMapURL); loadMap('primitivemap', mapType); $timeout(function () { showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear); diff --git a/landcoverportal/static/app/controllers/myanmar-plantation-controller.js b/landcoverportal/static/app/controllers/myanmar-plantation-controller.js index 5ef0e94..07016ff 100644 --- a/landcoverportal/static/app/controllers/myanmar-plantation-controller.js +++ b/landcoverportal/static/app/controllers/myanmar-plantation-controller.js @@ -234,7 +234,7 @@ LandCoverService.getLandCoverMap(parameters) .then(function (data) { - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, type); + var mapType = MapService.getMapType(type, data.eeMapURL); loadMap(type, mapType); $timeout(function () { showInfoAlert('The map data shows the landcover data for ' + $scope.sliderYear); @@ -676,7 +676,7 @@ .then(function (data) { MapService.removeGeoJson(map); MapService.clearLayer(map, 'primitivemap'); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'primitivemap'); + var mapType = MapService.getMapType('primitivemap', data.eeMapURL); loadMap('primitivemap', mapType); $timeout(function () { showInfoAlert('Showing ' + getPrimitiveLabel(index) + ' primitive layer for ' + $scope.sliderYear); @@ -780,7 +780,7 @@ .then(function (data) { MapService.removeGeoJson(map); MapService.clearLayer(map, 'probabilitymap'); - var mapType = MapService.getMapType(data.eeMapId, data.eeMapToken, 'probabilitymap'); + var mapType = MapService.getMapType('probabilitymap', data.eeMapURL); var checked = $('#probability-map-checkbox').prop('checked'); loadMap('probabilitymap', mapType); if (checked) { diff --git a/landcoverportal/static/app/services/map-service.js b/landcoverportal/static/app/services/map-service.js index 4734d8c..468098c 100644 --- a/landcoverportal/static/app/services/map-service.js +++ b/landcoverportal/static/app/services/map-service.js @@ -166,19 +166,20 @@ } }; - service.getMapType = function (mapId, mapToken, type) { + service.getMapType = function (type, eeMapURL) { var eeMapOptions = { - getTileUrl: function (tile, zoom) { - var url = 'https://earthengine.googleapis.com/map/'; - url += [mapId, zoom, tile.x, tile.y].join('/'); - url += '?token=' + mapToken; + getTileUrl: function (tile, zoom) { + var url = eeMapURL.replace('{x}', tile.x) + .replace('{y}', tile.y) + .replace('{z}', zoom); return url; }, - tileSize: new google.maps.Size(256, 256), - opacity: 1.0, - name: type + tileSize: new google.maps.Size(256, 256), + name: type, + opacity: 1.0 }; - return new google.maps.ImageMapType(eeMapOptions); + var mapType = new google.maps.ImageMapType(eeMapOptions); + return mapType }; service.getPolygonBoundArray = function (array) { diff --git a/landcoverportal/templates/layout.html b/landcoverportal/templates/layout.html index 742a770..96ae50f 100644 --- a/landcoverportal/templates/layout.html +++ b/landcoverportal/templates/layout.html @@ -100,11 +100,7 @@ {% cms_toolbar %} -
+ {% block navigation_container %} {% endblock navigation_container %} diff --git a/landcoverportal/templates/panels/side-panel-forest-monitor.html b/landcoverportal/templates/panels/side-panel-forest-monitor.html index df34852..6f9a2be 100644 --- a/landcoverportal/templates/panels/side-panel-forest-monitor.html +++ b/landcoverportal/templates/panels/side-panel-forest-monitor.html @@ -67,7 +67,7 @@Tree Canopy Cover for
Tree Canopy Height for
Annual Forest Extend for
Primary Forest
- Forest Gain + Forest Gain
- Forest Loss + Forest Loss