vizLayer_animatorTrain.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="utf-8">
  8. <title data-i18n="resources.title_animatorTrain"></title>
  9. <style type="text/css">
  10. body {
  11. margin: 0;
  12. overflow: hidden;
  13. background: #fff;
  14. width: 100%;
  15. height: 100%
  16. }
  17. #map {
  18. position: absolute;
  19. width: 100%;
  20. height: 100%;
  21. }
  22. #toolbar {
  23. position: absolute;
  24. top: 50px;
  25. right: 10px;
  26. text-align: center;
  27. z-index: 100;
  28. border-radius: 4px;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="toolbar" class="panel panel-primary">
  34. <div class='panel-heading'>
  35. <h5 class='panel-title text-center' data-i18n="resources.title_animatorTrain"></h5></div>
  36. <div class='panel-body content'>
  37. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_play" onclick="startAnimator()"/>&nbsp;
  38. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_pause" onclick="pauseAnimator()"/>&nbsp;
  39. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_stop" onclick="stopAnimator()"/>&nbsp;
  40. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_acceleration" onclick="increaseSpeed()"/>&nbsp;
  41. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_deceleration" onclick="decreaseSpeed()"/>&nbsp;
  42. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_switchDirection" onclick="setReverseAnimator()"/>&nbsp;
  43. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_switchTwinkle" onclick="setGlint()"/>&nbsp;
  44. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_switchTails" onclick="setTailr()"/>&nbsp;
  45. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_showOrHideTrain" onclick="show()"/>
  46. </div>
  47. </div>
  48. <div id="map"></div>
  49. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  50. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  51. <script type="text" id="cartocssStr">
  52. /*此处定义不同的颜色变量,在后面可以重复用这些颜色值*/
  53. @waterColor:rgb(34,56,78);
  54. @roadColora:rgb(109,102,91);
  55. @roadColorb:rgb(109,102,91);
  56. @railwayColora:rgb(80,80,80);
  57. @railwayColorb:rgb(137,137,137);
  58. @vegetationColor:rgb(27,27,27);
  59. @continentColor:rgb(68,68,68);
  60. @provinceLineColor:rgb(180,0,0);
  61. #China_Railway_L___China::a{
  62. /*每一段的长度为15px,间隔也是15px*/
  63. line-color:@railwayColora;
  64. line-width:2.5;
  65. }
  66. #China_Railway_L___China::b{
  67. /*每一段的长度为15px,间隔也是15px*/
  68. line-dasharray:18,18;
  69. line-color:@railwayColorb;
  70. line-width:2;
  71. }
  72. /*底下的地图背景图层*/
  73. #World_Division_pl___China{
  74. polygon-fill:@waterColor;
  75. }
  76. /*中国除外的其他国家的图层*/
  77. #World_Continent_pl___China{
  78. polygon-fill:@continentColor;
  79. line-width:1;
  80. line-color:rgb(180,180,180);
  81. }
  82. #World_Division_pl___China{
  83. polygon-fill:@waterColor;
  84. }
  85. </script>
  86. <script>
  87. var map, layer, animatorVector, lineVector1, lineVector2,
  88. host = window.isLocal ? window.server : "https://iserver.supermap.io",
  89. url = host + "/iserver/services/map-china400/rest/maps/China",
  90. url2 = host + "/iserver/services/data-DynamicData/rest/data";
  91. var style1 =
  92. {
  93. fillColor: "#ffff00",
  94. fillOpacity: 0.8,
  95. strokeOpacity: 0,
  96. pointRadius: 5
  97. };
  98. var style2 =
  99. {
  100. fillColor: "#c165f6",
  101. fillOpacity: 1,
  102. strokeOpacity: 0,
  103. pointRadius: 5
  104. };
  105. init();
  106. function init() {
  107. if (!document.createElement('canvas').getContext) {
  108. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  109. return;
  110. }
  111. //初始化地图
  112. map = new SuperMap.Map("map", {
  113. controls: [
  114. new SuperMap.Control.ScaleLine(),
  115. new SuperMap.Control.Zoom(),
  116. new SuperMap.Control.Navigation({
  117. dragPanOptions: {
  118. enableKinetic: true
  119. }
  120. })],
  121. projection: "EPSG:3857"
  122. });
  123. //初始化图层
  124. var cartoCssStr = document.getElementById("cartocssStr");
  125. var cartoCss = cartoCssStr.text;
  126. var layerNames = ["World_Division_pl@China", "World_Continent_pl@China",
  127. "China_Province_pl@China", "China_Island@China",
  128. "China_Capital_Pt@China", "China_Boundary_A"].join(",");
  129. layerNames = "[" + layerNames + "]";
  130. layer = new SuperMap.Layer.TiledVectorLayer("China", url, {
  131. cacheEnabled: true,
  132. layerNames: layerNames
  133. }, {useLocalStorage: true, cartoCss: cartoCss});
  134. layer.events.on({"layerInitialized": addLayer});
  135. }
  136. function addLayer() {
  137. //初始化动画矢量图层
  138. animatorVector = new SuperMap.Layer.AnimatorVector("Train", {rendererType: "TadpolePoint"}, {
  139. //设置速度为每帧播放0.02小时的数据
  140. speed: 0.02,
  141. //开始时间为0晨
  142. startTime: 0,
  143. //结束时间设置为最后运行结束的火车结束时间
  144. endTime: 39
  145. });
  146. lineVector1 = new SuperMap.Layer.Vector("Line1");
  147. lineVector2 = new SuperMap.Layer.Vector("Line2");
  148. map.addLayers([layer, lineVector1, lineVector2, animatorVector]);
  149. map.setCenter(new SuperMap.LonLat(12009634.286396, 4258716.5813769), 4);
  150. //增加数据
  151. addTrain();
  152. }
  153. //添加火车数据
  154. function addTrain() {
  155. var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
  156. getFeatureParam = new SuperMap.REST.FilterParameter({
  157. name: "Train@DynamicData",
  158. attributeFilter: "SmID < 2240"
  159. });
  160. getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
  161. queryParameter: getFeatureParam,
  162. datasetNames: ["DynamicData:Train"]
  163. });
  164. //返回个数
  165. getFeatureBySQLParams.toIndex = 2240;
  166. getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(url2, {
  167. eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
  168. });
  169. getFeatureBySQLService.processAsync(getFeatureBySQLParams);
  170. }
  171. function processCompleted(getFeaturesEventArgs) {
  172. var features, result = getFeaturesEventArgs.result;
  173. if (result && result.features) {
  174. features = result.features;
  175. }
  176. console.log(features);
  177. //使用数据
  178. var pointFeatures = [];
  179. var lines1 = [];
  180. var lines2 = [];
  181. var points = [];
  182. var id = 0;
  183. for (var i = 0, len = features.length; i < len; i++) {
  184. var point = features[i].geometry;
  185. var po = features[i].geometry;
  186. if (id == features[i].data.FEATUREID) {
  187. points.push(po);
  188. }
  189. else {
  190. id = features[i].data.FEATUREID;
  191. lines1.push(
  192. new SuperMap.Feature.Vector(
  193. new SuperMap.Geometry.LineString(points),
  194. {},
  195. {
  196. stroke: true,
  197. strokeColor: "#dddddd",
  198. strokeWidth: 3,
  199. strokeDashstyle: "solid"
  200. }
  201. )
  202. );
  203. lines2.push(
  204. new SuperMap.Feature.Vector(
  205. new SuperMap.Geometry.LineString(points),
  206. {},
  207. {
  208. stroke: true,
  209. strokeColor: "#41403f",
  210. strokeWidth: 2,
  211. strokeDashstyle: "dash"
  212. }
  213. )
  214. );
  215. points = [];
  216. }
  217. if (features[i].data.FEATUREID < 151) {
  218. var pointFeature = new SuperMap.Feature.Vector(point, {
  219. FEATUREID: features[i].data.FEATUREID,
  220. TIME: features[i].data.TIME
  221. }, style1);
  222. }
  223. else {
  224. var pointFeature = new SuperMap.Feature.Vector(point, {
  225. FEATUREID: features[i].data.FEATUREID,
  226. TIME: features[i].data.TIME
  227. }, style2);
  228. }
  229. pointFeatures.push(pointFeature);
  230. }
  231. animatorVector.addFeatures(pointFeatures);
  232. lineVector1.addFeatures(lines1);
  233. lineVector2.addFeatures(lines2);
  234. }
  235. function processFailed(e) {
  236. widgets.alert.showAlert(e.error.errorMsg, false);
  237. }
  238. //开始播放动画
  239. function startAnimator() {
  240. animatorVector.animator.start();
  241. }
  242. //暂停播放动画
  243. function pauseAnimator() {
  244. animatorVector.animator.pause();
  245. }
  246. //停止播放动画
  247. function stopAnimator() {
  248. animatorVector.animator.stop();
  249. }
  250. //减速播放
  251. function decreaseSpeed() {
  252. animatorVector.animator.setSpeed(animatorVector.animator.getSpeed() * 0.7);
  253. }
  254. //正反向播放切换
  255. function setReverseAnimator() {
  256. animatorVector.animator.setReverse(!animatorVector.animator.getReverse());
  257. }
  258. //加速播放
  259. function increaseSpeed() {
  260. animatorVector.animator.setSpeed(animatorVector.animator.getSpeed() * 1.5);
  261. }
  262. //开关闪烁
  263. function setGlint() {
  264. animatorVector.renderer.glint = !animatorVector.renderer.glint;
  265. }
  266. //开关尾巴
  267. function setTailr() {
  268. animatorVector.renderer.tail = !animatorVector.renderer.tail;
  269. }
  270. function show() {
  271. lineVector1.setVisibility(!lineVector1.getVisibility());
  272. lineVector2.setVisibility(!lineVector2.getVisibility());
  273. }
  274. </script>
  275. </body>
  276. </html>