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
<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
90
1
anychart.onDocumentReady(function () {
2
anychart.data.loadJsonFile( 'https://gist.githubusercontent.com/shacheeswadia/47b28a4d061e415555f01f5ce48e9ae3/raw/0f7592a8048872db7b77ccd2df8907e61952a806/shippingDataInverted.json',
3
function (data) {
4
5
// set the map chart
6
var map = anychart.map();
7
8
// set the global geodata
9
map.geoData('anychart.maps.world');
10
11
// set the map title
12
map.title( 'Shipping ports across the globe');
13
14
// creates dataset from entire data
15
var portsDataSet = anychart.data.set(data).mapAs();
16
17
// helper function to create several series
18
var createSeries = function (name, data, color) {
19
20
// set the marker series for the ports
21
var series = map.marker(data);
22
23
// configure the series settings
24
series
25
.name(name)
26
.fill(color)
27
.stroke('2 #E1E1E1')
28
.type('circle')
29
.size(5)
30
.labels(false)
31
.selectionMode('none');
32
33
series
34
.legendItem()
35
.iconType('circle')
36
.iconFill(color)
37
.iconStroke('2 #E1E1E1');
38
};
39
40
// create 5 series, filtering the data by the outflows at each port
41
createSeries(
42
'Up to 100,000',
43
portsDataSet.filter('outflows', filterFunction(0, 100000)),
44
'#D1FAE9'
45
);
46
createSeries(
47
'100,000 - 1,000,000',
48
portsDataSet.filter('outflows', filterFunction(100000, 1000000)),
49
'#9CE0E5'
50
);
51
createSeries(
52
'1,000,000 - 5,000,000',
53
portsDataSet.filter('outflows', filterFunction(1000000, 5000000)),
54
'#00ACC3'
55
);
56
createSeries(
57
'5,000,000 - 10,000,000',
58
portsDataSet.filter('outflows', filterFunction(5000000, 10000000)),
59
'#355CB1'
60
);
61
createSeries(
62
'More than 10,000,000 outflows',
63
portsDataSet.filter('outflows', filterFunction(10000000, 0)),
64
'#002D79'
65
);
66
67
// turn on the map legend
68
map.legend(true);
69
70
// set the container
71
map.container('container');
72
73
// draw the map
74
map.draw();
75
76
}
77
);
78
});
79
80
// helper filter function
81
function filterFunction(val1, val2) {
82
if (val2) {
83
return function (fieldVal) {
84
return val1 <= fieldVal && fieldVal < val2;
85
};
86
}
87
return function (fieldVal) {
88
return val1 <= fieldVal;
89
};
90
}