HTMLcopy
1
<div id="container"></div>
2
<div id='custom-tooltip'>
3
<div id='tooltip-content'></div>
4
<div class="pagination">
5
<span id='paginator-label'>3 of 9 points</span>
6
<a id='leftPage' href="#">«</a>
7
<a id='rightPage' href="#">»</a>
8
</div>
9
</div>
10
<div id='icon-tooltip'>
11
</div>
CSScopy
x
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
8
#custom-tooltip, #icon-tooltip {
9
position: absolute;
10
display: none;
11
z-index: 10000;
12
border-radius: 3px;
13
padding: 5px 10px;
14
background-color: rgba(33, 33, 33, 0.7);
15
border: none;
16
box-sizing: border-box;
17
letter-spacing: normal;
18
color: #fff;
19
font-family: Verdana, Helvetica, Arial, 'sans-serif';
20
font-size: 12px;
21
margin: 3px 0px 3px 3px;
22
}
23
24
25
#tooltip-content {
26
height: 80%;
27
width: 100%;
28
margin: 0;
29
padding: 0;
30
}
31
32
#paginator {
33
height: 20%;
34
width: 100%;
35
margin: 0;
36
padding: 0;
37
}
38
39
.pagination {
40
display: inline-block;
41
}
42
43
.pagination span {
44
float: left;
45
padding: 8px 16px;
46
text-decoration: none;
47
}
48
49
.pagination a {
50
color: white;
51
float: left;
52
padding: 8px 6px;
53
text-decoration: none;
54
}
JavaScriptcopy
162
1
anychart.onDocumentReady(function () {
2
3
var path;
4
var coordinates = [];
5
var points;
6
var tooltip = document.getElementById('custom-tooltip');
7
var contentHtml = document.getElementById('tooltip-content');
8
var leftPage = document.getElementById('leftPage');
9
var rightPage = document.getElementById('rightPage');
10
var paginatorLabel = document.getElementById('paginator-label');
11
var stage = anychart.graphics.create("container");
12
var timeout;
13
var tooltipPages = [];
14
var currentPage = 0;
15
16
17
18
// create the dataset of points that are defined by latitude and longtitude values
19
var data = [
20
{lat: -18.50, long: 135.24, name: "Office #1", value: 293},
21
{lat: -17.89, long: 145.09, name: "Office #2", value: 198},
22
{lat: -32.26, long: 151.44, name: "Office #3", value: 219},
23
{lat: -33.28, long: 135.58, name: "Office #4", value: 309}
24
];
25
26
var map = anychart.map();
27
map.geoData(anychart.maps.australia);
28
29
// Creates the bubble series
30
var series = map.bubble(data);
31
32
map.container(stage).draw();
33
34
// create SVG button for selection
35
var svgButton = stage.rect(10, 10, 50, 50);
36
svgButton.fill({src: 'https://static.anychart.com/cdn/ts/icons/anymap.svg'});
37
svgButton.listen('click', function() {
38
map.startSelectPolygonMarquee();
39
});
40
41
var iconTooltip = document.getElementById('icon-tooltip');
42
iconTooltip.innerHTML = 'Icon tooltip text';
43
44
svgButton.listen('mouseover', function() {
45
iconTooltip.style.display = "block";
46
});
47
48
svgButton.listen('mouseout', function() {
49
iconTooltip.style.display = "none";
50
});
51
52
// update tooltip position on mousemove
53
svgButton.listen('mousemove', function(e) {
54
var clientX = e.offsetX;
55
var clientY = e.offsetY;
56
iconTooltip.style.left = clientX + 20 + "px";
57
iconTooltip.style.top = clientY + 10 + "px";
58
});
59
60
61
62
// execute custom interactivity when selection finished
63
map.listen('selectMarqueeFinish', function(e) {
64
// setTimeout is required to enqueue the task
65
setTimeout(function() {
66
selectionFinish();
67
}, 0);
68
});
69
70
map.listen('selectMarqueeChange', function(e) {
71
selectionChange(e);
72
});
73
74
map.listen('selectMarqueeStart', function(e) {
75
// drop current polygon is exists
76
if (path)
77
path.remove();
78
79
selectionChange(e);
80
});
81
82
tooltip.addEventListener("mouseout", function( event ) {
83
// hide the tooltip div
84
customTooltipMouseOut();
85
});
86
87
tooltip.addEventListener("mouseover", function( event ) {
88
clearTimeout(timeout);
89
});
90
91
leftPage.addEventListener('click', function() {
92
if (currentPage > 0) {
93
currentPage--;
94
updateTooltipContent(currentPage);
95
}
96
});
97
98
rightPage.addEventListener('click', function() {
99
if (currentPage < points.length - 1) {
100
currentPage++;
101
updateTooltipContent(currentPage);
102
}
103
});
104
105
function updateTooltipContent(currentPage) {
106
contentHtml.innerHTML = points[currentPage];
107
paginatorLabel.innerHTML = currentPage + 1 + ' of ' + points.length;
108
}
109
110
function customTooltipMouseOut() {
111
timeout = setTimeout(function(){
112
// hide the tooltip div
113
tooltip.style.display = "none";
114
}, 100)
115
}
116
117
function selectionChange(e) {
118
// collect selection polygon coordinates
119
coordinates.push({x: e.offsetX, y: e.offsetY});
120
}
121
122
function selectionFinish() {
123
// get points coordinates and related names from data
124
points = map.getSelectedPoints().map(function(point) {
125
return point.get('name');
126
});
127
128
// check if there are selected points
129
if (!points.length) return;
130
131
// draw polygon and apply fill settings
132
path = stage.path();
133
134
path.moveTo(coordinates[0].x, coordinates[0].y);
135
for (var i = 0; i < coordinates.length; i++) {
136
path.lineTo(coordinates[i].x, coordinates[i].y);
137
}
138
path.close();
139
path.fill('#cecece 0.3');
140
path.zIndex(100);
141
142
// clear coordinates
143
coordinates.length = 0;
144
tooltipPages.length = 0;
145
146
// compose cutom tooltip content
147
currentPage = 0;
148
updateTooltipContent(currentPage);
149
150
// add listeners for for the custom tooltip
151
path.listen('mouseover', function(e) {
152
clearTimeout(timeout);
153
tooltip.style.display = "block";
154
var clientX = e.offsetX;
155
var clientY = e.offsetY;
156
tooltip.style.left = clientX + "px";
157
tooltip.style.top = clientY + "px";
158
});
159
160
path.listen('mouseout', customTooltipMouseOut);
161
}
162
});