cms/app-client/app/components/visu-carto.js
author ymh <ymh.work@gmail.com>
Fri, 12 Feb 2016 22:31:48 +0100
changeset 123 4c97e9da1416
parent 95 f7ab931581af
child 193 64afd482ac71
permissions -rw-r--r--
Remove use of global variables + remove ember-cli-content-security-policy from package.json to avoid bogus csp violation warnings
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({
45
b9adc23abd01 update visualisation with sample values
nowmad@nowmads-macbook-pro.local
parents: 38
diff changeset
     5
  // storage: Ember.inject.service(),
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     6
  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
     7
    var _this = this;
45
b9adc23abd01 update visualisation with sample values
nowmad@nowmads-macbook-pro.local
parents: 38
diff changeset
     8
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     9
    var franceDataProvider = {
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    10
        mapVar: AmCharts.maps.france2016Low,
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    11
        getAreasFromMap:true,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    12
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    13
        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
    14
    };
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    15
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    16
    var worldDataProvider = {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    17
        map: "worldLow",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    18
        getAreasFromMap: true,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    19
        images: [{
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    20
            id: "backButton",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    21
            label: "Back to continents map",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    22
            rollOverColor: "#CC0000",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    23
            labelRollOverColor: "#CC0000",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    24
            useTargetsZoomValues: true,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    25
            left: 30,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    26
            bottom: 30,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    27
            labelFontSize: 15,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    28
            selectable: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    29
        }],
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
    30
        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
    31
    };
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    32
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    33
45
b9adc23abd01 update visualisation with sample values
nowmad@nowmads-macbook-pro.local
parents: 38
diff changeset
    34
    var continentsDataProvider = {
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    35
        map: "continentsLow",
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
        areas: [{
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    38
            id: "africa",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    39
            linkToObject: worldDataProvider,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    40
            color: "#7CACAE",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    41
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    42
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    43
            id: "asia",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    44
            linkToObject: worldDataProvider,
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    45
            color: "#fff",
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    46
            selectable: false,
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    47
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    48
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    49
            id: "australia",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    50
            linkToObject: worldDataProvider,
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    51
            color: "#fff",
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    52
            selectable: false,
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    53
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    54
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    55
            id: "europe",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    56
            linkToObject: worldDataProvider,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    57
            color: "#2D7073",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    58
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    59
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    60
            id: "north_america",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    61
            linkToObject: worldDataProvider,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    62
            color: "#B0D1D3",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    63
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    64
        }, {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    65
            id: "south_america",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    66
            linkToObject: worldDataProvider,
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    67
            color: "#fff",
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    68
            selectable: false,
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    69
            passZoomValuesToTarget: true
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    70
        }]
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    71
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    72
    };
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    73
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
    var map = AmCharts.makeChart("mapdiv", {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    76
        type: "map",
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
        areasSettings: {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    80
            autoZoom: true,
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    81
            rollOverOutlineColor: "#000000",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    82
            selectedOutlineColor: "#CC0000",
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    83
            selectedColor: "green",
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    84
            color: "#fff"
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    85
        },
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    86
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    87
        dataProvider: continentsDataProvider,
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    88
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    89
        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
    90
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    91
    });
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    92
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    93
    function handleGoHome() {
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    94
        map.dataProvider = continentsDataProvider;
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    95
        map.validateNow();
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    96
    }
45
b9adc23abd01 update visualisation with sample values
nowmad@nowmads-macbook-pro.local
parents: 38
diff changeset
    97
    function handleMapObjectClick (event) {
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 62
diff changeset
    98
      console.log("bbox: ", event.mapObject.displayObject.node.getBBox());
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
    99
        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
   100
            handleGoHome();
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   101
        }
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
   102
        _this.sendAction('action', event.mapObject.title);
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   103
    }
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   104
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   105
    // 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
   106
    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
   107
  },
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
   108
  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
   109
    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
   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
    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
   112
    var count = {};
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
   113
    area.svg.g.path.map(function(elt){
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 84
diff changeset
   114
      var length = _this.get("documents").filterBy("spatial", elt.title).toArray().length;
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
   115
      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
   116
        count[elt.id]= length;
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
   117
      }
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
   118
    });
92
3437f5191645 fix warnings
nowmad@nowmads-macbook-pro.local
parents: 91
diff changeset
   119
    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
   120
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
      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
   122
        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
   123
        linkToObject: (elt.id === "FR" ? dataProvider : ""),
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
   124
        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
   125
        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
   126
        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
   127
        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
   128
      });
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
    });
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
    return areaList;
34
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   131
  }
78a7be2ea5db create dumb template to wrap the map component visu-carto
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   132
});