cms/app-client/app/components/visu-carto.js
author Chloe Laisne <chloe.laisne@gmail.com>
Mon, 05 Sep 2016 18:45:47 +0200
changeset 274 53a6985443f8
parent 273 a719b2dcea34
child 278 f2c2c80a49f7
permissions -rw-r--r--
geostats endpoint + mapvar
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';
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     3
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     4
export default Ember.Component.extend({
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 193
diff changeset
     5
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
     6
    continentsMapVar: AmCharts.maps.continentsLow,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
     7
    countriesMapVar: AmCharts.maps.worldLow,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
     8
    franceMapVar: AmCharts.maps.france2016Low,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
     9
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    10
    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
    11
    locationObserver: Ember.observer('filter.location', function() {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    12
        if(!this.get('filter').get('location')) {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    13
            this.get('map').selectObject();
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    14
        }
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    15
    }),
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    16
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    17
    geostats: [],
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    18
    observerGeostats: Ember.observer('geostats', function() {
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    19
        //console.log(this.get('geostats'));
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    20
    }),
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    21
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    22
    didInsertElement: function(){
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    23
        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
    24
        this.createAmMap();
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    25
    },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    26
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    27
    createAmMap: function() {
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    28
        var self = this;
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    29
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    30
        var france2016LowAreas = [];
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    31
        this.get('franceMapVar')['svg']['g']['path'].forEach(function(area) {
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    32
            france2016LowAreas.push({
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    33
                'id': area.id,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    34
                'passZoomValuesToTarget': false,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    35
                'autoZoom': false,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    36
                'selectable': true
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    37
            })
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    38
        });
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    39
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    40
        var continentsLowAreas = [];
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    41
        this.get('continentsMapVar')['svg']['g']['path'].forEach(function(area) {
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    42
            var object = {
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    43
                'id': area.id,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    44
                'linkToObject': {
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    45
                    'mapVar': self.get('countriesMapVar'),
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    46
                    'getAreasFromMap': true
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    47
                },
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    48
                'passZoomValuesToTarget': true,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    49
                'autoZoom': true
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    50
            };
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    51
            if(area.id === 'europe') {
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    52
                object['linkToObject']['areas'] = [{
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    53
                    'id': 'FR',
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    54
                    'linkToObject': {
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    55
                        'mapVar': self.get('franceMapVar'),
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    56
                        'getAreasFromMap': true,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    57
                        'areas': france2016LowAreas
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    58
                    },
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    59
                    'autoZoom': true,
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    60
                    'selectable': true
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    61
                }];
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    62
            }
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    63
            continentsLowAreas.push(object);
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    64
        });
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    65
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    66
        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
    67
            'type': 'map',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    68
            'fontFamily': 'sans-serif',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    69
            'fontSize': '12px',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    70
            'dragMap': false,
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    71
            'zoomOnDoubleClick': false,
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    72
            'language': 'fr',
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    73
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    74
            'areasSettings': {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    75
                'autoZoom': false,
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    76
                'selectable': true,
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    77
                'color': '#becfd4',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    78
                'colorOutline': '#253946',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    79
                'selectedColor': '#253946',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    80
                'rollOverOutlineColor': '#253946'
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    81
            },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    82
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    83
            'zoomControl': {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    84
                'zoomControlEnabled': false,
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    85
            },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    86
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    87
            'dataProvider': {
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    88
                'mapVar': this.get('continentsMapVar'),
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
    89
                'areas': continentsLowAreas
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    90
            },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    91
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    92
            listeners: [{
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    93
                'event':'clickMapObject',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    94
                'method': Ember.run.bind(this, 'clickMapObject')
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    95
            },
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    96
            {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    97
                'event':'homeButtonClicked',
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
    98
                '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
    99
            }]
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   100
        }));
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   101
    },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   102
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   103
    clickMapObject: function(event) {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   104
        this.get('filter').set('location', event.mapObject.title);
274
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
   105
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
   106
        /*this.get('geostats').forEach( function (geostat) {
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
   107
            console.log('geostat', geostat.get('id'), geostat.get('count'));
53a6985443f8 geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents: 273
diff changeset
   108
        });*/
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   109
    },
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   110
273
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   111
    homeButtonClicked: function(event) {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   112
        if(event.chart.dataProvider.map !== 'continentsLow') {
a719b2dcea34 Cartography on 3 levels (continents/countries/france) and backToContinents button
Chloe Laisne <chloe.laisne@gmail.com>
parents: 204
diff changeset
   113
            this.createAmMap();
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   114
        }
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   115
    }
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   116
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   117
});