vizLayer_animatorMetro.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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_animatorMetro"></title>
  9. <script type="text/javascript" src="./data/animationExtendLineData.js"></script>
  10. <style type="text/css">
  11. body {
  12. margin: 0;
  13. overflow: hidden;
  14. background: #fff;
  15. }
  16. #map {
  17. position: absolute;
  18. width: 100%;
  19. height: 100%;
  20. }
  21. #toolbar {
  22. position: absolute;
  23. top: 50px;
  24. right: 10px;
  25. width: 300px;
  26. text-align: center;
  27. z-index: 100;
  28. border-radius: 4px;
  29. }
  30. #d_GroupDiv .smPopupContent {
  31. padding-top: 0px;
  32. display: inline;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <div id="toolbar" class="panel panel-primary">
  38. <div class='panel-heading'>
  39. <h5 class='panel-title text-center' data-i18n="resources.title_animatorMetro"></h5></div>
  40. <div class='panel-body content'>
  41. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_play" onclick="startAnimator()"/>&nbsp;
  42. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_pause" onclick="pauseAnimator()"/>&nbsp;
  43. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_showOrHide" onclick="show()"/>
  44. </div>
  45. </div>
  46. <div id="map"></div>
  47. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  48. <script type="text/javascript" include="responsive,bootstrap,widgets.alert" src="../js/include-web.js"></script>
  49. <script>
  50. var map, layer, animatorVector, vectorLayer, popup,
  51. host = window.isLocal ? window.server : "https://iserver.supermap.io",
  52. url = host + "/iserver/services/map-china400/rest/maps/China",
  53. url2 = host + "/iserver/services/data-DynamicData/rest/data";
  54. var features = {};
  55. var popups = {};
  56. var style = {
  57. style1: {
  58. fillColor: "#cc0000",
  59. pointRadius: 3,
  60. strokeColor: "#cc0000",
  61. strokeWidth: 5
  62. },
  63. style2: {
  64. fillColor: "#0066cc",
  65. pointRadius: 3,
  66. strokeColor: "#0066cc",
  67. strokeWidth: 5
  68. },
  69. style4: {
  70. fillColor: "#008d9e",
  71. pointRadius: 3,
  72. strokeColor: "#008d9e",
  73. strokeWidth: 5
  74. },
  75. style5: {
  76. fillColor: "#a71c81",
  77. pointRadius: 3,
  78. strokeColor: "#a71c81",
  79. strokeWidth: 5
  80. },
  81. style6: {
  82. fillColor: "#d19708",
  83. pointRadius: 3,
  84. strokeColor: "#d19708",
  85. strokeWidth: 5
  86. },
  87. style8: {
  88. fillColor: "#019a6b",
  89. pointRadius: 3,
  90. strokeColor: "#019a6b",
  91. strokeWidth: 5
  92. },
  93. style9: {
  94. fillColor: "#8cc31f",
  95. pointRadius: 3,
  96. strokeColor: "#8cc31f",
  97. strokeWidth: 5
  98. },
  99. style10: {
  100. fillColor: "#019bc1",
  101. pointRadius: 3,
  102. strokeColor: "#019bc1",
  103. strokeWidth: 5
  104. },
  105. style13: {
  106. fillColor: "#fad15c",
  107. pointRadius: 3,
  108. strokeColor: "#fad15c",
  109. strokeWidth: 5
  110. },
  111. style14: {
  112. fillColor: "#d6a6a2",
  113. pointRadius: 3,
  114. strokeColor: "#d6a6a2",
  115. strokeWidth: 5
  116. },
  117. style15: {
  118. fillColor: "#69347c",
  119. pointRadius: 3,
  120. strokeColor: "#69347c",
  121. strokeWidth: 5
  122. },
  123. style16: {
  124. fillColor: "#cc0000",
  125. pointRadius: 3,
  126. strokeColor: "#cc0000",
  127. strokeWidth: 5
  128. },
  129. style17: {
  130. fillColor: "#db83b3",
  131. pointRadius: 3,
  132. strokeColor: "#db83b3",
  133. strokeWidth: 5
  134. },
  135. style18: {
  136. fillColor: "#e50075",
  137. pointRadius: 3,
  138. strokeColor: "#e50075",
  139. strokeWidth: 5
  140. },
  141. style19: {
  142. fillColor: "#e46022",
  143. pointRadius: 3,
  144. strokeColor: "#e46022",
  145. strokeWidth: 5
  146. },
  147. style20: {
  148. fillColor: "#a49abc",
  149. pointRadius: 3,
  150. strokeColor: "#a49abc",
  151. strokeWidth: 5
  152. }
  153. };
  154. init();
  155. function init() {
  156. if (!document.createElement('canvas').getContext) {
  157. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  158. return;
  159. }
  160. //初始化地图
  161. map = new SuperMap.Map("map", {
  162. controls: [
  163. new SuperMap.Control.ScaleLine(),
  164. new SuperMap.Control.Zoom(),
  165. new SuperMap.Control.MousePosition(),
  166. new SuperMap.Control.Navigation({
  167. dragPanOptions: {
  168. enableKinetic: true
  169. }
  170. })],
  171. projection: "EPSG:3857"
  172. });
  173. layer = new SuperMap.Layer.CloudLayer();
  174. addLayer();
  175. }
  176. function addLayer() {
  177. //初始化动画矢量图层
  178. animatorVector = new SuperMap.Layer.AnimatorVector("Metro", {rendererType: "StretchLine"}, {
  179. repeat: false,
  180. //设置速度为每帧播放0.05的数据
  181. speed: 0.05,
  182. //开始时间为0
  183. startTime: 0,
  184. //每秒渲染12帧
  185. frameRate: 12,
  186. //结束时间设置为10
  187. endTime: 10
  188. });
  189. vectorLayer = new SuperMap.Layer.Vector("point");
  190. animatorVector.events.on({"drawfeaturestart": drawfeaturestart});
  191. animatorVector.animator.events.on({"firstframestart": framestart});
  192. map.addLayers([layer, animatorVector, vectorLayer]);
  193. map.setCenter(new SuperMap.LonLat(12958264.797366, 4846889.6362871), 11);
  194. var selectFeature = new SuperMap.Control.SelectFeature(vectorLayer, {
  195. onSelect: onFeatureSelected
  196. });
  197. map.addControl(selectFeature);
  198. selectFeature.activate();
  199. addMetro();
  200. layer.setVisibility(true);
  201. }
  202. function framestart() {
  203. vectorLayer.removeAllFeatures();
  204. map.removeAllPopup();
  205. }
  206. function drawfeaturestart(feature) {
  207. var featureId = feature.attributes.FEATUREID;
  208. //删除弹出框
  209. if (!popups[featureId]) popups[featureId] = [];
  210. for (var n = 0; n < popups[featureId].length; n++) {
  211. map.removePopup(popups[featureId][n]);
  212. }
  213. popups[featureId] = [];
  214. var arr = [];
  215. for (var i = 0; i < feature.geometry.components.length; i++) {
  216. var ml = feature.geometry.components[i];
  217. var po = ml.components[0];
  218. var contentHTML = "";
  219. contentHTML += "<span style='font-size:12px; line-height: 12px;background-color: #fff'>";
  220. contentHTML += po.MetroName + resources.text_stops;
  221. contentHTML += "</span>";
  222. var popup = new SuperMap.Popup("d",
  223. new SuperMap.LonLat(po.x, po.y),
  224. new SuperMap.Size((po.MetroName.length + 1) * 12, 12),
  225. contentHTML,
  226. false);
  227. popup.setOpacity(0.8);
  228. popup.setBackgroundColor("#fff");
  229. popup.setBorder("1px solid " + feature.style.fillColor);
  230. popups[featureId].push(popup);
  231. map.addPopup(popup);
  232. var fea = new SuperMap.Feature.Vector(
  233. po,
  234. {
  235. metro: po.Metro,
  236. name: po.MetroName
  237. },
  238. feature.style
  239. );
  240. arr.push(fea);
  241. }
  242. vectorLayer.addFeatures(arr);
  243. }
  244. //选择具体地铁站
  245. function onFeatureSelected(e) {
  246. if (popup) {
  247. map.removePopup(popup);
  248. }
  249. popup = new SuperMap.Popup.FramedCloud("chicken",
  250. new SuperMap.LonLat(e.geometry.x, e.geometry.y),
  251. null,
  252. resources.text_metro + e.attributes["metro"] + "</br>" + e.attributes["name"] + resources.text_stops,
  253. null,
  254. true);
  255. map.addPopup(popup);
  256. }
  257. //添加数据
  258. function addMetro() {
  259. var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
  260. getFeatureParam = new SuperMap.REST.FilterParameter({
  261. name: "Metro@DynamicData",
  262. attributeFilter: "SmID < 138"
  263. });
  264. getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
  265. queryParameter: getFeatureParam,
  266. datasetNames: ["DynamicData:Metro"]
  267. });
  268. getFeatureBySQLParams.toIndex = 137;
  269. getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(url2, {
  270. eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
  271. });
  272. getFeatureBySQLService.processAsync(getFeatureBySQLParams);
  273. }
  274. function processCompleted(getFeaturesEventArgs) {
  275. var features, result = getFeaturesEventArgs.result;
  276. if (result && result.features) {
  277. features = result.features;
  278. }
  279. var lineFeatures = [];
  280. //循环有几条地铁
  281. for (var i = 0, len = features.length; i < len; i++) {
  282. //有几个部分的情况
  283. var arrL = [];
  284. if (features[i].geometry.CLASS_NAME == "SuperMap.Geometry.MultiLineString") {
  285. var metro = features[i].geometry.components;
  286. //循环每一条地铁分几部分修建
  287. for (var j = 0; j < metro.length; j++) {
  288. var part = metro[j];
  289. var arrP = [];
  290. var m = 0;
  291. for (var k = 0; k < part.components.length; k++) {
  292. var pp = part.components[k];
  293. var point = new SuperMap.Geometry.Point(pp.x, pp.y);
  294. //名字
  295. var metroname = [];
  296. metroname = features[i].attributes.ATTRIBUTION.split(",");
  297. point.MetroName = metroname[m];
  298. m = m + 1;
  299. point.Metro = features[i].attributes.LINENAME;
  300. arrP.push(point);
  301. }
  302. var lineString = new SuperMap.Geometry.LineString(arrP);
  303. arrL.push(lineString);
  304. }
  305. }
  306. else {
  307. var metro1 = features[i].geometry.components;
  308. var arrP1 = [];
  309. for (var a = 0; a < metro1.length; a++) {
  310. var point1 = metro1[a];
  311. metroname1 = features[i].attributes.ATTRIBUTION.split(",");
  312. point1.MetroName = metroname1[a];
  313. point1.Metro = features[i].attributes.LINENAME;
  314. arrP1.push(point1);
  315. }
  316. var lineString1 = new SuperMap.Geometry.LineString(arrP1);
  317. arrL.push(lineString1);
  318. }
  319. var multiLineString = new SuperMap.Geometry.MultiLineString(arrL);
  320. var mm = parseInt(features[i].attributes.LINENUMBER);
  321. var sty = style["style" + mm];
  322. var lineFeature = new SuperMap.Feature.Vector(multiLineString, {
  323. FEATUREID: features[i].attributes.FEATUREID,
  324. TIME: features[i].attributes.TIME
  325. }, sty);
  326. lineFeatures.push(lineFeature);
  327. }
  328. animatorVector.addFeatures(lineFeatures);
  329. }
  330. function processFailed(e) {
  331. widgets.alert.showAlert(e.error.errorMsg, false);
  332. }
  333. //开始播放动画
  334. function startAnimator() {
  335. animatorVector.animator.start();
  336. }
  337. //暂停播放动画
  338. function pauseAnimator() {
  339. animatorVector.animator.pause();
  340. }
  341. //切换底图的显示
  342. function show() {
  343. layer.setVisibility(!layer.getVisibility());
  344. }
  345. </script>
  346. </body>
  347. </html>