cms/app-client/app/components/visu-carto.js
author Chloe Laisne <chloe.laisne@gmail.com>
Fri, 24 Jun 2016 02:07:09 +0200
changeset 204 dd969e178944
parent 200 a441c40f9c5e
child 273 a719b2dcea34
permissions -rw-r--r--
Fix linting, remove logs and dead code
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
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 193
diff changeset
     6
  filter: Ember.inject.service(),
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 193
diff changeset
     7
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     8
  didInsertElement: function(){
51
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents: 45
diff changeset
     9
    var _this = this;
45
b9adc23abd01 update visualisation with sample values
nowmad@nowmads-macbook-pro.local
parents: 38
diff changeset
    10
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    11
    this.$('#mapdiv').height(Ember.$('.corpus-app-container').height());
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    12
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    13
    var franceDataProvider = {
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    14
        mapVar: AmCharts.maps.france2016Low,
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    15
        getAreasFromMap:true,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    16
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    17
        areas: this.initArea(AmCharts.maps.france2016Low)
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    18
    };
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    19
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    20
    var worldDataProvider = {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    21
        map: "worldLow",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    22
        getAreasFromMap: true,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    23
        images: [{
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    24
            id: "backButton",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    25
            label: "Back to continents map",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    26
            rollOverColor: "#CC0000",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    27
            labelRollOverColor: "#CC0000",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    28
            useTargetsZoomValues: true,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    29
            left: 30,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    30
            bottom: 30,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    31
            labelFontSize: 15,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    32
            selectable: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    33
        }],
62
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
    34
        areas: this.initArea(AmCharts.maps.worldLow, franceDataProvider)
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    35
    };
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    36
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    37
45
b9adc23abd01 update visualisation with sample values
nowmad@nowmads-macbook-pro.local
parents: 38
diff changeset
    38
    var continentsDataProvider = {
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    39
        map: "continentsLow",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    40
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    41
        areas: [{
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    42
            id: "africa",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    43
            linkToObject: worldDataProvider,
193
64afd482ac71 /thematiques endpoint autocomplete design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 123
diff changeset
    44
            color: "#373737",
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    45
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    46
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    47
            id: "asia",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    48
            linkToObject: worldDataProvider,
193
64afd482ac71 /thematiques endpoint autocomplete design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 123
diff changeset
    49
            color: "#515151",
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    50
            selectable: false,
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    51
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    52
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    53
            id: "australia",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    54
            linkToObject: worldDataProvider,
193
64afd482ac71 /thematiques endpoint autocomplete design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 123
diff changeset
    55
            color: "#6c6c6c",
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    56
            selectable: false,
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    57
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    58
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    59
            id: "europe",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    60
            linkToObject: worldDataProvider,
193
64afd482ac71 /thematiques endpoint autocomplete design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 123
diff changeset
    61
            color: "#888888",
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    62
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    63
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    64
            id: "north_america",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    65
            linkToObject: worldDataProvider,
193
64afd482ac71 /thematiques endpoint autocomplete design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 123
diff changeset
    66
            color: "#a2a2a2",
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    67
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    68
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    69
            id: "south_america",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    70
            linkToObject: worldDataProvider,
193
64afd482ac71 /thematiques endpoint autocomplete design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 123
diff changeset
    71
            color: "#f1f1f1",
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    72
            selectable: false,
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    73
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    74
        }]
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    75
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    76
    };
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    77
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    78
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    79
    var map = AmCharts.makeChart("mapdiv", {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    80
        type: "map",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    81
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    82
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    83
        areasSettings: {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    84
            autoZoom: true,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    85
            rollOverOutlineColor: "#000000",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    86
            selectedOutlineColor: "#CC0000",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    87
            selectedColor: "green",
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    88
            color: "#fff"
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    89
        },
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    90
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    91
        dataProvider: continentsDataProvider,
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    92
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    93
        listeners: [{event:"clickMapObject", method:handleMapObjectClick}]
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    94
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    95
    });
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    96
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    97
    function handleGoHome() {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    98
        map.dataProvider = continentsDataProvider;
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    99
        map.validateNow();
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   100
    }
45
b9adc23abd01 update visualisation with sample values
nowmad@nowmads-macbook-pro.local
parents: 38
diff changeset
   101
    function handleMapObjectClick (event) {
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
   102
        if (event.mapObject.id === "backButton") {
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   103
            handleGoHome();
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   104
        }
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 193
diff changeset
   105
        _this.get('filter').set('location', event.mapObject.title);
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   106
    }
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   107
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   108
    // monitor when home icon was clicked and also go to continents map
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   109
    map.addListener("homeButtonClicked", handleGoHome);
62
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   110
  },
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   111
  initArea: function(area, dataProvider){
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   112
    var _this = this;
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   113
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   114
    var areaList = [];
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   115
    var count = {};
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
   116
    area.svg.g.path.map(function(elt){
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 84
diff changeset
   117
      var length = _this.get("documents").filterBy("spatial", elt.title).toArray().length;
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
   118
      if (length > 0){
62
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   119
        count[elt.id]= length;
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
   120
      }
62
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   121
    });
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
   122
    area.svg.g.path.map(function(elt){
62
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   123
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   124
      areaList.push({
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   125
        id: elt.id,
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   126
        linkToObject: (elt.id === "FR" ? dataProvider : ""),
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
   127
        color: ((typeof(count[elt.id]) === "undefined") ? "#fff" : "#2D7073"),
62
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   128
        autoZoom: (elt.id === "FR" ? true : false),
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   129
        selectable: true,
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   130
        passZoomValuesToTarget: false
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   131
      });
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   132
    });
6fc7d50c6b5d remove unecessary svg icon and update the way we define the area to make it more automatic
nowmad@23.1.168.192.in-addr.arpa
parents: 51
diff changeset
   133
    return areaList;
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   134
  }
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   135
});