HTMLcopy
1
<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
x
1
anychart.onDocumentReady(function () {
2
// create data set
3
var dataSet = anychart.data.set(getData());
4
5
// create map chart
6
var map = anychart.map();
7
// set geodata using https://cdn.anychart.com/geodata/latest/countries/france/france.js
8
map.geoData('anychart.maps.france');
9
map.padding(0);
10
11
var regionData;
12
// create map title
13
map
14
.title()
15
.enabled(true)
16
.padding([20, 0, 20, 0])
17
.text(
18
'Coordinates and the region name\nby moving the cursor over the map of France'
19
);
20
21
var label = map.label();
22
var labelFormat =
23
'<span style=\'color: #545f69; font-size: 14px\'><b>lat</b>: %s;<br/><b>long</b>: %s;<br/><b>region</b>: %s</span>';
24
label
25
.enabled(true)
26
.useHtml(true)
27
.padding(10)
28
.hAlign('left')
29
.position('right-top')
30
.anchor('right-top')
31
.offsetY(80)
32
.offsetX(20)
33
.width(280)
34
.text(anychart.format.subs(labelFormat, '', '', ''));
35
label
36
.background()
37
.fill('#FCFCFC')
38
.stroke('#E1E1E1')
39
.corners(3)
40
.cornerType('ROUND');
41
42
// create choropleth series
43
var series = map.choropleth(dataSet);
44
series
45
.tooltip()
46
.title(false)
47
.separator(false)
48
.format(function () {
49
return (
50
'<span>' +
51
this.name +
52
'</span><br/>' +
53
'<span style="font-size: 14px; color: #E1E1E1">id: ' +
54
this.id +
55
'</span>'
56
);
57
});
58
series
59
.selectionMode('none')
60
.labels(false)
61
.fill('#F7F7F7')
62
.stroke('#B9B9B9')
63
.tooltip()
64
.useHtml(true)
65
.padding([8, 13, 10, 13])
66
.fontSize(16);
67
68
series.hovered().fill('#64b5f6');
69
70
// set series geo id field settings
71
series.geoIdField('id');
72
73
// add pointsHover listener to get hovered region
74
map.listen('pointsHover', function (evt) {
75
if (evt.seriesStatus[0].points[0]) {
76
regionData = evt.seriesStatus[0].points[0].properties.name;
77
} else regionData = undefined;
78
});
79
80
// add mouseMove listener to calc lat/long
81
map.listen('mouseMove', function (evt) {
82
var localCord = map.globalToLocal(evt.clientX, evt.clientY);
83
var latLong = map.inverseTransform(localCord.x, localCord.y);
84
if (regionData) {
85
label.text(
86
anychart.format.subs(
87
labelFormat,
88
latLong.lat,
89
latLong.long,
90
regionData
91
)
92
);
93
} else {
94
label.text(
95
anychart.format.subs(labelFormat, latLong.lat, latLong.long, '')
96
);
97
}
98
});
99
100
// set container id for the chart
101
map.container('container');
102
103
// initiate chart drawing
104
map.draw();
105
});
106
107
function getData() {
108
return [
109
{ id: 'FR.ARA' },
110
{ id: 'FR.BFC' },
111
{ id: 'FR.BRE' },
112
{ id: 'FR.COR' },
113
{ id: 'FR.CVL' },
114
{ id: 'FR.GES' },
115
{ id: 'FR.GF' },
116
{ id: 'FR.GUA' },
117
{ id: 'FR.HDF' },
118
{ id: 'FR.IDF' },
119
{ id: 'FR.LRE' },
120
{ id: 'FR.MAY' },
121
{ id: 'FR.MQ' },
122
{ id: 'FR.NAQ' },
123
{ id: 'FR.NOR' },
124
{ id: 'FR.OCC' },
125
{ id: 'FR.PAC' },
126
{ id: 'FR.PDL' }
127
];
128
}