forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_fieldStatistics.html
More file actions
178 lines (169 loc) · 7.3 KB
/
02_fieldStatistics.html
File metadata and controls
178 lines (169 loc) · 7.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title data-i18n="resources.title_fieldStatistics"></title>
<style>
#popup {
position: absolute;
background-color: white;
filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
padding: 10px;
border-radius: 5px;
border: 1px solid #cccccc;
bottom: 10px;
left: 10px;
min-width: 280px;
z-index: 1;
}
</style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%">
<div id="popup">
<div id="popup-content">
<div style="line-height: 35px;">
<div id="tableName"><strong data-i18n="resources.text_layer"></strong>(continent_T@World) <strong
data-i18n="resources.text_field"></strong></div>
<div>
<div style="line-height: 35px;"><strong data-i18n="resources.text_statisticResult"></strong>
<div>
<table id="trafficRes" class="table table-bordered">
<tbody>
<tr>
<td data-i18n="resources.text_averageValue"></td>
<td data-i18n="resources.text_maxValue"></td>
<td data-i18n="resources.text_minValue"></td>
<td data-i18n="resources.text_standardDeviation"></td>
<td data-i18n="resources.text_sum"></td>
<td data-i18n="resources.text_variance"></td>
</tr>
<tr>
<td id="AVERAGE"></td>
<td id="MAX"></td>
<td id="MIN"></td>
<td id="STDDEVIATION"></td>
<td id="SUM"></td>
<td id="VARIANCE"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
<script type="text/javascript" src="../../dist/include-mapboxgl.js"></script>
<script>
var map, currentData, layersName = [],
baseUrl = (window.isLocal ? window.server : "http://support.supermap.com.cn:8090") + "/iserver/services/map-world/rest/maps/World Map",
mapUrl = baseUrl + "/zxyTileImage.png?z={z}&x={x}&y={y}",
dataUrl = (window.isLocal ? window.server : "http://support.supermap.com.cn:8090") + "/iserver/services/data-world/rest/data";
var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
"| Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> " +
" with <span>© <a href='http://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>";
map = new mapboxgl.Map({
container: 'map',
style: {
"version": 8,
"sources": {
"raster-tiles": {
"attribution": attribution,
"type": "raster",
"tiles": [mapUrl],
"tileSize": 256
}
},
"layers": [{
"id": "simple-tiles",
"type": "raster",
"source": "raster-tiles",
}]
},
center: [0, 0],
zoom: 2
});
map.addControl(new mapboxgl.NavigationControl(), 'top-left');
map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
showLayersInfo();
//获取子图层信息
function showLayersInfo() {
var subLayer;
new mapboxgl.supermap.LayerInfoService(baseUrl).getLayersInfo(function (serviceResult) {
var layers = serviceResult.result.subLayers.layers;
if (!layers) return;
for (var i = 0, len = layers.length; i < len; i++) {
subLayer = layers[i];
if ("UGC" == subLayer.type) {
//记录数据源,数据集信息供字段查询统计使用
if (subLayer.datasetInfo.name && subLayer.datasetInfo.dataSourceName) {
layersName[i] = {
dataSetName: subLayer.datasetInfo.name,
dataSourceName: subLayer.datasetInfo.dataSourceName,
layerName: subLayer.name
};
}
}
}
getFields();
});
}
function getFields() {
var name = 'continent_T@World';
var dataInfo;
for (var i = 0; i < layersName.length; i++) {
dataInfo = layersName[i];
if (dataInfo.layerName == name) {
//设置数据集,数据源,查询fields信息
currentData = dataInfo;
var param = new SuperMap.FieldParameters({
datasource: dataInfo.dataSourceName,
dataset: dataInfo.dataSetName
});
new mapboxgl.supermap.FieldService(dataUrl).getFields(param, function (serviceResult) {
fieldStatistic();
});
}
}
}
function fieldStatistic() {
var fieldName = 'SmID';
var param = new SuperMap.FieldStatisticsParameters({
datasource: currentData.dataSourceName,
dataset: currentData.dataSetName,
fieldName: fieldName,
statisticMode: [
SuperMap.StatisticMode.MAX,
SuperMap.StatisticMode.MIN,
SuperMap.StatisticMode.SUM,
SuperMap.StatisticMode.AVERAGE,
SuperMap.StatisticMode.STDDEVIATION,
SuperMap.StatisticMode.VARIANCE
]
});
if (currentData) {
new mapboxgl.supermap.FieldService(dataUrl).getFieldStatisticsInfo(param, function (serviceResult) {
showResult(serviceResult.result);
});
}
}
function showResult(serviceResult) {
if (!serviceResult) {
return;
}
var tableName = document.getElementById("tableName");
tableName.textContent += '(' + serviceResult.fieldName + ')';
var keys = ["AVERAGE", "MAX", "MIN", "STDDEVIATION", "SUM", "VARIANCE"];
document.getElementById("AVERAGE").textContent += serviceResult[keys[0]];
document.getElementById("MAX").textContent += serviceResult[keys[1]];
document.getElementById("MIN").textContent += serviceResult[keys[2]];
document.getElementById("STDDEVIATION").textContent += serviceResult[keys[3]];
document.getElementById("SUM").textContent += serviceResult[keys[4]];
document.getElementById("VARIANCE").textContent += serviceResult[keys[5]];
}
</script>
</body>
</html>