cms/app-client/app/components/visu-carto.js
author ymh <ymh.work@gmail.com>
Tue, 20 Mar 2018 15:02:40 +0100
changeset 573 25f3d28f51b2
parent 481 002a05cd849f
permissions -rw-r--r--
Added tag 0.0.25 for changeset 190ae1dee68d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     1
import Ember from 'ember';
123
4c97e9da1416 Remove use of global variables + remove ember-cli-content-security-policy from package.json to avoid bogus csp violation warnings
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
     2
import AmCharts from 'ammaps';
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
     3
import ENV from 'app-client/config/environment';
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
     4
import * as commonConstants from 'corpus-common-addon/utils/constants';
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
     5
import * as commonUtils from 'corpus-common-addon/utils/utils';
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     6
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     7
export default Ember.Component.extend({
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 193
diff changeset
     8
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
     9
  constants: Ember.inject.service(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    10
  colors: Ember.inject.service(),
481
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
    11
  filter: Ember.inject.service(),
331
9836845ed1e8 AmMaps geonames constants
Chloe Laisne <chloe.laisne@gmail.com>
parents: 309
diff changeset
    12
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    13
  map: null,
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
    14
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    15
  continentsMapVar: AmCharts.maps.continentsLow,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    16
  continentsAreas: [],
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    17
  countriesMapVar: AmCharts.maps.worldLow,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    18
  countriesAreas: [],
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    19
  franceMapVar: AmCharts.maps.france2016Low,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    20
  franceAreas: [],
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    21
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    22
  dataProvider: {},
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    23
481
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
    24
  colorScale: Ember.computed('maxCount', 'minCount', function () {
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
    25
    let maxCount = this.get('maxCount');
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
    26
    let minCount = this.get('minCount');
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
    27
    return this.get('colors').getScaleLinear(minCount, maxCount);
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
    28
  }),
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
    29
  counts: Ember.computed.mapBy('geostats', 'count'),
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
    30
  maxCount: Ember.computed.max('counts'),
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
    31
  minCount: Ember.computed.min('counts'),
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
    32
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    33
  area: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    34
  originalZoomLevel: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    35
  originalZoomLongitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    36
  originalZoomLatitude: null,
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
    37
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    38
  color: 'rgba(113,132,141,.2)',
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    39
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    40
  locationObserver: Ember.observer('filter.location', function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    41
    if (this.get('filter').get('location') === null) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    42
      this.sendAction('setLocation', this.get('constants').GEONAMES['world']);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    43
      this.get('map').selectObject();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    44
    } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    45
      this.sendAction('setLocation', commonUtils.getGeonamesCode(this.get('filter').get('location')));
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    46
    }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    47
  }),
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    48
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    49
  geostats: [],
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    50
  observerGeostats: Ember.observer('geostats', function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    51
    let map = this.get('map');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    52
    if(!map) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    53
      return;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    54
    }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    55
    let selectedObject = map.selectedObject;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    56
    if (selectedObject.id) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    57
      if (selectedObject.parentObject.mapVar === this.get('countriesMapVar')) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    58
        if (selectedObject.id === this.get('constants').GEONAMES['france']) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    59
          this.setProperties({
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    60
            area: 'france',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    61
            originalZoomLevel: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    62
            originalZoomLongitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    63
            originalZoomLatitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    64
          });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    65
          this.setFranceAreas();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    66
          this.set('dataProvider', {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    67
            'mapVar': this.get('franceMapVar'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    68
            'getAreasFromMap': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    69
            'areas': this.get('franceAreas')
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    70
          });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    71
          map['zoomControl'] = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    72
            'zoomControlEnabled': false
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    73
          };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    74
          map['dragMap'] = false;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    75
          map['dataProvider'] = this.get('dataProvider');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    76
          map.validateData();
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
    77
        }
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    78
      } else if (selectedObject.parentObject.mapVar === this.get('continentsMapVar')) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    79
        this.setProperties({
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    80
          area: 'countries',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    81
          originalZoomLevel: map.zoomLevel(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    82
          originalZoomLongitude: map.zoomLongitude(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    83
          originalZoomLatitude: map.zoomLatitude()
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    84
        });
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
    85
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    86
        this.setCountriesAreas();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    87
        this.set('dataProvider', {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    88
          'mapVar': this.get('countriesMapVar'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    89
          'getAreasFromMap': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    90
          'areas': this.get('countriesAreas'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    91
          'zoomLevel': map.zoomLevel(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    92
          'zoomLatitude': map.zoomLatitude(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    93
          'zoomLongitude': map.zoomLongitude()
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
    94
        });
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    95
        map['dataProvider'] = this.get('dataProvider');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    96
        map['zoomControl'] = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    97
          'zoomControlEnabled': true
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    98
        };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    99
        map['dragMap'] = true;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   100
        map.validateData();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   101
      }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   102
    } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   103
      this.setProperties({
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   104
        area: 'continents',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   105
        originalZoomLevel: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   106
        originalZoomLongitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   107
        originalZoomLatitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   108
      });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   109
      this.setContinentsAreas();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   110
      this.set('dataProvider', {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   111
        'mapVar': this.get('continentsMapVar'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   112
        'areas': this.get('continentsAreas')
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   113
      });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   114
      map['zoomControl'] = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   115
        'zoomControlEnabled': false
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   116
      };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   117
      map['dragMap'] = false;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   118
      this.createAmMap();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   119
    }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   120
  }),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   121
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   122
  init: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   123
    this._super(...arguments);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   124
    if (ENV.environment === 'development') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   125
      this.set('color', '#f3f3f3');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   126
    }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   127
    this.get('service'); // gotcha cf: https://github.com/emberjs/ember.js/issues/10821
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   128
  },
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
   129
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   130
  setFranceAreas: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   131
    var self = this;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   132
    var france2016LowAreas = [];
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   133
    this.get('franceMapVar')['svg']['g']['path'].forEach(function (area) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   134
      var object = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   135
        'id': area.id,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   136
        'passZoomValuesToTarget': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   137
        'autoZoom': false
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   138
      };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   139
      var departments = self.get('geostats').find(geostat => geostat.id === area.id);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   140
      if (typeof departments === 'undefined') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   141
        object['mouseEnabled'] = false;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   142
        object['color'] = self.get('color');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   143
      } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   144
        object['value'] = departments.get('count');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   145
        object['title'] = area.title + "&nbsp;(" + departments.get('count') + ")";
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   146
      }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   147
      france2016LowAreas.push(object);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   148
    });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   149
    this.set('franceAreas', france2016LowAreas);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   150
  },
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
   151
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   152
  setCountriesAreas: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   153
    var self = this;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   154
    var worldLowAreas = [];
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   155
    this.get('countriesMapVar')['svg']['g']['path'].forEach(function (area) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   156
      var countries = self.get('geostats').find(geostat => geostat.id === area.id);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   157
      if (typeof countries === 'undefined') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   158
        worldLowAreas.push({
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   159
          'id': area.id,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   160
          'mouseEnabled': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   161
          'color': self.get('color')
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
   162
        });
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   163
      } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   164
        if (typeof worldLowAreas.find(country => country.id === area.id) === 'undefined') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   165
          var object = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   166
            'id': area.id,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   167
            'selectable': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   168
            'value': countries.get('count'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   169
            'title': area.title + "&nbsp;(" + countries.get('count') + ")"
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   170
          };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   171
          if (area.id === 'FR') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   172
            object['autoZoom'] = true;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   173
          }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   174
          worldLowAreas.push(object);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   175
        }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   176
      }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   177
    });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   178
    this.set('countriesAreas', worldLowAreas);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   179
  },
