vizLayer_animatorWeatherMonitor.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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_animatorWeatherMonitor"></title>
  9. <script src='./data/sampleData1.js'></script>
  10. <script src='./data/sampleData2.js'></script>
  11. <script src='./data/sampleData3.js'></script>
  12. <script src='./data/sampleData4.js'></script>
  13. <script src='./data/sampleData5.js'></script>
  14. <script src='./data/sampleData6.js'></script>
  15. <script src='./data/sampleData7.js'></script>
  16. <script src='./data/sampleData8.js'></script>
  17. <style type="text/css">
  18. body {
  19. margin: 0;
  20. overflow: hidden;
  21. background: #fff;
  22. width: 100%;
  23. height: 100%
  24. }
  25. #map {
  26. position: absolute;
  27. width: 100%;
  28. height: 100%;
  29. }
  30. #toolbar {
  31. position: absolute;
  32. top: 50px;
  33. right: 10px;
  34. text-align: center;
  35. z-index: 100;
  36. border-radius: 4px;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <div id="toolbar" class="panel panel-primary">
  42. <div class='panel-heading'>
  43. <h5 class='panel-title text-center' data-i18n="resources.title_animatorWeatherMonitor"></h5></div>
  44. <div class='panel-body content'>
  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>
  53. var map, layer, animatorVector, features, select, tempLayer,
  54. drag, delIndex = 0, editEnable = false, dataIndex = 0, timerID = null,
  55. weatherDatas = [],
  56. //设置图层样式
  57. transformControl,
  58. style = {
  59. strokeColor: "#cccccc",
  60. strokeWidth: 1,
  61. fillColor: "#ccfffa",
  62. fillOpacity: "0.5"
  63. },
  64. style2 = {
  65. strokeColor: "#cccccc",
  66. strokeWidth: 1,
  67. fillColor: "#a3f8b4",
  68. fillOpacity: "0.5"
  69. },
  70. style1 = {
  71. strokeColor: "#cccccc",
  72. strokeWidth: 1,
  73. fillColor: "#79f26f",
  74. fillOpacity: "0.5"
  75. },
  76. style3 = {
  77. strokeColor: "#cccccc",
  78. strokeWidth: 1,
  79. fillColor: "#2dd90b",
  80. fillOpacity: "0.5"
  81. },
  82. style4 = {
  83. strokeColor: "#cccccc",
  84. strokeWidth: 1,
  85. fillColor: "#8aee1e",
  86. fillOpacity: "0.5"
  87. },
  88. style6 = {
  89. strokeColor: "#cccccc",
  90. strokeWidth: 1,
  91. fillColor: "#c5ef0f",
  92. fillOpacity: "0.5"
  93. },
  94. style5 = {
  95. strokeColor: "#cccccc",
  96. strokeWidth: 1,
  97. fillColor: "#fff100",
  98. fillOpacity: "0.5"
  99. },
  100. style7 = {
  101. strokeColor: "#cccccc",
  102. strokeWidth: 1,
  103. fillColor: "#fcbd10",
  104. fillOpacity: "0.5"
  105. },
  106. style8 = {
  107. strokeColor: "#cccccc",
  108. strokeWidth: 1,
  109. fillColor: "#fb8722",
  110. fillOpacity: "0.5"
  111. },
  112. style9 = {
  113. strokeColor: "#cccccc",
  114. strokeWidth: 1,
  115. fillColor: "#d53b3b",
  116. fillOpacity: "1"
  117. },
  118. host = window.isLocal ? window.server : "https://iserver.supermap.io",
  119. url1 = host + "/iserver/services/map-world/rest/maps/World";
  120. init();
  121. function init() {
  122. /*
  123. * 不支持canvas的浏览器不能运行该范例
  124. * android 设备也不能运行该范例*/
  125. var broz = SuperMap.Util.getBrowser();
  126. if (!document.createElement('canvas').getContext) {
  127. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  128. return;
  129. } else if (broz.device === 'android') {
  130. widgets.alert.showAlert(resources.msg_supportEquipment, false);
  131. return;
  132. }
  133. //加载map控件
  134. map = new SuperMap.Map("map", {
  135. controls: [
  136. new SuperMap.Control.ScaleLine(),
  137. new SuperMap.Control.Zoom(),
  138. new SuperMap.Control.Navigation({
  139. dragPanOptions: {
  140. enableKinetic: true
  141. }
  142. })], units: "m"
  143. });
  144. map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
  145. //初始化图层
  146. layer = new SuperMap.Layer.TiledDynamicRESTLayer("China400", url1, {
  147. transparent: true,
  148. cacheEnabled: true
  149. }, {maxResolution: "auto"});
  150. //初始化动画矢量图层
  151. animatorVector = new SuperMap.Layer.AnimatorVector("Polygon", {smooth: false}, {
  152. //设置速度为每帧播放1小时的数据
  153. speed: 1,
  154. //开始时间为0点
  155. startTime: 0,
  156. //每秒渲染1次
  157. frameRate: 1,
  158. //结束时间为7点
  159. endTime: 7
  160. });
  161. layer.events.on({"layerInitialized": addLayer});
  162. }
  163. //添加图层
  164. function addLayer() {
  165. map.addLayers([layer, animatorVector]);
  166. map.setCenter(new SuperMap.LonLat(106, 34), 2);
  167. map.addControl(new SuperMap.Control.MousePosition());
  168. monitor();
  169. };
  170. //添加数据
  171. function monitor() {
  172. //初始化数据
  173. if (weatherDatas.length == 0) {
  174. weatherDatas[0] = SuperMap.REST.Recordset.fromJson(sampleData1);
  175. weatherDatas[1] = SuperMap.REST.Recordset.fromJson(sampleData2);
  176. weatherDatas[2] = SuperMap.REST.Recordset.fromJson(sampleData3);
  177. weatherDatas[3] = SuperMap.REST.Recordset.fromJson(sampleData4);
  178. weatherDatas[4] = SuperMap.REST.Recordset.fromJson(sampleData5);
  179. weatherDatas[5] = SuperMap.REST.Recordset.fromJson(sampleData6);
  180. weatherDatas[6] = SuperMap.REST.Recordset.fromJson(sampleData7);
  181. weatherDatas[7] = SuperMap.REST.Recordset.fromJson(sampleData8);
  182. }
  183. animatorVector.removeAllFeatures();
  184. var features = [];
  185. for (var index = 0; index < weatherDatas.length; index++) {
  186. var result = weatherDatas[index];
  187. var len = result.features.length;
  188. for (var i = 0; i < len; i++) {
  189. var feature = result.features[i];
  190. var data = feature.attributes;
  191. data['TIME'] = index;
  192. data['FEATUREID'] = index + "_" + i;
  193. var value = data['DMAXVALUE'];
  194. if (value < -24) {
  195. feature.style = style;
  196. }
  197. else if (value < -18) {
  198. feature.style = style1;
  199. }
  200. else if (value < -12) {
  201. feature.style = style2;
  202. }
  203. else if (value < -6) {
  204. feature.style = style3;
  205. }
  206. else if (value < 0) {
  207. feature.style = style4;
  208. }
  209. else if (value < 6) {
  210. feature.style = style5;
  211. }
  212. else if (value < 12) {
  213. feature.style = style6;
  214. }
  215. else if (value < 18) {
  216. feature.style = style7;
  217. }
  218. else if (value < 24) {
  219. feature.style = style8;
  220. }
  221. else {
  222. features.style = style9;
  223. }
  224. features.push(feature);
  225. }
  226. }
  227. animatorVector.addFeatures(features);
  228. };
  229. //开始播放动画
  230. function startAnimator() {
  231. animatorVector.animator.start();
  232. }
  233. //暂停播放动画
  234. function pauseAnimator() {
  235. animatorVector.animator.pause();
  236. }
  237. </script>
  238. </body>
  239. </html>