cms/app-client/app/components/visu-carto.js
author ymh <ymh.work@gmail.com>
Tue, 08 Nov 2016 15:48:01 +0100
changeset 404 0a5eef6ad2fe
parent 392 4fbe94af93e8
child 424 feb0d3e0fef9
permissions -rw-r--r--
correction, change colors for discourse categories, add loding spinner
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
331
9836845ed1e8 AmMaps geonames constants
Chloe Laisne <chloe.laisne@gmail.com>
parents: 309
diff changeset
     9
    constants: Ember.inject.service(),
9836845ed1e8 AmMaps geonames constants
Chloe Laisne <chloe.laisne@gmail.com>
parents: 309
diff changeset
    10
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
    11
    map: null,
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
    12
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    13
    continentsMapVar: AmCharts.maps.continentsLow,
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
    continentsAreas: [],
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    15
    countriesMapVar: AmCharts.maps.worldLow,
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
    16
    countriesAreas: [],
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    17
    franceMapVar: AmCharts.maps.france2016Low,
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
    18
    franceAreas: [],
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
    19
291
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    20
    dataProvider: {},
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
    21
281
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
    22
    color: 'rgba(113,132,141,.2)',
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    23
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    24
    filter: Ember.inject.service(),
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    25
    locationObserver: Ember.observer('filter.location', function() {
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
    26
        if(this.get('filter').get('location') === null) {
331
9836845ed1e8 AmMaps geonames constants
Chloe Laisne <chloe.laisne@gmail.com>
parents: 309
diff changeset
    27
            this.sendAction('setLocation', this.get('constants').GEONAMES['world']);
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
    28
            this.get('map').selectObject();
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
    29
        } else {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
    30
            this.sendAction('setLocation', commonUtils.getGeonamesCode(this.get('filter').get('location')));
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    31
        }
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    32
    }),
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    33
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    34
    geostats: [],
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    35
    observerGeostats: Ember.observer('geostats', function() {
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
    36
        if(this.get('map')) {
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
            if(this.get('map').selectedObject.id) {
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
    38
                if(this.get('map').selectedObject.parentObject.mapVar === this.get('countriesMapVar')) {
331
9836845ed1e8 AmMaps geonames constants
Chloe Laisne <chloe.laisne@gmail.com>
parents: 309
diff changeset
    39
                    if(this.get('map').selectedObject.id === this.get('constants').GEONAMES['france']) {
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
    40
                        this.setFranceAreas();
291
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    41
                        this.set('dataProvider', {
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
    42
                            'mapVar': this.get('franceMapVar'),
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
    43
                            'getAreasFromMap': true,
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
    44
                            'areas': this.get('franceAreas')
291
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    45
                        });
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    46
                        this.get('map')['dataProvider'] = this.get('dataProvider');
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
    47
                        this.get('map').validateData();
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
    48
                    }
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
    49
                } else if(this.get('map').selectedObject.parentObject.mapVar === this.get('continentsMapVar')) {
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
    50
                    this.setCountriesAreas();
291
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    51
                    this.set('dataProvider', {
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
    52
                        'mapVar': this.get('countriesMapVar'),
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
    53
                        'getAreasFromMap': true,
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
    54
                        'areas': this.get('countriesAreas'),
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
    55
                        'zoomLevel': this.get('map').zoomLevel(),
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
    56
                        'zoomLatitude': this.get('map').zoomLatitude(),
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
    57
                        'zoomLongitude': this.get('map').zoomLongitude()
291
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    58
                    });
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    59
                    this.get('map')['dataProvider'] = this.get('dataProvider');
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
    60
                    this.get('map').validateData();
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
    61
                }
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
    62
            } else {
291
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    63
                this.setContinentsAreas();
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    64
                this.set('dataProvider', {
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    65
                    'mapVar': this.get('continentsMapVar'),
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    66
                    'areas': this.get('continentsAreas')
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
    67
                });
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
    68
                this.createAmMap();
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
            }
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
    70
        }
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    71
    }),
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    72
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
    73
    init: function() {
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
    74
        this._super(...arguments);
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
    75
        if (ENV.environment === 'development') {
355
83f5247f3c7a Fix carto counts and map colors
Chloe Laisne <chloe.laisne@gmail.com>
parents: 331
diff changeset
    76
            this.set('color', '#f3f3f3');
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
        }
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
    78
        this.get('service'); // gotcha cf: https://github.com/emberjs/ember.js/issues/10821
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
    79
    },
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
    80
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
    81
    setFranceAreas: function() {
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
    82
        var self = this;
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
    83
        var france2016LowAreas = [];
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
    84
        this.get('franceMapVar')['svg']['g']['path'].forEach(function(area) {
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
            var object = {
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
                'id': area.id,
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
    87
                'passZoomValuesToTarget': false,
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
    88
                'autoZoom': false
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
    89
            };
281
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
    90
            var departments = self.get('geostats').find(geostat => geostat.id === area.id);
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
    91
            if(typeof departments === 'undefined') {
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
    92
                object['mouseEnabled'] = false;
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
    93
                object['color'] = self.get('color');
281
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
    94
            } else {
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
    95
                object['value'] = departments.get('count');
391
4f6118afabee Carto improvement:
ymh <ymh.work@gmail.com>
parents: 355
diff changeset
    96
                object['title'] = area.title + "&nbsp;(" + departments.get('count') + ")";
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
    97
            }
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
    98
            france2016LowAreas.push(object);
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
    99
        });
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
   100
        this.set('franceAreas', france2016LowAreas);
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
   101
    },
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
   102
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
   103
    setCountriesAreas: function() {
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
   104
        var self = this;
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
   105
        var worldLowAreas = [];
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
   106
        this.get('countriesMapVar')['svg']['g']['path'].forEach(function(area) {
281
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
   107
            var countries = self.get('geostats').find(geostat => geostat.id === area.id);
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
   108
            if(typeof countries === 'undefined') {
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
   109
                worldLowAreas.push({
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
   110
                    'id': area.id,
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
   111
                    'mouseEnabled': false,
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
   112
                    'color': self.get('color')
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
   113
                });
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
   114
            } else {
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
   115
                if(typeof worldLowAreas.find(country => country.id === area.id) === 'undefined') {
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
   116
                    var object = {
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
   117
                        'id': area.id,
281
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
   118
                        'selectable': true,
391
4f6118afabee Carto improvement:
ymh <ymh.work@gmail.com>
parents: 355
diff changeset
   119
                        'value': countries.get('count'),
4f6118afabee Carto improvement:
ymh <ymh.work@gmail.com>
parents: 355
diff changeset
   120
                        'title': area.title + "&nbsp;(" + countries.get('count') + ")"
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
                    };
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
   122
                    if(area.id === 'FR') {
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
   123
                        object['autoZoom'] = true;
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
   124
                    }
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
   125
                    worldLowAreas.push(object);
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
   126
                }
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
   127
            }
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
   128
        });
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
        this.set('countriesAreas', worldLowAreas);
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
   130
    },
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
   131
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
   132
    setContinentsAreas: function() {
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
   133
        var self = this;
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
   134
        var continentsLowAreas = [];
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
   135
        this.get('continentsMapVar')['svg']['g']['path'].forEach(function(area) {
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
   136
            var object = {
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
   137
                'id': area.id,
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
   138
                'passZoomValuesToTarget': true,
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
   139
                'selectable': true,
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
   140
                'mouseEnabled': true,
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
   141
                'autoZoom': true
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
   142
            };
281
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
   143
            var continent = self.get('geostats').find(geostat => geostat.id === area.id);
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
   144
            if(typeof continent === 'undefined') {
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
   145
                object['mouseEnabled'] = false;
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
   146
                object['color'] = self.get('color');
281
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
   147
            } else {
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
   148
                object['value'] = continent.get('count');
391
4f6118afabee Carto improvement:
ymh <ymh.work@gmail.com>
parents: 355
diff changeset
   149
                object['title'] = area.title + "&nbsp;(" + continent.get('count') + ")";
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
   150
            }
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
            continentsLowAreas.push(object);
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
   152
        });
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
   153
        this.set('continentsAreas', continentsLowAreas);
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
    },
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
   155
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   156
    didInsertElement: function(){
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   157
        this.$('#mapdiv').height(Ember.$('.corpus-app-container').height());
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   158
        this.createAmMap();
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   159
    },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   160
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   161
    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
   162
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
   163
        this.setContinentsAreas();
