vizLayer_animatorMigrate.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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_animatorMigrate"></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: 230px;
  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_animatorMigrate"></h5></div>
  37. <div class='panel-body content'>
  38. <div class='panel'>
  39. <div class='input-group'>
  40. <label data-i18n="resources.text_currentTime" style="display:inline"></label>
  41. <label style="display:inline" id="timeDate"></label>
  42. <label style="display:inline" id="timeHour"></label>
  43. </div>
  44. </div>
  45. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_play" onclick="startAnimator()"/>&nbsp;
  46. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_pause" onclick="pauseAnimator()"/>
  47. </div>
  48. </div>
  49. <div id="map"></div>
  50. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  51. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  52. <script type="text" id="cartocssStr">
  53. @color:#111;
  54. #World_Continent_txt___China::hover{
  55. text-fill:#0f0;
  56. }
  57. #World_Division_pl___China{
  58. polygon-fill:#123;
  59. ::click{
  60. polygon-fill:#123;
  61. }
  62. }
  63. #World_Continent_pl___China{
  64. polygon-fill:#000002;
  65. line-width:1;
  66. line-color:#888;
  67. ::hover[featureID=73]{
  68. polygon-fill:#f00;
  69. }
  70. }
  71. #China_Capital_Pt___China [zoom>4] {
  72. point-file:url("../examples/images/marker2.png");
  73. }
  74. #China_Province_pl___China{
  75. polygon-fill:#555;
  76. }
  77. #China_Boundary_A___China{
  78. line-color:#000000;
  79. }
  80. </script>
  81. <script>
  82. var map, layer, animatorVector, vectorLayer, url2,
  83. host = window.isLocal ? window.server : "https://iserver.supermap.io",
  84. url = host + "/iserver/services/map-china400/rest/maps/China",
  85. url2 = host + "/iserver/services/data-DynamicData/rest/data";
  86. var items = [
  87. {
  88. start: 0,
  89. end: 101,
  90. length: 55,
  91. style: {
  92. strokeOpacity: 1,
  93. strokeColor: "#000000",
  94. strokeWidth: 1
  95. }
  96. },
  97. {
  98. start: 101,
  99. end: 201,
  100. length: 60,
  101. style: {
  102. strokeOpacity: 1,
  103. strokeColor: "#0000FF",
  104. strokeWidth: 1.5
  105. }
  106. },
  107. {
  108. start: 201,
  109. end: 301,
  110. length: 65,
  111. style: {
  112. strokeOpacity: 1,
  113. strokeColor: "#FF00FF",
  114. strokeWidth: 2
  115. }
  116. },
  117. {
  118. start: 301,
  119. end: 401,
  120. length: 70,
  121. style: {
  122. strokeOpacity: 1,
  123. strokeColor: "#FF0000",
  124. strokeWidth: 2.5
  125. }
  126. },
  127. {
  128. start: 401,
  129. end: 501,
  130. length: 75,
  131. style: {
  132. strokeOpacity: 1,
  133. strokeColor: "#FFCCFF",
  134. strokeWidth: 3
  135. }
  136. },
  137. {
  138. start: 501,
  139. end: 601,
  140. length: 80,
  141. style: {
  142. strokeOpacity: 1,
  143. strokeColor: "#00FF00",
  144. strokeWidth: 3.5
  145. }
  146. },
  147. {
  148. start: 601,
  149. end: 701,
  150. length: 85,
  151. style: {
  152. strokeOpacity: 1,
  153. strokeColor: "#00FFFF",
  154. strokeWidth: 4
  155. }
  156. },
  157. {
  158. start: 701,
  159. end: 801,
  160. length: 90,
  161. style: {
  162. strokeOpacity: 1,
  163. strokeColor: "#FFFF00",
  164. strokeWidth: 4.5
  165. }
  166. },
  167. {
  168. start: 801,
  169. end: 901,
  170. length: 95,
  171. style: {
  172. strokeOpacity: 1,
  173. strokeColor: "#66CCCC",
  174. strokeWidth: 5
  175. }
  176. },
  177. {
  178. start: 901,
  179. end: 1001,
  180. length: 100,
  181. style: {
  182. strokeOpacity: 1,
  183. strokeColor: "#FF9999",
  184. strokeWidth: 5.5
  185. }
  186. }
  187. ];
  188. init();
  189. function init() {
  190. if (!document.createElement('canvas').getContext) {
  191. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  192. return;
  193. }
  194. //初始化地图
  195. map = new SuperMap.Map("map", {
  196. controls: [
  197. new SuperMap.Control.ScaleLine(),
  198. new SuperMap.Control.Zoom(),
  199. new SuperMap.Control.Navigation({
  200. dragPanOptions: {
  201. enableKinetic: true
  202. }
  203. })],
  204. projection: "EPSG:3857"
  205. });
  206. //初始化图层
  207. var cartoCssStr = document.getElementById("cartocssStr");
  208. var cartoCss = cartoCssStr.text;
  209. var layerNames = ["World_Division_pl@China", "World_Continent_pl@China",
  210. "China_Province_pl@China", "China_Island@China",
  211. "China_Capital_Pt@China", "China_Boundary_A"].join(",");
  212. layerNames = "[" + layerNames + "]";
  213. layer = new SuperMap.Layer.TiledVectorLayer("China", url, {
  214. cacheEnabled: true,
  215. layerNames: layerNames
  216. }, {useLocalStorage: true, cartoCSS: cartoCss});
  217. layer.events.on({"layerInitialized": addLayer});
  218. }
  219. function addLayer() {
  220. //初始化动画矢量图层
  221. animatorVector = new SuperMap.Layer.AnimatorVector("春运", {rendererType: "RadiatePoint"}, {
  222. frameRate: 20,
  223. //设置速度为每帧播放0.01小时的数据
  224. speed: 0.01,
  225. //开始时间为0晨
  226. startTime: 0,
  227. //结束时间设置为第七天,也就是大年三十
  228. endTime: 7
  229. });
  230. animatorVector.renderer.items = items;
  231. animatorVector.renderer.dataField = "POPULATION";
  232. animatorVector.animator.events.on({"framestart": framestart});
  233. vectorLayer = new SuperMap.Layer.Vector("point");
  234. map.addLayers([layer, animatorVector, vectorLayer]);
  235. map.setCenter(new SuperMap.LonLat(12009634.286396, 4208716.5813769), 5);
  236. //增加数据
  237. addMigrate();
  238. }
  239. function framestart(time) {
  240. //从服务端获取数据
  241. var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
  242. getFeatureParam = new SuperMap.REST.FilterParameter({
  243. name: "Migrate@DynamicData",
  244. attributeFilter: "SmID < 809"
  245. });
  246. getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
  247. queryParameter: getFeatureParam,
  248. datasetNames: ["DynamicData:Migrate"]
  249. });
  250. getFeatureBySQLParams.toIndex = 808;
  251. getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(url2, {
  252. eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
  253. });
  254. getFeatureBySQLService.processAsync(getFeatureBySQLParams);
  255. function processCompleted(getFeaturesEventArgs) {
  256. var features, result = getFeaturesEventArgs.result;
  257. if (result && result.features) {
  258. features = result.features;
  259. }
  260. //计算每个featureid相同的点个数
  261. var court = [];
  262. court[0] = 0;
  263. var mm = 0;
  264. var kk = 0;
  265. var arr = []; //用来存储ID相同的要素;
  266. var featurearr = [];
  267. for (var i = 0; i < features.length; i++) {
  268. if (features[i].data.AREA == mm) {
  269. court[kk] = court[kk] + 1;
  270. arr.push(features[i]);
  271. }
  272. else {
  273. featurearr.push(arr);
  274. arr = [];
  275. kk = kk + 1;
  276. court[kk] = 1;
  277. arr.push(features[i]);
  278. mm = mm + 1;
  279. }
  280. if (court[27] == 11) {
  281. featurearr.push(arr);
  282. }
  283. }
  284. //遍历每个区域
  285. changeTime(time);
  286. vectorLayer.removeAllFeatures();
  287. var pointFeatures = [];
  288. //循环遍历区域
  289. for (var j = 0; j < court.length; j++) {
  290. var area = featurearr[j];
  291. var population = 0;
  292. for (var z = 0; z < area.length; z++) {
  293. if ((area[z].attributes.MIGRATION == "true" && area[z].attributes.TIME >= time) || (area[z].attributes.MIGRATION == "false" && area[z].attributes.TIME <= time)) {
  294. population += Number(area[z].attributes.POPULATION);
  295. }
  296. }
  297. var point = new SuperMap.Geometry.Point(area[0].geometry.x, area[0].geometry.y);
  298. var pointFeature = new SuperMap.Feature.Vector(point, {}, {
  299. fillColor: "#ff8000",
  300. fillOpacity: 0.8,
  301. strokeOpacity: 0,
  302. label: population + "",
  303. fontColor: "#ffffff",
  304. fontOpacity: "1",
  305. fontFamily: "隶书",
  306. fontSize: "1em",
  307. pointRadius: Math.sqrt(population / 50)
  308. });
  309. pointFeatures.push(pointFeature);
  310. }
  311. vectorLayer.addFeatures(pointFeatures);
  312. }
  313. function processFailed(getFeaturesEventArgs) {
  314. widgets.alert.showAlert(getFeaturesEventArgs.error.errorMsg, false);
  315. }
  316. }
  317. function changeTime(time) {
  318. if (time >= 0 && time < 1) {
  319. document.getElementById("timeDate").innerHTML = resources.text_24;
  320. }
  321. else if (time >= 1 && time < 2) {
  322. document.getElementById("timeDate").innerHTML = resources.text_25;
  323. }
  324. else if (time >= 1 && time < 3) {
  325. document.getElementById("timeDate").innerHTML = resources.text_26;
  326. }
  327. else if (time >= 1 && time < 4) {
  328. document.getElementById("timeDate").innerHTML = resources.text_27;
  329. }
  330. else if (time >= 1 && time < 5) {
  331. document.getElementById("timeDate").innerHTML = resources.text_28;
  332. }
  333. else if (time >= 1 && time < 6) {
  334. document.getElementById("timeDate").innerHTML = resources.text_29;
  335. }
  336. else if (time >= 1 && time < 7) {
  337. document.getElementById("timeDate").innerHTML = resources.text_23;
  338. }
  339. document.getElementById("timeHour").innerHTML = parseInt((time - parseInt(time)) * 24) + resources.text_clock;
  340. }
  341. //添加迁徙数据
  342. function addMigrate() {
  343. var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
  344. getFeatureParam = new SuperMap.REST.FilterParameter({
  345. name: "Migrate@DynamicData",
  346. attributeFilter: "SmID < 809"
  347. });
  348. getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
  349. queryParameter: getFeatureParam,
  350. datasetNames: ["DynamicData:Migrate"]
  351. });
  352. getFeatureBySQLParams.toIndex = 808;
  353. getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(url2, {
  354. eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
  355. });
  356. getFeatureBySQLService.processAsync(getFeatureBySQLParams);
  357. }
  358. function processCompleted(getFeaturesEventArgs) {
  359. var features, result = getFeaturesEventArgs.result;
  360. if (result && result.features) {
  361. features = result.features;
  362. }
  363. var pointFeatures = [];
  364. //循环遍历区域
  365. for (var i = 0, len = features.length; i < len; i++) {
  366. var point = features[i].geometry;
  367. var pointFeature = new SuperMap.Feature.Vector(point, {
  368. FEATUREID: features[i].data.FEATUREID,
  369. TIME: features[i].data.TIME,
  370. POPULATION: features[i].data.POPULATION
  371. });
  372. pointFeatures.push(pointFeature);
  373. }
  374. animatorVector.addFeatures(pointFeatures);
  375. }
  376. function processFailed(getFeaturesEventArgs) {
  377. widgets.alert.showAlert(getFeaturesEventArgs.error.errorMsg, false);
  378. }
  379. //开始播放动画
  380. function startAnimator() {
  381. animatorVector.animator.start();
  382. }
  383. //暂停播放动画
  384. function pauseAnimator() {
  385. animatorVector.animator.pause();
  386. }
  387. </script>
  388. </body>
  389. </html>