278
f2c2c80a49f7 Disable click on map areas w/o geoname + development/production disabled color + geostat endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 274
diff changeset
   180
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   181
  setContinentsAreas: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   182
    var self = this;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   183
    var continentsLowAreas = [];
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   184
    this.get('continentsMapVar')['svg']['g']['path'].forEach(function (area) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   185
      var object = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   186
        'id': area.id,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   187
        'passZoomValuesToTarget': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   188
        'selectable': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   189
        'mouseEnabled': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   190
        'autoZoom': true
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   191
      };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   192
      var continent = self.get('geostats').find(geostat => geostat.id === area.id);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   193
      if (typeof continent === 'undefined') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   194
        object['mouseEnabled'] = false;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   195
        object['color'] = self.get('color');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   196
      } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   197
        object['value'] = continent.get('count');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   198
        object['title'] = area.title + "&nbsp;(" + continent.get('count') + ")";
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   199
      }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   200
      continentsLowAreas.push(object);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   201
    });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   202
    this.set('continentsAreas', continentsLowAreas);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   203
  },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   204
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   205
  didInsertElement: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   206
    this.$('#mapdiv').height(Ember.$('.corpus-app-container').height());
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   207
    this.createAmMap();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   208
  },
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   209
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   210
  createAmMap: function () {
306
3fccf43160a7 Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents: 291
diff changeset
   211
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   212
    this.setContinentsAreas();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   213
    this.set('dataProvider', {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   214
      'mapVar': this.get('continentsMapVar'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   215
      'areas': this.get('continentsAreas')
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   216
    });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   217
    this.set('map', AmCharts.makeChart('mapdiv', {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   218
      'type': 'map',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   219
      'accessible': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   220
      'fontFamily': 'sans-serif',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   221
      'fontSize': '12px',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   222
      'dragMap': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   223
      'zoomOnDoubleClick': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   224
      'language': 'fr',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   225
      'areasSettings': {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   226
        'autoZoom': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   227
        'selectable': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   228
        'color': this.get('colors').LINEAR_COLOR_START,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   229
        'colorSolid': this.get('colors').LINEAR_COLOR_END,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   230
        'colorOutline': '#253946',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   231
        'selectedColor': '#0085cb',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   232
        'rollOverColor': '#0085cb',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   233
        'rollOverOutlineColor': '#ffffff'
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   234
      },
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   235
      'zoomControl': {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   236
        'zoomControlEnabled': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   237
      },
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   238
      'dataProvider': this.get('dataProvider'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   239
      listeners: [{
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   240
        'event': 'clickMapObject',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   241
        'method': Ember.run.bind(this, 'clickMapObject')
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   242
      }, {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   243
        'event': 'homeButtonClicked',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   244
        'method': Ember.run.bind(this, 'homeButtonClicked')
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   245
      }]
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   246
    }));
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   247
  },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   248
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   249
  clickMapObject: function (event) {
481
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
   250
    const changed = this.get('filter').setFilter('location', commonConstants.GEONAMES_BASE_URL + event.mapObject.id);
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
   251
    if(!changed) {
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
   252
      //force filter change
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
   253
      this.notifyPropertyChange('filter.location');
002a05cd849f add color gradient to map visualisaion
ymh <ymh.work@gmail.com>
parents: 475
diff changeset
   254
    }
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   255
  },
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   256
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   257
  homeButtonClicked: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   258
    const map = this.get('map');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   259
    const { area, originalZoomLevel, originalZoomLongitude, originalZoomLatitude } =
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   260
      this.getProperties('area', 'originalZoomLevel', 'originalZoomLongitude', 'originalZoomLatitude');
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   261
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   262
    if(area === 'countries' && (
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   263
      (originalZoomLevel && originalZoomLevel !== map.zoomLevel()) ||
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   264
      (originalZoomLatitude && originalZoomLatitude !== map.zoomLatitude()) ||
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   265
      (originalZoomLongitude && originalZoomLongitude !== map.zoomLongitude())
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   266
    )) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   267
      // in mode countries, the map has been moved or zoomed, just reset the view
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   268
      return;
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   269
    }
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   270
    this.get('filter').removeFilter('location', null);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   271
    this.sendAction('setLocation', this.get('constants').GEONAMES['world']);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   272
  }
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   273
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   274
});