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
var stage = acgraph.create('container');
3
4
$('#container')
5
.append(
6
'<div class="seat-map-title">' +
7
'<h1>District Map</h1>' +
8
'<p>Source <a href="https://cdn.anychart.com/svg-data/' +
9
'seat-map/map.svg" target="_blank">SVG Image</a><br>' +
10
'</p></div>'
11
)
12
.append(
13
'<a href="http://www.freepik.com" ' +
14
'class="link-freepik" target="_blank">Designed by Freepik</a>'
15
);
16
17
// get svg file
18
$.ajax({
19
type: 'GET',
20
url: 'https://cdn.anychart.com/svg-data/seat-map/map.svg',
21
// The data that have been used for this sample can be taken from the CDN
22
// load SVG image using jQuery ajax
23
success: function (svgData) {
24
// data for creating a SeatMap
25
var chart = anychart.seatMap([
26
{
27
id: 'gas-station',
28
name: 'Gas station'
29
},
30
{
31
id: 'hotel',
32
name: 'Hotel'
33
},
34
{
35
id: 'coffee-house',
36
name: 'Coffee House'
37
},
38
{
39
id: 'park',
40
name: 'Park'
41
},
42
{
43
id: 'restaurant',
44
name: 'Restaurant'
45
}
46
]);
47
// set svg data
48
chart.geoData(svgData);
49
// load svg-file how it looked(colors stroke/fill except
50
// for elements of series)
51
chart
52
.unboundRegions('as-is')
53
// set chart padding
54
.padding([85, 0, 20, 0]);
55
56
var series = chart.getSeries(0);
57
// sets fill series
58
series.fill(function () {
59
var attrs = this.attributes;
60
61
if (attrs) {
62
var itemClass = attrs.class;
63
if (attrs) {
64
switch (itemClass) {
65
case 'ellipse':
66
return 'none';
67
default:
68
return attrs.fill;
69
}
70
} else {
71
return this.sourceColor;
72
}
73
}
74
});
75
76
// sets stroke series
77
series.stroke(function () {
78
var attrs = this.attributes;
79
80
return attrs ? attrs.stroke : this.sourceColor;
81
});
82
83
// sets fill on hover series
84
series.hovered().fill(returnColorHoverSelectFill);
85
// sets stroke on hover stroke
86
series.hovered().stroke(function () {
87
var attrs = this.attributes;
88
89
return attrs ? attrs.stroke : this.sourceColor;
90
});
91
// sets fill on select series
92
series.selected().fill(returnColorHoverSelectFill);
93
94
// settings for chart tooltip
95
var tooltip = series.tooltip();
96
tooltip
97
.fontSize(15)
98
.title(false)
99
.separator(false)
100
.format('{%name}');
101
102
// label info
103
var infoLabel = chart.label();
104
infoLabel
105
.useHtml(true)
106
.padding(10)
107
.hAlign('left')
108
.fontColor('#212121')
109
.position('right-top')
110
.anchor('right-top')
111
.zIndex(100)
112
.offsetY(85)
113
.offsetX(20)
114
.width(165)
115
.text('Click on a marker<br>to see<br>more information.');
116
infoLabel.background({
117
fill: '#FCFCFC',
118
stroke: '#E1E1E1',
119
corners: 3,
120
cornerType: 'ROUND'
121
});
122
123
// picture label
124
var pictureLabel = chart.label(1);
125
pictureLabel
126
.enabled(false)
127
.padding(10)
128
.background(true)
129
.position('right-top')
130
.anchor('right-top')
131
.offsetY(125)
132
.offsetX(40)
133
.width(200)
134
.height(100)
135
.text('');
136
137
chart.listen('pointsSelect', function (points) {
138
var point = points.seriesStatus[0].points;
139
140
if (chart.getSelectedPoints().length) {
141
var pointIndex = point[0].index;
142
// from the CDN https://cdn.anychart.com/csv-data/map-info.js
143
var info = mapInfo(); // eslint-disable-line no-undef
144
var state = info[pointIndex];
145
146
pictureLabel
147
.background()
148
.fill({
149
src: state.picture,
150
mode: 'fit'
151
})
152
.stroke(null);
153
pictureLabel.enabled(true).zIndex(100);
154
155
infoLabel
156
.text(
157
'<span style="font-size: 16px;">' +
158
state.name +
159
'</span><br/><br/><br/><br/><br/><br/><br/><br/><br/>' +
160
'<span style="color: #8c8c8c">Address: </span>' +
161
state.address +
162
'<br/>' +
163
'<span style="color: #8c8c8c">Phone: </span>' +
164
state.phone +
165
'<br/>' +
166
hoursOrDescription(point[0].id, state)
167
)
168
.enabled(true)
169
.zIndex(90)
170
.width(250);
171
}
172
});
173
174
// add chartClick listener to hide infoLabel/pictureLabel
175
chart.listen('click', function () {
176
if (chart.getSelectedPoints().length === 0) {
177
infoLabel.enabled(false);
178
pictureLabel.enabled(false);
179
}
180
});
181
182
// set container id for the chart
183
chart.container(stage);
184
// initiate chart drawing
185
chart.draw();
186
}
187
});
188
});
189
190
function returnColorHoverSelectFill() {
191
var attrs = this.attributes;
192
193
if (attrs) {
194
var itemClass = attrs.class;
195
if (attrs) {
196
switch (itemClass) {
197
case 'ellipse':
198
return '#546269';
199
default:
200
return attrs.fill;
201
}
202
} else {
203
return this.sourceColor;
204
}
205
}
206
}
207
208
function isOpen(date) {
209
var d = new Date();
210
var min = 60;
211
var currentTime = d.getHours() * min + d.getMinutes();
212
var openHours = parseInt(date.split('-')[0]);
213
var closeHours = parseInt(date.split('-')[1]);
214
215
if (currentTime >= openHours * min && currentTime <= closeHours * min) {
216
return 'Open today';
217
}
218
return 'Close today';
219
}
220
221
function hoursOrDescription(id, state) {
222
switch (id) {
223
case 'park':
224
case 'hotel':
225
return (
226
'<span style="color: #8c8c8c">Description: </span>' +
227
state.description
228
);
229
case 'gas-station':
230
return (
231
'<span style="color: #8c8c8c">Diesel: </span>' +
232
state.diesel +
233
'<br>' +
234
'<span style="color: #8c8c8c">Regular: </span>' +
235
state.regular +
236
'<br>' +
237
'<span style="color: #8c8c8c">Midgrade: </span>' +
238
state.midgrade +
239
'<br>' +
240
'<span style="color: #8c8c8c">Premium: </span>' +
241
state.premium
242
);
243
default:
244
return (
245
'<span style="color: #8c8c8c">Hours: </span>' +
246
state.hours +
247
' | <span><b><i>' +
248
isOpen(state.hours24Format) +
249
'</b></i></span>'
250
);
251
}
252
}