Skip to content
Navigation Menu
{{ message }}
forked from woliqiang/iClient-for-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimatorMetro.html
More file actions
348 lines (338 loc) · 10 KB
/
Copy pathanimatorMetro.html
File metadata and controls
348 lines (338 loc) · 10 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
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>地铁修建模拟</title>
<style type="text/css">
body{
margin: 0;
overflow: hidden;
background: #fff;
}
#map{
position: relative;
height: 520px;
border:1px solid #3473b7;
}
#d_GroupDiv .smPopupContent{
padding-top:0px;
}
</style>
<link href='./css/bootstrap.min.css' rel='stylesheet' />
<link href='./css/bootstrap-responsive.min.css' rel='stylesheet' />
<script src='../libs/SuperMap.Include.js'></script>
<script src="data/animationExtendLineData.js"></script>
<script type="text/javascript">
var map, layer,animatorVector,vectorLayer,popup, host = document.location.toString().match(/file:\/\//) ? "http://localhost:8090" : 'http://' + document.location.host;
url = host + "/iserver/services/map-china400/rest/maps/China";
url2 = host + "/iserver/services/data-DynamicData/rest/data";
var features = {};
var popups = {};
var style = {
style1:{
fillColor: "#cc0000",
pointRadius: 3,
strokeColor: "#cc0000",
strokeWidth: 5
},
style2:{
fillColor: "#0066cc",
pointRadius: 3,
strokeColor: "#0066cc",
strokeWidth: 5
},
style4:{
fillColor: "#008d9e",
pointRadius: 3,
strokeColor: "#008d9e",
strokeWidth: 5
},
style5:{
fillColor: "#a71c81",
pointRadius: 3,
strokeColor: "#a71c81",
strokeWidth: 5
},
style6:{
fillColor: "#d19708",
pointRadius: 3,
strokeColor: "#d19708",
strokeWidth: 5
},
style8:{
fillColor: "#019a6b",
pointRadius: 3,
strokeColor: "#019a6b",
strokeWidth: 5
},
style9:{
fillColor: "#8cc31f",
pointRadius: 3,
strokeColor: "#8cc31f",
strokeWidth: 5
},
style10:{
fillColor: "#019bc1",
pointRadius: 3,
strokeColor: "#019bc1",
strokeWidth: 5
},
style13:{
fillColor: "#fad15c",
pointRadius: 3,
strokeColor: "#fad15c",
strokeWidth: 5
},
style14:{
fillColor: "#d6a6a2",
pointRadius: 3,
strokeColor: "#d6a6a2",
strokeWidth: 5
},
style15:{
fillColor: "#69347c",
pointRadius: 3,
strokeColor: "#69347c",
strokeWidth: 5
},
style16:{
fillColor: "#cc0000",
pointRadius: 3,
strokeColor: "#cc0000",
strokeWidth: 5
},
style17:{
fillColor: "#db83b3",
pointRadius: 3,
strokeColor: "#db83b3",
strokeWidth: 5
},
style18:{
fillColor: "#e50075",
pointRadius: 3,
strokeColor: "#e50075",
strokeWidth: 5
},
style19:{
fillColor: "#e46022",
pointRadius: 3,
strokeColor: "#e46022",
strokeWidth: 5
},
style20:{
fillColor: "#a49abc",
pointRadius: 3,
strokeColor: "#a49abc",
strokeWidth: 5
}
};
function init() {
if(!document.createElement('canvas').getContext) {
alert('您的浏览器不支持 canvas,请升级');
return;
}
//初始化地图
map = new SuperMap.Map("map",{controls: [
new SuperMap.Control.ScaleLine(),
new SuperMap.Control.Zoom(),
new SuperMap.Control.MousePosition(),
new SuperMap.Control.Navigation({
dragPanOptions: {
enableKinetic: true
}
})],
projection: "EPSG:3857"
});
layer = new SuperMap.Layer.CloudLayer();
addLayer();
}
function addLayer() {
//初始化动画矢量图层
animatorVector = new SuperMap.Layer.AnimatorVector("Metro", {rendererType:"StretchLine"},{
repeat:false,
//设置速度为每帧播放0.05的数据
speed:0.05,
//开始时间为0
startTime:0,
//每秒渲染12帧
frameRate:12,
//结束时间设置为10
endTime:10
});
vectorLayer = new SuperMap.Layer.Vector("point");
animatorVector.events.on({"drawfeaturestart": drawfeaturestart});
animatorVector.animator.events.on({"firstframestart":framestart});
map.addLayers([layer,animatorVector,vectorLayer]);
map.setCenter(new SuperMap.LonLat(12958264.797366,4846889.6362871), 11);
var selectFeature = new SuperMap.Control.SelectFeature(vectorLayer, {
onSelect: onFeatureSelected
});
map.addControl(selectFeature);
selectFeature.activate();
addMetro();
layer.setVisibility(true);
}
function framestart()
{
vectorLayer.removeAllFeatures();
map.removeAllPopup();
}
function drawfeaturestart(feature)
{
var featureId = feature.attributes.FEATUREID;
//删除弹出框
if(!popups[featureId]) popups[featureId] = [];
for(var n = 0;n<popups[featureId].length;n++)
{
map.removePopup(popups[featureId][n]);
}
popups[featureId] = [];
var arr = [];
for(var i = 0;i<feature.geometry.components.length;i++)
{
var ml = feature.geometry.components[i];
var po = ml.components[0];
var contentHTML = "";
contentHTML += "<span style=' font-size:12px; line-height: 12px;background-color: #fff'>";
contentHTML += po.MetroName+"站";
contentHTML += "</span>";
var popup = new SuperMap.Popup("d",
new SuperMap.LonLat(po.x,po.y),
new SuperMap.Size((po.MetroName.length+1)*12,12),
contentHTML,
false);
popup.setOpacity(0.8);
popup.setBackgroundColor("#fff");
popup.setBorder("1px solid "+feature.style.fillColor);
popups[featureId].push(popup);
map.addPopup(popup);
var fea = new SuperMap.Feature.Vector(
po,
{
metro:po.Metro,
name:po.MetroName
},
feature.style
);
arr.push(fea);
}
vectorLayer.addFeatures(arr);
}
//选择具体地铁站
function onFeatureSelected(e)
{
if(popup)
{
map.removePopup(popup);
}
popup = new SuperMap.Popup.FramedCloud("chicken",
new SuperMap.LonLat(e.geometry.x,e.geometry.y),
null,
"地铁"+e.attributes["metro"]+"</br>"+e.attributes["name"]+"站",
null,
true);
map.addPopup(popup);
}
//添加数据
function addMetro()
{
var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
getFeatureParam = new SuperMap.REST.FilterParameter({
name: "Metro@DynamicData",
attributeFilter: "SmID < 138"
});
getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
queryParameter: getFeatureParam,
datasetNames:["DynamicData:Metro"]
});
getFeatureBySQLParams.toIndex = 137;
getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(url2, {
eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}});
getFeatureBySQLService.processAsync(getFeatureBySQLParams);
}
function processCompleted(getFeaturesEventArgs){
var features,result = getFeaturesEventArgs.result;
if (result && result.features) {
features = result.features;
}
var lineFeatures = [];
//循环有几条地铁
for(var i = 0,len = features.length;i<len;i++)
{
//有几个部分的情况
var arrL = [];
if(features[i].geometry.CLASS_NAME == "SuperMap.Geometry.MultiLineString"){
var metro = features[i].geometry.components;
//循环每一条地铁分几部分修建
for(var j=0;j<metro.length;j++)
{
var part = metro[j];
var arrP = [];
var m = 0;
for(var k=0;k < part.components.length;k++)
{
var pp = part.components[k];
var point = new SuperMap.Geometry.Point(pp.x,pp.y);
//名字
var metroname = [];
metroname = features[i].attributes.ATTRIBUTION.split(",");
point.MetroName = metroname[m];
m = m + 1;
point.Metro = features[i].attributes.LINENAME;
arrP.push(point);
}
var lineString = new SuperMap.Geometry.LineString(arrP);
arrL.push(lineString);
}
}
else{
var metro1 = features[i].geometry.components;
var arrP1 = [];
for(var a=0;a<metro1.length;a++)
{
var point1 = metro1[a];
metroname1 = features[i].attributes.ATTRIBUTION.split(",");
point1.MetroName = metroname1[a];
point1.Metro = features[i].attributes.LINENAME;
arrP1.push(point1);
}
var lineString1 = new SuperMap.Geometry.LineString(arrP1);
arrL.push(lineString1);
}
var multiLineString = new SuperMap.Geometry.MultiLineString(arrL);
var mm = parseInt(features[i].attributes.LINENUMBER);
var sty = style["style"+mm];
var lineFeature = new SuperMap.Feature.Vector(multiLineString,{
FEATUREID:features[i].attributes.FEATUREID,
TIME:features[i].attributes.TIME
},sty);
lineFeatures.push(lineFeature);
}
animatorVector.addFeatures(lineFeatures);
}
function processFailed(e){
alert(e.error.errorMsg);
}
//开始播放动画
function startAnimator(){
animatorVector.animator.start();
}
//暂停播放动画
function pauseAnimator(){
animatorVector.animator.pause();
}
//切换底图的显示
function show(){
layer.setVisibility(!layer.getVisibility());
}
</script>
</head>
<body onload="init()">
<div id="toolbar">
<input type="button" class="btn" value="播放" onclick="startAnimator()" />
<input type="button" class="btn" value="暂停" onclick="pauseAnimator()" />
<input type="button" class="btn" value="显示/隐藏底图" onclick="show()"/>
</div>
<div id="map"></div>
</body>
</html>
You can’t perform that action at this time.
