HTMLcopy
x
1
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-core.min.js"></script>
2
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-map.min.js"></script>
3
4
<script src="https://cdn.anychart.com/geodata/latest/custom/world/world.js"></script>
5
6
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-data-adapter.min.js"></script>
7
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.15/proj4.js"></script>
8
9
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-exports.min.js"></script>
10
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-ui.min.js"></script>
11
12
<script src="https://cdn.anychart.com/releases/8.9.0/themes/dark_glamour.min.js"></script>
13
14
<link rel="stylesheet" type="text/css" href="https://cdn.anychart.com/releases/8.9.0/css/anychart-ui.min.css">
15
<link rel="stylesheet" type="text/css" href="https://cdn.anychart.com/releases/8.9.0/fonts/css/anychart-font.min.css">
16
17
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
118
1
anychart.onDocumentReady(function () {
2
anychart.data.loadJsonFile(
3
'https://gist.githubusercontent.com/shacheeswadia/47b28a4d061e415555f01f5ce48e9ae3/raw/0f7592a8048872db7b77ccd2df8907e61952a806/shippingDataInverted.json',
4
function (data) {
5
6
// set the color theme
7
anychart.theme('darkGlamour');
8
9
// set the map chart
10
var map = anychart.map();
11
12
// set the global geodata
13
map.geoData('anychart.maps.world');
14
15
// set the map title
16
map.title( 'Shipping ports across the globe');
17
18
// create a dataset from data
19
var portsDataSet = anychart.data.set(data).mapAs();
20
21
// helper function to create several series
22
var createSeries = function (name, data, color) {
23
24
// set the marker series
25
var series = map.marker(data);
26
27
// configure the series settings
28
series
29
.name(name)
30
.fill(color)
31
.stroke('none')
32
.type('circle')
33
.size(3)
34
.labels(false)
35
.selectionMode('none');
36
37
series
38
.legendItem()
39
.iconType('circle')
40
.iconFill(color);
41
};
42
43
// create 5 series, filtering the data by the outflows at each port
44
createSeries(
45
'Up to 100,000',
46
portsDataSet.filter('outflows', filterFunction(0, 100000)),
47
'#D1FAE9'
48
);
49
createSeries(
50
'100,000 - 1,000,000',
51
portsDataSet.filter('outflows', filterFunction(100000, 1000000)),
52
'#9CE0E5'
53
);
54
createSeries(
55
'1,000,000 - 5,000,000',
56
portsDataSet.filter('outflows', filterFunction(1000000, 5000000)),
57
'#00ACC3'
58
);
59
createSeries(
60
'5,000,000 - 10,000,000',
61
portsDataSet.filter('outflows', filterFunction(5000000, 10000000)),
62
'#355CB1'
63
);
64
createSeries(
65
'More than 10,000,000 outflows',
66
portsDataSet.filter('outflows', filterFunction(10000000, 0)),
67
'#002D79'
68
);
69
70
// enable and configure the map tooltip
71
map
72
.tooltip()
73
.useHtml(true)
74
.padding([8, 13, 10, 13])
75
.width(350)
76
.fontSize(12)
77
.fontColor('#e6e6e6')
78
.titleFormat(function () {
79
return this.getData('Name');
80
})
81
.format(function () {
82
return (
83
'<span style="color: #bfbfbf">Country: </span>'+
84
this.getData('Country') +
85
'<br/>' +
86
'<span style="color: #bfbfbf">Outflows: </span>' +
87
this.getData('outflows').toFixed(0)
88
);
89
});
90
91
// turn on the map legend
92
map.legend(true);
93
94
// add zoom ui controls
95
var zoomController = anychart.ui.zoom();
96
zoomController.render(map);
97
98
// set the container
99
map.container('container');
100
101
// draw the map
102
map.draw();
103
104
}
105
);
106
});
107
108
// helper filter function
109
function filterFunction(val1, val2) {
110
if (val2) {
111
return function (fieldVal) {
112
return val1 <= fieldVal && fieldVal < val2;
113
};
114
}
115
return function (fieldVal) {
116
return val1 <= fieldVal;
117
};
118
}