291
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
   164
        this.set('dataProvider', {
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
   165
            'mapVar': this.get('continentsMapVar'),
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
   166
            'areas': this.get('continentsAreas')
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
   167
        });
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   168
        this.set('map', AmCharts.makeChart('mapdiv', {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   169
            'type': 'map',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   170
            'fontFamily': 'sans-serif',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   171
            'fontSize': '12px',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   172
            'dragMap': false,
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   173
            'zoomOnDoubleClick': false,
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   174
            'language': 'fr',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   175
            'areasSettings': {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   176
                'autoZoom': false,
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   177
                'selectable': true,
355
83f5247f3c7a Fix carto counts and map colors
Chloe Laisne <chloe.laisne@gmail.com>
parents: 331
diff changeset
   178
                'color': '#777777',
83f5247f3c7a Fix carto counts and map colors
Chloe Laisne <chloe.laisne@gmail.com>
parents: 331
diff changeset
   179
                'colorSolid': '#333333',
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   180
                'colorOutline': '#253946',
355
83f5247f3c7a Fix carto counts and map colors
Chloe Laisne <chloe.laisne@gmail.com>
parents: 331
diff changeset
   181
                'selectedColor': '#0085cb',
83f5247f3c7a Fix carto counts and map colors
Chloe Laisne <chloe.laisne@gmail.com>
parents: 331
diff changeset
   182
                'rollOverColor': '#0085cb',
83f5247f3c7a Fix carto counts and map colors
Chloe Laisne <chloe.laisne@gmail.com>
parents: 331
diff changeset
   183
                'rollOverOutlineColor': '#ffffff'
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   184
            },
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   185
            'zoomControl': {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   186
                'zoomControlEnabled': false,
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   187
            },
291
478cdcc56a63 Reset geonames model parameter when coming back to cartography tab
Chloe Laisne <chloe.laisne@gmail.com>
parents: 290
diff changeset
   188
            'dataProvider': this.get('dataProvider'),
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   189
            listeners: [{
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   190
                'event':'clickMapObject',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   191
                'method': Ember.run.bind(this, 'clickMapObject')
281
618aec1734d5 Set step colors with geoname counts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 278
diff changeset
   192
            }, {
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   193
                'event':'homeButtonClicked',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   194
                'method': Ember.run.bind(this, 'homeButtonClicked')
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   195
            }]
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   196
        }));
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   197
    },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   198
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   199
    clickMapObject: function(event) {
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
   200
        this.get('filter').setFilter('location', commonConstants.GEONAMES_BASE_URL + event.mapObject.id);
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   201
    },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   202
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
   203
    homeButtonClicked: function() {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
   204
        this.get('filter').removeFilter('location', null);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 391
diff changeset
   205
        this.sendAction('setLocation', this.get('constants').GEONAMES['world']);
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   206
    }
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   207
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   208
});