forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphThemeLayer.html
More file actions
462 lines (423 loc) · 17.9 KB
/
graphThemeLayer.html
File metadata and controls
462 lines (423 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title data-i18n="resources.title_graphThemeLayer"></title>
<script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<script type="text/javascript" src="../data/chinaConsumptionLevel.js"></script>
<style>
body, #map {
position: absolute;
width: 100%;
height: 100%
}
.editPane {
position: absolute;
right: 65px;
top: 8px;
text-align: center;
background: #FFF;
z-index: 1000;
border-radius: 4px;
}
.tooltip-inner {
width: 68px;
background-color: transparent;
color: #515151;
}
.graph {
margin: 5px;
width: 26px;
height: 26px;
border: none;
border-radius: 4px;
background-size: 100%;
}
#bar {
background-image: url("../img/bar.png");
}
#bar3d {
background-image: url("../img/bar3D.png");
}
#ling {
background-image: url("../img/ling.png");
}
#point {
background-image: url("../img/point.png");
}
#pie {
background-image: url("../img/pie.png");
}
#ring {
background-image: url("../img/ring.png");
}
</style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div class="editPane" role="group" aria-label="...">
<button type='button' class='btn btn-default graph active' id='bar' data-toggle='tooltip' data-placement='bottom'
data-i18n="[title]resources.title_GraphBar"></button>
<button type='button' class='btn btn-default graph' id='bar3d' data-toggle='tooltip' data-placement='bottom'
data-i18n="[title]resources.title_GraphBar3D"></button>
<button type='button' class='btn btn-default graph' id='ling' data-toggle='tooltip' data-placement='bottom'
data-i18n="[title]resources.title_GraphLine"></button>
<button type='button' class='btn btn-default graph' id='point' data-toggle='tooltip' data-placement='bottom'
data-i18n="[title]resources.title_GraphPoint"></button>
<button type='button' class='btn btn-default graph' id='pie' data-toggle='tooltip' data-placement='bottom'
data-i18n="[title]resources.title_GraphPie"></button>
<button type='button' class='btn btn-default graph' id='ring' data-toggle='tooltip' data-placement='bottom'
data-i18n="[title]resources.title_GraphRing"></button>
</div>
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
<script type="text/javascript">
var themeLayer, popup,
host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090",
url = host + "/iserver/services/map-china400/rest/maps/China_4326";
var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
" with <span>© <a href='http://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
" Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
var map = new mapboxgl.Map({
container: 'map',
style: {
"version": 8,
"sources": {
"raster-tiles": {
"attribution": attribution,
"type": "raster",
"tiles": [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
"tileSize": 256,
},
},
"layers": [{
"id": "simple-tiles",
"type": "raster",
"source": "raster-tiles",
"minzoom": 0,
"maxzoom": 22
}]
},
center: [105.85, 36.79],
zoom: 3.8
});
map.addControl(new mapboxgl.NavigationControl(), 'top-left');
map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
bindEvent();
initFeaterDatasAddStyles();
createBarThemeLayer();
function bindEvent() {
$("[data-toggle='tooltip']").on("mouseover", function () {
$("[data-toggle='tooltip']").tooltip();
});
$("[data-toggle='tooltip']").on("mouseout", function () {
$("[data-toggle='tooltip']").tooltip("hide");
});
$(".graph").on("click", function () {
$(".graph").removeClass("active");
});
$("#bar").on("click", function () {
$("#bar").addClass("active");
initFeaterDatasAddStyles();
clearThemeLayer();
createBarThemeLayer();
});
$("#bar3d").on("click", function () {
$("#bar3d").addClass("active");
initFeaterDatasAddStyles();
clearThemeLayer();
createBar3DThemeLayer();
});
$("#ling").on("click", function () {
$("#ling").addClass("active");
initFeaterDatasAddStyles();
clearThemeLayer();
createLineThemeLayer();
});
$("#point").on("click", function () {
$("#point").addClass("active");
initFeaterDatasAddStyles();
clearThemeLayer();
createPointThemeLayer();
});
$("#pie").on("click", function () {
$("#pie").addClass("active");
initFeaterDatasAddStyles();
clearThemeLayer();
createPieThemeLayer();
});
$("#ring").on("click", function () {
$("#ring").addClass("active");
initFeaterDatasAddStyles();
clearThemeLayer();
createRingThemeLayer();
});
}
var features,
chartsSettingForBarAddBar3DCommon,
chartsSettingForPointOrLine,
chartsSettingForPieOrRing,
themeLayerOptions;
function initFeaterDatasAddStyles() {
//创建附着要素
// features = [];
var feas = [];
for (var i = 0, len = chinaConsumptionLevel.length; i < len; i++) {
// 省居民消费水平(单位:元)信息
var provinceInfo = chinaConsumptionLevel[i];
//支持传入 mapboxgl.supermap.ThemeFeature 类型:
/* var geo = new mapboxgl.LngLat(provinceInfo[1], provinceInfo[2]);
var attrs = {};
attrs.NAME = provinceInfo[0];
attrs.CON2009 = provinceInfo[3];
attrs.CON2010 = provinceInfo[4];
attrs.CON2011 = provinceInfo[5];
attrs.CON2012 = provinceInfo[6];
attrs.CON2013 = provinceInfo[7];
var fea = new mapboxgl.supermap.ThemeFeature(geo, attrs);
features.push(fea);*/
//支持 传入 GeoJSON 规范数据类型:
var fea = {
"type": "feature",
"geometry": {
"type": "Point",
"coordinates": [provinceInfo[1], provinceInfo[2]]
},
"properties": {
"NAME": provinceInfo[0],
"CON2009": provinceInfo[3],
"CON2010": provinceInfo[4],
"CON2011": provinceInfo[5],
"CON2012": provinceInfo[6],
"CON2013": provinceInfo[7],
}
};
feas.push(fea);
}
features = {
"type": "FeatureCollection",
"features": feas
};
//Bar add Bar3D chartsSetting
chartsSettingForBarAddBar3DCommon = {
width: 260,
height: 120,
codomain: [0, 40000],
xShapeBlank: [15, 15, 15],
axisYTick: 4,
axisYLabels: ["4万", "3万", "2万", "1万", "0"],
axisXLabels: ["09年", "10年", "11年", "12年", "13年"],
backgroundRadius: [5, 5, 5, 5],
backgroundStyle: {
fillColor: "#d1eeee",
shadowBlur: 12,
shadowColor: "#d1eeee"
}
};
//Point add Line chartsSetting
chartsSettingForPointOrLine = {
width: 220,
height: 100,
codomain: [0, 40000],
xShapeBlank: [10, 10],
axisYTick: 4,
axisYLabels: ["4万", "3万", "2万", "1万", "0"],
axisXLabels: ["09年", "10年", "11年", "12年", "13年"],
backgroundStyle: {fillColor: "#d1eeee"},
backgroundRadius: [5, 5, 5, 5],
useXReferenceLine: true,
pointStyle: {
pointRadius: 5,
shadowBlur: 12,
shadowColor: "#D8361B",
fillOpacity: 0.8
},
pointHoverStyle: {
stroke: true,
strokeColor: "#D8361B",
strokeWidth: 2,
fillColor: "#ffffff",
pointRadius: 4
},
};
//Pie add Ring chartsSetting
chartsSettingForPieOrRing = {
width: 240,
height: 100,
codomain: [0, 40000], // 允许图表展示的值域范围,此范围外的数据将不制作图表
sectorStyle: {fillOpacity: 0.8}, // 柱状图中柱条的(表示字段值的图形)样式
sectorStyleByFields: [
{fillColor: "#FFB980"},
{fillColor: "#5AB1EF"},
{fillColor: "#B6A2DE"},
{fillColor: "#2EC7C9"},
{fillColor: "#D87A80"}],
sectorHoverStyle: {fillOpacity: 1},
xShapeBlank: [10, 10, 10], // 水平方向上的空白间距参数
axisYLabels: ["4万", "3万", "2万", "1万", "0"], // y 轴标签内容
axisXLabels: ["09年", "10年", "11年", "12年", "13年"], // x 轴标签内容
backgroundStyle: {fillColor: "#CCE8CF"}, // 背景样式
backgroundRadius: [5, 5, 5, 5], // 背景框圆角参数
};
//设置graphThemeLayer option参数
themeLayerOptions = {
// map: map,//该可选参数将在下个版本遗弃
attributions: " ",
themeFields: ["CON2009", "CON2010", "CON2011", "CON2012", "CON2013"],
opacity: 0.9,
chartsSetting: {},
};
}
function createBarThemeLayer() {
var chartsSettingForBar = chartsSettingForBarAddBar3DCommon;
chartsSettingForBar.barStyle = {fillOpacity: 0.7}; // 柱状图中柱条的(表示字段值的图形)样式
chartsSettingForBar.barHoverStyle = {fillOpacity: 1}; // 柱条 hover 样式
//阴影样式
chartsSettingForBar.barShadowStyle = {
shadowBlur: 8,
shadowOffsetX: 2,
shadowOffsetY: 2,
shadowColor: "rgba(100,100,100,0.8)"
};
chartsSettingForBar.barLinearGradient = [
["#00FF00", "#00CD00"],
["#00CCFF", "#5E87A2"],
["#00FF66", "#669985"],
["#CCFF00", "#94A25E"],
["#FF9900", "#A2945E"]];
themeLayerOptions.chartsSetting = chartsSettingForBar;
themeLayer = new mapboxgl.supermap.GraphThemeLayer("BarLayer", "Bar", themeLayerOptions);
map.addLayer(themeLayer);
//专题图层 mousemove 事件
themeLayer.on('mousemove', showInfoWin);
themeLayer.addFeatures(features);
}
//创建Bar3D图表
function createBar3DThemeLayer() {
var chartsSettingForBar3D = chartsSettingForBarAddBar3DCommon;
chartsSettingForBar3D.useXReferenceLine = true;
chartsSettingForBar3D.xReferenceLineStyle = {strokeColor: "#008acd", strokeOpacity: 0.4};
// 3d 柱条正面样式(3d 柱条的侧面和顶面会以 3d 柱条正面样式为默认样式)
chartsSettingForBar3D.barFaceStyle = {stroke: true};
// 按字段设置 3d 柱条正面样式
chartsSettingForBar3D.barFaceStyleByFields = [
{fillColor: "#FFB980"},
{fillColor: "#5AB1EF"},
{fillColor: "#B6A2DE"},
{fillColor: "#2EC7C9"},
{fillColor: "#D87A80"}];
// 3d 柱条正面 hover 样式(3d 柱条的侧面和顶面 hover 会以 3d 柱条正面 hover 样式为默认 hover 样式)
chartsSettingForBar3D.barFaceHoverStyle = {
stroke: true,
strokeWidth: 1,
strokeColor: "#ffff00"
};
themeLayerOptions.chartsSetting = chartsSettingForBar3D;
themeLayer = new mapboxgl.supermap.GraphThemeLayer("Bar3DLayer", "Bar3D", themeLayerOptions);
map.addLayer(themeLayer);
themeLayer.addFeatures(features);
//专题图层 mousemove 事件
themeLayer.on('mousemove', showInfoWin);
}
//创建Line图表
function createLineThemeLayer() {
chartsSettingForPointOrLine.pointStyle.fillColor = "#9966CC";
themeLayerOptions.chartsSetting = chartsSettingForPointOrLine;
themeLayer = new mapboxgl.supermap.GraphThemeLayer("LineLayer", "Line", themeLayerOptions);
map.addLayer(themeLayer);
themeLayer.addFeatures(features);
//专题图层 mousemove 事件
themeLayer.on('mousemove', showInfoWin);
}
//创建Point图表
function createPointThemeLayer() {
chartsSettingForPointOrLine.pointStyle.fillColor = "#D8361B";
themeLayerOptions.chartsSetting = chartsSettingForPointOrLine;
themeLayer = new mapboxgl.supermap.GraphThemeLayer("PointLayer", "Point", themeLayerOptions);
map.addLayer(themeLayer);
themeLayer.addFeatures(features);
//专题图层 mousemove 事件
themeLayer.on('mousemove', showInfoWin);
}
//创建Pie图表
function createPieThemeLayer() {
themeLayerOptions.chartsSetting = chartsSettingForPieOrRing;
themeLayer = new mapboxgl.supermap.GraphThemeLayer("PieLayer", "Pie", themeLayerOptions);
map.addLayer(themeLayer);
themeLayer.addFeatures(features);
//专题图层 mousemove 事件
themeLayer.on('mousemove', showInfoWin);
}
//创建Ring图表
function createRingThemeLayer() {
chartsSettingForPieOrRing.innerRingRadius = 20;
themeLayerOptions.chartsSetting = chartsSettingForPieOrRing;
themeLayer = new mapboxgl.supermap.GraphThemeLayer("RingSymbolLayer", "Ring", themeLayerOptions);
map.addLayer(themeLayer);
themeLayer.addFeatures(features);
//专题图层 mousemove 事件
themeLayer.on('mousemove', showInfoWin);
}
//清除图表专题图
function clearThemeLayer() {
if (themeLayer) {
themeLayer.clear();
themeLayer.removeFromMap();
themeLayer = null;
}
}
function showInfoWin(e) {
closeInfoWin();
// e.target 是图形对象,即数据的可视化对象,柱状图中是柱条;
// 图形对象的 refDataID 属性是数据(feature)的 id 属性,它指明图形对象是由那个数据制作而来;
// 图形对象的 dataInfo 属性是图形对象表示的具体数据,他有两个属性,field 和 value;
if (e.target && e.target.refDataID && e.target.dataInfo) {
// 获取图形对应的数据 (feature)
var fea = themeLayer.getFeatureById(e.target.refDataID);
var info = e.target.dataInfo;
// 弹窗内容
var contentHTML = "<div style='color: #000; background-color: #fff'>";
contentHTML += resources.text_Name + "<br><strong>" + fea.attributes.NAME + "</strong>";
contentHTML += "<hr style='margin: 3px'>";
switch (info.field) {
case "CON2009":
contentHTML += resources.text_consumptionLevel1 + "09" + resources.text_consumptionLevel2 + "<br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
break;
case "CON2010":
contentHTML += resources.text_consumptionLevel1 + "10" + resources.text_consumptionLevel2 + "<br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
break;
case "CON2011":
contentHTML += resources.text_consumptionLevel1 + "11" + resources.text_consumptionLevel2 + "<br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
break;
case "CON2012":
contentHTML += resources.text_consumptionLevel1 + "12" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
break;
case "CON2013":
contentHTML += resources.text_consumptionLevel1 + "13" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
break;
default:
contentHTML += "No Data";
}
contentHTML += "</div>";
var tempPoint = map.unproject({x: e.event.x, y: e.event.y});
popup = new mapboxgl.Popup({closeOnClick: false})
.setLngLat([tempPoint.lng, tempPoint.lat])
.setHTML(contentHTML)
.addTo(map);
return;
}
closeInfoWin();
}
// 移除地图弹窗
function closeInfoWin() {
if (popup) {
popup.remove(map);
}
}
</script>
</body>
</html>