cms/app-client/app/components/visu-carto.js
author ymh <ymh.work@gmail.com>
Sat, 17 Dec 2016 23:43:28 +0100
changeset 475 dbb941b9fb66
parent 424 feb0d3e0fef9
child 481 002a05cd849f
permissions -rw-r--r--
add missing territories and the zoom function at counties level
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(),
331
9836845ed1e8 AmMaps geonames constants
Chloe Laisne <chloe.laisne@gmail.com>
parents: 309
diff changeset
    11
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    12
  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
    13
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    14
  continentsMapVar: AmCharts.maps.continentsLow,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    15
  continentsAreas: [],
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    16
  countriesMapVar: AmCharts.maps.worldLow,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    17
  countriesAreas: [],
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    18
  franceMapVar: AmCharts.maps.france2016Low,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    19
  franceAreas: [],
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    20
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    21
  dataProvider: {},
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    22
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
    23
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    24
  area: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    25
  originalZoomLevel: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    26
  originalZoomLongitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    27
  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
    28
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    29
  color: 'rgba(113,132,141,.2)',
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    30
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    31
  filter: Ember.inject.service(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    32
  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
    33
    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
    34
      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
    35
      this.get('map').selectObject();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    36
    } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    37
      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
    38
    }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    39
  }),
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    40
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    41
  geostats: [],
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    42
  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
    43
    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
    44
    if(!map) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    45
      return;
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
    let selectedObject = map.selectedObject;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    48
    if (selectedObject.id) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    49
      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
    50
        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
    51
          this.setProperties({
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    52
            area: 'france',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    53
            originalZoomLevel: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    54
            originalZoomLongitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    55
            originalZoomLatitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    56
          });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    57
          this.setFranceAreas();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    58
          this.set('dataProvider', {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    59
            'mapVar': this.get('franceMapVar'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    60
            'getAreasFromMap': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    61
            'areas': this.get('franceAreas')
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    62
          });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    63
          map['zoomControl'] = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    64
            'zoomControlEnabled': false
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    65
          };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    66
          map['dragMap'] = false;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    67
          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
    68
          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
    69
        }
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    70
      } 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
    71
        this.setProperties({
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    72
          area: 'countries',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    73
          originalZoomLevel: map.zoomLevel(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    74
          originalZoomLongitude: map.zoomLongitude(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    75
          originalZoomLatitude: map.zoomLatitude()
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    76
        });
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
        this.setCountriesAreas();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    79
        this.set('dataProvider', {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    80
          'mapVar': this.get('countriesMapVar'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    81
          'getAreasFromMap': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    82
          'areas': this.get('countriesAreas'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    83
          'zoomLevel': map.zoomLevel(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    84
          'zoomLatitude': map.zoomLatitude(),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    85
          '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
    86
        });
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    87
        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
    88
        map['zoomControl'] = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    89
          'zoomControlEnabled': true
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    90
        };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    91
        map['dragMap'] = true;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    92
        map.validateData();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    93
      }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    94
    } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    95
      this.setProperties({
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    96
        area: 'continents',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    97
        originalZoomLevel: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    98
        originalZoomLongitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
    99
        originalZoomLatitude: null,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   100
      });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   101
      this.setContinentsAreas();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   102
      this.set('dataProvider', {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   103
        'mapVar': this.get('continentsMapVar'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   104
        'areas': this.get('continentsAreas')
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   105
      });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   106
      map['zoomControl'] = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   107
        'zoomControlEnabled': false
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
      map['dragMap'] = false;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   110
      this.createAmMap();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   111
    }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   112
  }),
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
  init: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   115
    this._super(...arguments);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   116
    if (ENV.environment === 'development') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   117
      this.set('color', '#f3f3f3');
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   118
    }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   119
    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
   120
  },
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
   121
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   122
  setFranceAreas: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   123
    var self = this;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   124
    var france2016LowAreas = [];
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   125
    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
   126
      var object = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   127
        'id': area.id,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   128
        'passZoomValuesToTarget': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   129
        'autoZoom': false
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   130
      };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   131
      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
   132
      if (typeof departments === 'undefined') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   133
        object['mouseEnabled'] = false;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   134
        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
   135
      } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   136
        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
   137
        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
   138
      }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   139
      france2016LowAreas.push(object);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   140
    });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   141
    this.set('franceAreas', france2016LowAreas);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   142
  },
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
   143
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   144
  setCountriesAreas: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   145
    var self = this;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   146
    var worldLowAreas = [];
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   147
    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
   148
      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
   149
      if (typeof countries === 'undefined') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   150
        worldLowAreas.push({
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   151
          'id': area.id,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   152
          'mouseEnabled': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   153
          '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
   154
        });
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   155
      } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   156
        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
   157
          var object = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   158
            'id': area.id,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   159
            'selectable': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   160
            'value': countries.get('count'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   161
            '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
   162
          };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   163
          if (area.id === 'FR') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   164
            object['autoZoom'] = true;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   165
          }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   166
          worldLowAreas.push(object);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   167
        }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   168
      }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   169
    });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   170
    this.set('countriesAreas', worldLowAreas);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   171
  },
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
   172
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   173
  setContinentsAreas: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   174
    var self = this;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   175
    var continentsLowAreas = [];
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   176
    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
   177
      var object = {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   178
        'id': area.id,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   179
        'passZoomValuesToTarget': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   180
        'selectable': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   181
        'mouseEnabled': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   182
        'autoZoom': true
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   183
      };
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   184
      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
   185
      if (typeof continent === 'undefined') {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   186
        object['mouseEnabled'] = false;
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   187
        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
   188
      } else {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   189
        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
   190
        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
   191
      }
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   192
      continentsLowAreas.push(object);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   193
    });
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   194
    this.set('continentsAreas', continentsLowAreas);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   195
  },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   196
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   197
  didInsertElement: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   198
    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
   199
    this.createAmMap();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   200
  },
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
  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
   203
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   204
    this.setContinentsAreas();
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   205
    this.set('dataProvider', {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   206
      'mapVar': this.get('continentsMapVar'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   207
      'areas': this.get('continentsAreas')
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
    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
   210
      'type': 'map',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   211
      'accessible': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   212
      'fontFamily': 'sans-serif',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   213
      'fontSize': '12px',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   214
      'dragMap': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   215
      'zoomOnDoubleClick': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   216
      'language': 'fr',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   217
      'areasSettings': {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   218
        'autoZoom': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   219
        'selectable': true,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   220
        '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
   221
        '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
   222
        'colorOutline': '#253946',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   223
        'selectedColor': '#0085cb',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   224
        'rollOverColor': '#0085cb',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   225
        'rollOverOutlineColor': '#ffffff'
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   226
      },
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   227
      'zoomControl': {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   228
        'zoomControlEnabled': false,
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   229
      },
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   230
      'dataProvider': this.get('dataProvider'),
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   231
      listeners: [{
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   232
        'event': 'clickMapObject',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   233
        '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
   234
      }, {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   235
        'event': 'homeButtonClicked',
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   236
        '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
   237
      }]
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   238
    }));
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   239
  },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   240
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   241
  clickMapObject: function (event) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   242
    this.get('filter').setFilter('location', commonConstants.GEONAMES_BASE_URL + event.mapObject.id);
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   243
  },
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   244
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   245
  homeButtonClicked: function () {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   246
    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
   247
    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
   248
      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
   249
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   250
    if(area === 'countries' && (
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   251
      (originalZoomLevel && originalZoomLevel !== map.zoomLevel()) ||
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   252
      (originalZoomLatitude && originalZoomLatitude !== map.zoomLatitude()) ||
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   253
      (originalZoomLongitude && originalZoomLongitude !== map.zoomLongitude())
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   254
    )) {
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   255
      // 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
   256
      return;
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   257
    }
475
dbb941b9fb66 add missing territories and the zoom function at counties level
ymh <ymh.work@gmail.com>
parents: 424
diff changeset
   258
    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
   259
    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
   260
  }
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   261
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   262
});