getFeatureByAggregation.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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_ESGridAggregation"></title>
  9. <script type="text/javascript" include="jquery,bootstrap,moment,bootstrap-datetimepicker,bootstrap-select"
  10. src="../js/include-web.js"></script>
  11. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  13. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  14. <script type="text/javascript" include="mapv" src="../../dist/leaflet/include-leaflet.js"></script>
  15. <script type="text/javascript">
  16. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  17. var map,
  18. baseUrl = host + "/iserver/services/map-china400/rest/maps/ChinaDark",
  19. url = host + "/iserver/services/data-es/rest/data";
  20. var liveRenderer,
  21. timeControl,
  22. liveDataSet,
  23. info = L.control({position: 'bottomleft'}),
  24. layerOptions = getGridOptions();
  25. map = L.map('map', {
  26. center: [33.75, 0],
  27. maxZoom: 15,
  28. minZoom: 1,
  29. zoom: 2,
  30. crs: L.CRS.EPSG3857
  31. });
  32. L.supermap.tiledMapLayer(baseUrl).addTo(map);
  33. init();
  34. function init() {
  35. info.onAdd = function () {
  36. var popup = L.DomUtil.create('div');
  37. popup.innerHTML = "<div class='btn-group' role='group' aria-label='...'>" +
  38. "<button value='grid' type='button' class='btn btn-default'>" + resources.btn_grid + "</button>" +
  39. "<button value='heatmap' type='button' class='btn btn-default'>" + resources.title_heatMap + "</button></div>"
  40. handleMapEvent(popup, map);
  41. return popup;
  42. };
  43. info.addTo(map);
  44. initTimeControlView();
  45. }
  46. //默认设置参数
  47. function getDefaultControlOptions() {
  48. var startMs = 1493706384000;
  49. var endMs = 1504333584000;
  50. var start = moment(startMs).format("YYYY-MM-DD HH:mm:ss");
  51. var end = moment(endMs).format("YYYY-MM-DD HH:mm:ss");
  52. return {
  53. startTime: start,
  54. endTime: end,
  55. speed: 300000,
  56. frequency: 1000
  57. }
  58. }
  59. function handleMapEvent(div, map) {
  60. if (!div || !map) {
  61. return;
  62. }
  63. div.addEventListener('mouseover', function () {
  64. map.dragging.disable();
  65. map.scrollWheelZoom.disable();
  66. map.doubleClickZoom.disable();
  67. });
  68. div.addEventListener('mouseout', function () {
  69. map.dragging.enable();
  70. map.scrollWheelZoom.enable();
  71. map.doubleClickZoom.enable();
  72. });
  73. }
  74. //开始播放
  75. function start() {
  76. var options = getControlOptions();
  77. if (!timeControl) {
  78. timeControl = new SuperMap.TimeFlowControl(loadLiveData, options);
  79. } else {
  80. timeControl.updateOptions(options);
  81. }
  82. timeControl.start();
  83. }
  84. //暂停播放
  85. function pause() {
  86. timeControl.pause();
  87. }
  88. //停止播放
  89. function stop() {
  90. timeControl.stop();
  91. clearAll();
  92. }
  93. //时间控制器回调参数,即每次刷新时执行的操作,此处为向服务器请求数据并绘制。实时刷新执行。
  94. function loadLiveData(currentTime) {
  95. query(currentTime, currentTime + getControlOptions().speed);
  96. updateProgress(moment(currentTime).format("YYYY-MM-DD HH:mm:ss"));
  97. }
  98. function query(startTime, endTime) {
  99. var esmode = $("#esmode").val();
  100. var geoHashAggegation = new SuperMap.GeoHashGridAggParameter({
  101. aggName: "aggName",
  102. aggFieldName: "pin.location",
  103. precision: 5
  104. });
  105. var sqlParam = new SuperMap.GetFeaturesBySQLParameters({
  106. queryParameter: {
  107. name: "flight",
  108. },
  109. datasetNames: ["aliveflight:flight"],
  110. aggregations: geoHashAggegation,
  111. maxFeatures: 1000
  112. });
  113. if (esmode === "esmodeHistroy") {
  114. sqlParam.queryParameter.attributeFilter = "datetime>" + startTime + " AND datetime<" + endTime;
  115. } else {
  116. sqlParam.queryParameter.attributeFilter = "id>0";
  117. }
  118. L.supermap.featureService(url).getFeaturesBySQL(sqlParam, function (serviceResult) {
  119. renderLive(serviceResult.result.aggregations[0].buckets);
  120. });
  121. }
  122. function renderLive(result) {
  123. var data = createLiveRendererData(result);
  124. if (data.length < 1) {
  125. return;
  126. }
  127. updateDataSet(data);
  128. if (!liveRenderer) {
  129. liveRenderer = L.supermap.mapVLayer(liveDataSet, layerOptions, {noWrap: true}).addTo(map);
  130. } else {
  131. liveRenderer.update({data: liveDataSet, options: layerOptions});
  132. }
  133. }
  134. function updateDataSet(data) {
  135. if (!liveDataSet) {
  136. liveDataSet = new mapv.DataSet(data);
  137. return;
  138. }
  139. var innerData = liveDataSet.get();
  140. var dataLen = data.length;
  141. for (var i = 0; i < innerData.length; i++) {
  142. if (i < dataLen && data[i].ident === innerData[i].ident) {
  143. innerData[i] = data[i];
  144. }
  145. }
  146. liveDataSet.set(innerData);
  147. }
  148. //更新当前时间界面
  149. function updateProgress(currentTime) {
  150. $("#progress").html(currentTime);
  151. }
  152. //获取时间控件设置的参数
  153. function getControlOptions() {
  154. var startTime = $("#startTime").val();
  155. var endTime = $("#endTime").val();
  156. startTime = new Date(Date.parse(startTime.replace(/-/g, "/"))).getTime();
  157. endTime = new Date(Date.parse(endTime.replace(/-/g, "/"))).getTime();
  158. var speed = $("#speed").val();
  159. speed = (speed > 0) ? speed : 1000;
  160. speed = parseInt(speed);
  161. var frequency = $("#frequency").val();
  162. frequency = (frequency > 0) ? frequency : 1000;
  163. frequency = parseInt(frequency);
  164. return {
  165. startTime: startTime,
  166. endTime: endTime,
  167. speed: speed,
  168. frequency: frequency
  169. }
  170. }
  171. //解析点查询结果数据为mapv数据
  172. function createLiveRendererData(results) {
  173. var data = [];
  174. for (var i = 0; i < results.length; i++) {
  175. data.push({
  176. geometry: {
  177. type: 'Point',
  178. coordinates: [results[i].point.x, results[i].point.y]
  179. },
  180. count: results[i].count
  181. });
  182. }
  183. return data;
  184. }
  185. var buttons = $('.btn-group').children();
  186. buttons.map(function (key) {
  187. var value = buttons[key].value;
  188. if (value === 'grid') {
  189. $(buttons[key]).on('click', function () {
  190. layerOptions = getGridOptions();
  191. if (liveDataSet) {
  192. liveRenderer.update({data: liveDataSet, options: layerOptions});
  193. }
  194. });
  195. return;
  196. }
  197. if (value === 'heatmap') {
  198. $(buttons[key]).on('click', function () {
  199. layerOptions = getHeatMapOptions();
  200. if (liveDataSet) {
  201. liveRenderer.update({data: liveDataSet, options: layerOptions});
  202. }
  203. });
  204. }
  205. });
  206. function getGridOptions() {
  207. return {
  208. fillStyle: 'rgba(55, 50, 250, 0.8)',
  209. shadowColor: 'rgba(255, 250, 50, 1)',
  210. shadowBlur: 10,
  211. size: 40,
  212. globalAlpha: 0.5,
  213. label: {
  214. show: true,
  215. fillStyle: 'white',
  216. shadowColor: 'yellow',
  217. font: '15px Arial',
  218. shadowBlur: 10
  219. },
  220. gradient: {
  221. 0: "rgba(49, 54, 149, 0)",
  222. 0.2: "rgba(69,117,180, 0.7)",
  223. 0.3: "rgba(116,173,209, 0.7)",
  224. 0.4: "rgba(171,217,233, 0.7)",
  225. 0.5: "rgba(224,243,248, 0.7)",
  226. 0.6: "rgba(254,224,144,0.7)",
  227. 0.7: "rgba(253,174,97,0.7)",
  228. 0.8: "rgba(244,109,67,0.8)",
  229. 0.9: "rgba(215,48,39,0.8)",
  230. 0.95: "rgba(165, 0, 38,0.8)"
  231. },
  232. draw: 'grid'
  233. }
  234. }
  235. function getHeatMapOptions() {
  236. return {
  237. size: 20,
  238. gradient: {
  239. 0: "rgba(49, 54, 149, 0)",
  240. 0.2: "rgba(69,117,180, 0.7)",
  241. 0.3: "rgba(116,173,209, 0.7)",
  242. 0.4: "rgba(171,217,233, 0.7)",
  243. 0.5: "rgba(224,243,248, 0.7)",
  244. 0.6: "rgba(254,224,144,0.7)",
  245. 0.7: "rgba(253,174,97,0.7)",
  246. 0.8: "rgba(244,109,67,0.8)",
  247. 0.9: "rgba(215,48,39,0.8)",
  248. 0.95: "rgba(165, 0, 38,0.8)"
  249. },
  250. draw: 'heatmap'
  251. }
  252. }
  253. //初始化时间控制控件,仅UI
  254. function initTimeControlView() {
  255. var control = L.control({position: "topright"});
  256. control.onAdd = function () {
  257. var me = this;
  258. me._div = L.DomUtil.create('div', 'panel panel-primary controlPane');
  259. me._div.style.width = "300px";
  260. $("<div class='panel-heading text-center' id='toggle' style='cursor: pointer'>" +
  261. "<span class='panel-title text-center'>" + resources.text_console + "</span>&nbsp;" +
  262. "<span class='glyphicon glyphicon-triangle-top' id='toggleIcon' ></span></div>").appendTo(me._div);
  263. var contentDiv = $("<div class='panel-body content center-block' style='font-size: 14px'></div>").appendTo(me._div);
  264. var optionsDiv = $("<div class='' id='options'></div>").appendTo(contentDiv);
  265. var defaultOption = getDefaultControlOptions();
  266. $("<div class='form-group form-inline'><label class='text-right' for='esmode' >" + resources.text_esmode + ": " + "</label>" +
  267. "<select id='esmode' class='form-control'><option id='esmode_streaming' value='esmodeStreaming'>" + resources.text_esmode_streaming + "</option> " +
  268. "<option id='esmode_histroy' selected value='esmodeHistroy'>" + resources.text_esmode_history + "</option> " +
  269. "</select> " + "</div></div>").appendTo(optionsDiv);
  270. var timeOptionDiv = $("<div class='' id='timeOption'></div>").appendTo(optionsDiv);
  271. $("<div class='form-group form-inline'><label class='text-right' for='startTime' >" + resources.text_startTime + ": " + "</label>" +
  272. "<input id='startTime' type='text' class='form-control input-sm' placeholder='" + defaultOption.startTime +
  273. "' value='" + defaultOption.startTime + "'/></div></div>").appendTo(timeOptionDiv);
  274. $("<div class='form-group form-inline'><label class='text-right' for='endTime' >" + resources.text_finishTime + ": " + "</label>" +
  275. "<input id='endTime' type='text' class='form-control input-sm' placeholder='" + defaultOption.endTime +
  276. "' value='" + defaultOption.endTime + "'/></div></div>").appendTo(timeOptionDiv);
  277. $("<div class='form-group form-inline'><label class='text-right' for='speed' >" + resources.text_refreshStepSize + ": " + "</label>" +
  278. "<input id='speed' type='number' min='1' class='form-control input-sm' placeholder='" + defaultOption.speed +
  279. "' value='" + defaultOption.speed + "'/></div></div>").appendTo(timeOptionDiv);
  280. $("<div class='form-group form-inline'><label class='text-right' for='frequency' >" + resources.text_refreshFrequency + ": " + "</label>" +
  281. "<input id='frequency' type='number' min='1' class='form-control input-sm' placeholder='" + defaultOption.frequency +
  282. "' value='" + defaultOption.frequency + "'/></div></div>").appendTo(optionsDiv);
  283. $("<div class='form-group' id='progressDiv'><div class='form-horizontal text-center'><div class='form-group'>" +
  284. "<label for='progress'>" + resources.text_currentTime + "</label><span class='form-control-static' id='progress'>" + resources.text_noStart + "</span>" +
  285. "</div></div></div>").appendTo(contentDiv);
  286. $("<section><div class='form-inline text-center'>" +
  287. "<input id='start' type='button' class='btn btn-default text-center' value=" + resources.btn_start + ">&nbsp;" +
  288. "<input id='pause' type='button' class='btn btn-default text-center' value=" + resources.btn_pause + ">&nbsp;" +
  289. "<input id='stop' type='button' class='btn btn-default text-center' value=" + resources.btn_stop + ">" +
  290. "</div></section>").appendTo(contentDiv);
  291. me._div.addEventListener('mouseover', function () {
  292. me._map.dragging.disable();
  293. me._map.scrollWheelZoom.disable();
  294. me._map.doubleClickZoom.disable();
  295. });
  296. me._div.addEventListener('mouseout', function () {
  297. me._map.dragging.enable();
  298. me._map.scrollWheelZoom.enable();
  299. me._map.doubleClickZoom.enable();
  300. });
  301. return me._div;
  302. };
  303. control.addTo(map);
  304. var dateOptions = {
  305. format: "YYYY-MM-DD HH:mm:ss",
  306. stepping: 1,
  307. showClose: true,
  308. locale: 'zh-cn'
  309. };
  310. // $("#timeOption").hide();
  311. // $("#progressDiv").hide();
  312. $("#esmode").change(function () {
  313. var esmode = $(this).val();
  314. if (esmode === "esmodeStreaming") {
  315. $("#timeOption").hide();
  316. $("#progressDiv").hide();
  317. } else {
  318. $("#timeOption").show();
  319. $("#progressDiv").show();
  320. }
  321. });
  322. $("#startTime").datetimepicker(dateOptions);
  323. $("#endTime").datetimepicker(dateOptions);
  324. $("#start").on('click', function () {
  325. $("#options").slideUp("fast", function () {
  326. toggle(this);
  327. });
  328. start();
  329. });
  330. $("#pause").on('click', pause);
  331. $("#stop").on('click', stop);
  332. $("#toggle").on('click', function () {
  333. $("#options").slideToggle("fast", function () {
  334. toggle(this);
  335. });
  336. return false;
  337. });
  338. function toggle(ele) {
  339. if ($(ele).is(":visible")) {
  340. $("#toggleIcon").attr('class', "glyphicon glyphicon-triangle-top");
  341. } else {
  342. $("#toggleIcon").attr('class', "glyphicon glyphicon-triangle-bottom");
  343. }
  344. }
  345. }
  346. function clearAll() {
  347. if (timeControl) {
  348. timeControl.destroy();
  349. timeControl = null;
  350. }
  351. if (liveRenderer) {
  352. map.removeLayer(liveRenderer);
  353. liveRenderer = null;
  354. }
  355. if (liveDataSet) {
  356. liveDataSet = null;
  357. }
  358. }
  359. </script>
  360. </body>
  361. </html>