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 pathanimatorTrain.html
More file actions
289 lines (265 loc) · 9.61 KB
/
Copy pathanimatorTrain.html
File metadata and controls
289 lines (265 loc) · 9.61 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
<!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: 510px;
border:1px solid #3473b7;
}
#toolbar {
position: relative;
padding-top: 5px;
padding-bottom: 10px;
}
</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 type="text" id="cartocssStr">
/*此处定义不同的颜色变量,在后面可以重复用这些颜色值*/
@waterColor:rgb(34,56,78);
@roadColora:rgb(109,102,91);
@roadColorb:rgb(109,102,91);
@railwayColora:rgb(80,80,80);
@railwayColorb:rgb(137,137,137);
@vegetationColor:rgb(27,27,27);
@continentColor:rgb(68,68,68);
@provinceLineColor:rgb(180,0,0);
#China_Railway_L___China400::a{
/*每一段的长度为15px,间隔也是15px*/
line-color:@railwayColora;
line-width:2.5;
}
#China_Railway_L___China400::b{
/*每一段的长度为15px,间隔也是15px*/
line-dasharray:18,18;
line-color:@railwayColorb;
line-width:2;
}
/*底下的地图背景图层*/
#World_Division___China400{
polygon-fill:@waterColor;
}
/*中国除外的其他国家的图层*/
#World_Continent___China400{
polygon-fill:@continentColor;
line-width:1;
line-color:rgb(180,180,180);
}
#World_Division___China400{
polygon-fill:@waterColor;
}
</script>
<script type="text/javascript">
var map, layer,animatorVector,lineVector1,lineVector2, 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 style1=
{
fillColor: "#ffff00",
fillOpacity: 0.8,
strokeOpacity: 0,
pointRadius: 5
};
var style2=
{
fillColor: "#c165f6",
fillOpacity: 1,
strokeOpacity: 0,
pointRadius: 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.Navigation({
dragPanOptions: {
enableKinetic: true
}
})],
projection: "EPSG:3857"
});
//初始化图层
var cartoCssStr=document.getElementById("cartocssStr");
var cartoCss=cartoCssStr.text;
var layerNames=["World_Division@China400","World_Continent@China400",
"China_Province_R@China400","China_island_R@China400",
"China_Provinces_L@China400","China_Capital_P@China400",
"China_BeiJing@China400"].join(",");
layerNames="["+layerNames+"]";
layer = new SuperMap.Layer.TiledVectorLayer("China", url,{cacheEnabled:true,layerNames:layerNames},{useLocalStorage:true,cartoCss:cartoCss});
layer.events.on({"layerInitialized": addLayer});
}
function addLayer() {
//初始化动画矢量图层
animatorVector = new SuperMap.Layer.AnimatorVector("Train", {rendererType:"TadpolePoint"},{
//设置速度为每帧播放0.02小时的数据
speed:0.02,
//开始时间为0晨
startTime:0,
//结束时间设置为最后运行结束的火车结束时间
endTime:39
});
lineVector1 = new SuperMap.Layer.Vector("Line1");
lineVector2 = new SuperMap.Layer.Vector("Line2");
map.addLayers([layer,lineVector1,lineVector2,animatorVector]);
map.setCenter(new SuperMap.LonLat(12009634.286396, 4258716.5813769), 4);
//增加数据
addTrain();
}
//添加火车数据
function addTrain()
{
var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
getFeatureParam = new SuperMap.REST.FilterParameter({
name: "Train@DynamicData",
attributeFilter: "SmID < 2240"
});
getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
queryParameter: getFeatureParam,
datasetNames:["DynamicData:Train"]
});
//返回个数
getFeatureBySQLParams.toIndex = 2240;
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;
}
console.log(features);
//使用数据
var pointFeatures = [];
var lines1 = [];
var lines2 = [];
var points = [];
var id = 0;
for(var i = 0,len = features.length;i<len;i++)
{
var point = features[i].geometry;
var po = features[i].geometry;
if(id == features[i].data.FEATUREID)
{
points.push(po);
}
else
{
id = features[i].data.FEATUREID;
lines1.push(
new SuperMap.Feature.Vector(
new SuperMap.Geometry.LineString(points),
{},
{
stroke:true,
strokeColor:"#dddddd",
strokeWidth:3,
strokeDashstyle:"solid"
}
)
);
lines2.push(
new SuperMap.Feature.Vector(
new SuperMap.Geometry.LineString(points),
{},
{
stroke:true,
strokeColor:"#41403f",
strokeWidth:2,
strokeDashstyle:"dash"
}
)
);
points = [];
}
if(features[i].data.FEATUREID <151)
{
var pointFeature = new SuperMap.Feature.Vector(point,{
FEATUREID:features[i].data.FEATUREID,
TIME:features[i].data.TIME
},style1);
}
else
{
var pointFeature = new SuperMap.Feature.Vector(point,{
FEATUREID:features[i].data.FEATUREID,
TIME:features[i].data.TIME
},style2);
}
pointFeatures.push(pointFeature);
}
animatorVector.addFeatures(pointFeatures);
lineVector1.addFeatures(lines1);
lineVector2.addFeatures(lines2);
}
function processFailed(e){
alert(e.error.errorMsg);
}
//开始播放动画
function startAnimator(){
animatorVector.animator.start();
}
//暂停播放动画
function pauseAnimator(){
animatorVector.animator.pause();
}
//停止播放动画
function stopAnimator(){
animatorVector.animator.stop();
}
//减速播放
function decreaseSpeed(){
animatorVector.animator.setSpeed(animatorVector.animator.getSpeed()*0.7);
}
//正反向播放切换
function setReverseAnimator(){
animatorVector.animator.setReverse(!animatorVector.animator.getReverse());
}
//加速播放
function increaseSpeed(){
animatorVector.animator.setSpeed(animatorVector.animator.getSpeed()*1.5);
}
//开关闪烁
function setGlint(){
animatorVector.renderer.glint = !animatorVector.renderer.glint;
}
//开关尾巴
function setTailr(){
animatorVector.renderer.tail = !animatorVector.renderer.tail;
}
function show(){
lineVector1.setVisibility(!lineVector1.getVisibility());
lineVector2.setVisibility(!lineVector2.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="stopAnimator()" />
<input type="button" class="btn" value="加速" onclick="increaseSpeed()" />
<input type="button" class="btn" value="减速" onclick="decreaseSpeed()" />
<input type="button" class="btn" value="正/反播放" onclick="setReverseAnimator()" />
<input type="button" class="btn" value="开/关闪烁" onclick="setGlint()" />
<input type="button" class="btn" value="开/关尾巴" onclick="setTailr()" />
<input type="button" class="btn" value="显示/隐藏铁路线" onclick="show()" />
</div>
<div id="map"></div>
</body>
</html>
You can’t perform that action at this time.
