vizLayer_animatorMetro2.html 13 KB

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