HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// This sample uses 3rd party proj4 component
4
// that makes it possible to set coordinates
5
// for the points and labels on the map and
6
// required for custom projections and grid labels formatting.
7
// See https://docs.anychart.com/7.14.3/Maps/Map_Projections
8
9
// create a container for maps and a button
10
stage = anychart.graphics.create("container");
11
12
// data sets
13
worldDataSet = anychart.data.set([
14
{id: "US"}
15
]);
16
usaDataSet = anychart.data.set([
17
{id: "US.TX"}
18
]);
19
20
// world map
21
var chart = anychart.map();
22
chart.geoData(anychart.maps.world);
23
worldSeries = chart.choropleth(worldDataSet);
24
25
// usa map
26
usaMap = anychart.map();
27
usaMap.geoData(anychart.maps.united_states_of_america);
28
usaSeries = usaMap.choropleth(usaDataSet);
29
30
// texas map
31
txMap = anychart.map();
32
txMap.geoData(anychart.maps["texas"]);
33
34
// set drill down for maps
35
worldSeries.listen("pointClick", function(e) {
36
// Drill down to the specified map.
37
chart.drillTo(e.point.get("id"), usaMap);
38
});
39
40
usaSeries.listen("pointClick", function(e) {
41
// Drill down to the specified map.
42
chart.drillTo(e.point.get("id"), txMap);
43
});
44
45
// listen for draw event and update path in a title
46
chart.listen("chartDraw",function(){
47
// get drilldown path
48
var path = chart.getDrilldownPath();
49
50
// get link to the current chart
51
var cv = path[path.length - 1].getCurrentChart();
52
53
// update path in the title of appropriate instance
54
cv.title(printPath(path))
55
});
56
57
// create drill up label
58
drillToLabel = createLabel("Drill Up", 0, function() {
59
// Drill down to the specified item.
60
chart.drillUp();
61
});
62
63
// set chart bounds and display it
64
chart.container(stage);
65
chart.draw();
66
67
});
68
69
// function to turn current drill down path structure to string
70
function printPath(path){
71
// root element is the World in this case
72
var text = "World";
73
// go through the next levels
74
for (i = 1; i < path.length; i++) {
75
text += " -> " + path[i].getProperties().name;
76
}
77
return text;
78
}
79
80
// helper function to create buttons
81
function createLabel(text, offset, action){
82
var label = anychart.standalones.label();
83
label.background({fill: "#9E9E9E"});
84
label.zIndex(1000);
85
label.text(text);
86
label.fontColor("#fff");
87
label.padding(5);
88
label.parentBounds(offset, 5, 130, 100);
89
label.listen("click", action);
90
label.container(stage);
91
label.draw();
92
return label;
93
}