1
|
import { MapCountryData } from '../../domain/map-country-data';
|
2
|
|
3
|
declare var require: any;
|
4
|
|
5
|
import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core';
|
6
|
|
7
|
import * as Highcharts from 'highcharts';
|
8
|
import MapModule from 'highcharts/modules/map';
|
9
|
import {CountryOverview} from '../../domain/overview-data';
|
10
|
|
11
|
const mapWorld = require('@highcharts/map-collection/custom/world.geo.json');
|
12
|
const mapEurope = require('@highcharts/map-collection/custom/europe.geo.json');
|
13
|
|
14
|
MapModule(Highcharts);
|
15
|
|
16
|
@Component({
|
17
|
selector: 'app-country-map',
|
18
|
templateUrl: './country-map.component.html',
|
19
|
encapsulation: ViewEncapsulation.None
|
20
|
})
|
21
|
|
22
|
export class CountryMapComponent implements OnInit {
|
23
|
|
24
|
@Input() country: string;
|
25
|
|
26
|
Highcharts: typeof Highcharts = Highcharts;
|
27
|
|
28
|
chartMapOptions: Highcharts.Options;
|
29
|
|
30
|
mapCountryData: MapCountryData[] = [];
|
31
|
seriesColor: string = '#ff9800';
|
32
|
seriesName: string = 'OA publications';
|
33
|
|
34
|
europe: string[] = [];
|
35
|
countryNames: string[] = [];
|
36
|
|
37
|
constructor() {}
|
38
|
|
39
|
ngOnInit(): void {
|
40
|
this.countryNames.push(this.country);
|
41
|
console.log('this.country', this.country);
|
42
|
console.log('this.countryNames', this.countryNames);
|
43
|
this.mapCountryData.push(this.overviewToMapData());
|
44
|
this.loadMap(this.mapCountryData, this.seriesColor, this.seriesName, this.country);
|
45
|
}
|
46
|
|
47
|
overviewToMapData(): MapCountryData {
|
48
|
this.seriesColor = '#A26C0A';
|
49
|
this.seriesName = 'OA policies';
|
50
|
return {
|
51
|
id: this.country,
|
52
|
country: this.country,
|
53
|
z: 5
|
54
|
};
|
55
|
}
|
56
|
|
57
|
loadMap(mapCountryData: MapCountryData[], seriesColor: string, seriesName: string, countryName: string) {
|
58
|
this.chartMapOptions = {
|
59
|
chart: {
|
60
|
map: mapWorld,
|
61
|
events: {
|
62
|
load: function() {
|
63
|
this.series[0].data = this.series[0].data.map((el) => {
|
64
|
if ((el.name === countryName)) {
|
65
|
el.color = 'rgba(139,151,167,0.6)';
|
66
|
return el;
|
67
|
}
|
68
|
return el;
|
69
|
});
|
70
|
this.update({
|
71
|
series: [{
|
72
|
data: this.series[0].data as Highcharts.SeriesMapbubbleDataOptions,
|
73
|
} as Highcharts.SeriesMapbubbleOptions]
|
74
|
});
|
75
|
let x, y;
|
76
|
for (let i = 0; i < mapCountryData.length; i++) {
|
77
|
if (mapCountryData[i].hasOwnProperty('name')) {
|
78
|
if (mapCountryData[i]['name'] === countryName) {
|
79
|
console.log(mapCountryData[i]);
|
80
|
if (mapCountryData[i].hasOwnProperty('_midX')) {
|
81
|
x = mapCountryData[i]['_midX'];
|
82
|
}
|
83
|
if (mapCountryData[i].hasOwnProperty('_midY')) {
|
84
|
y = mapCountryData[i]['_midY'];
|
85
|
}
|
86
|
break;
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
this.mapZoom(0.1, x, y);
|
91
|
}
|
92
|
}
|
93
|
},
|
94
|
title: {
|
95
|
text: ''
|
96
|
},
|
97
|
legend: {
|
98
|
enabled: false
|
99
|
},
|
100
|
colorAxis: {
|
101
|
min: 0
|
102
|
},
|
103
|
series: [{
|
104
|
// name: 'Countries',
|
105
|
// borderColor: '#fff',
|
106
|
// negativeColor: 'rgba(139,151,167,0.2)',
|
107
|
// enableMouseTracking: false,
|
108
|
// type: 'map'
|
109
|
// }, {
|
110
|
name: 'Random data',
|
111
|
type: 'map',
|
112
|
// joinBy: ['name', 'country'],
|
113
|
data : mapCountryData,
|
114
|
// data: [
|
115
|
// ['is', 1],
|
116
|
// ['no', 1],
|
117
|
// ['se', 1],
|
118
|
// ['dk', 1],
|
119
|
// ['fi', 1]
|
120
|
// ],
|
121
|
// states: {
|
122
|
// hover: {
|
123
|
// color: '#BADA55'
|
124
|
// }
|
125
|
// },
|
126
|
// dataLabels: {
|
127
|
// enabled: true,
|
128
|
// format: '{point.name}'
|
129
|
// },
|
130
|
// allAreas: false,
|
131
|
// joinBy: ['name', 'country'],
|
132
|
// data : mapCountryData
|
133
|
} as Highcharts.SeriesMapOptions]
|
134
|
};
|
135
|
|
136
|
}
|
137
|
}
|