cms/app-client/app/components/visu-carto.js
changeset 392 4fbe94af93e8
parent 391 4f6118afabee
child 424 feb0d3e0fef9
--- a/cms/app-client/app/components/visu-carto.js	Thu Nov 03 11:14:41 2016 +0100
+++ b/cms/app-client/app/components/visu-carto.js	Fri Nov 04 19:03:25 2016 +0100
@@ -1,6 +1,8 @@
 import Ember from 'ember';
 import AmCharts from 'ammaps';
 import ENV from 'app-client/config/environment';
+import * as commonConstants from 'corpus-common-addon/utils/constants';
+import * as commonUtils from 'corpus-common-addon/utils/utils';
 
 export default Ember.Component.extend({
 
@@ -15,15 +17,17 @@
     franceMapVar: AmCharts.maps.france2016Low,
     franceAreas: [],
 
-    locationQueryParam: '',
     dataProvider: {},
 
     color: 'rgba(113,132,141,.2)',
 
     filter: Ember.inject.service(),
     locationObserver: Ember.observer('filter.location', function() {
-        if(!this.get('filter').get('location')) {
+        if(this.get('filter').get('location') === null) {
             this.sendAction('setLocation', this.get('constants').GEONAMES['world']);
+            this.get('map').selectObject();
+        } else {
+            this.sendAction('setLocation', commonUtils.getGeonamesCode(this.get('filter').get('location')));
         }
     }),
 
@@ -71,6 +75,7 @@
         if (ENV.environment === 'development') {
             this.set('color', '#f3f3f3');
         }
+        this.get('service'); // gotcha cf: https://github.com/emberjs/ember.js/issues/10821
     },
 
     setFranceAreas: function() {
@@ -192,15 +197,12 @@
     },
 
     clickMapObject: function(event) {
-        this.set('locationQueryParam', event.mapObject.id);
-        this.sendAction('setLocation', event.mapObject.id);
-        this.get('filter').set('location', event.mapObject.id);
+        this.get('filter').setFilter('location', commonConstants.GEONAMES_BASE_URL + event.mapObject.id);
     },
 
-    homeButtonClicked: function(event) {
-        if(event.chart.dataProvider.map !== 'continentsLow') {
-            this.get('filter').set('location', null);
-        }
+    homeButtonClicked: function() {
+        this.get('filter').removeFilter('location', null);
+        this.sendAction('setLocation', this.get('constants').GEONAMES['world']);
     }
 
 });