GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — iClient-JavaScript/examples/leaflet/PlanesMonitor.html at master · lyinghappy/iClient-JavaScript Expand file tree/ Copy pathPlanesMonitor.htmlMore file actions 515 lines (455 loc) · 18.3 KB / Copy pathPlanesMonitor.htmlFile metadata and controls515 lines (455 loc) · 18.3 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 <!--******************************************************************** * Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved. *********************************************************************--> <!--******************************************************************** * 该示例需要引入 * Mapv (https://github.com/huiyan-fe/mapv) * Elasticsearch (https://github.com/elastic/elasticsearch-js) *********************************************************************--> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title data-i18n="resources.title_planesMonitor"></title> <script type="text/javascript" include="jquery,bootstrap,moment,bootstrap-datetimepicker,bootstrap-select,geohash,randomcolor,widgets.alert" src="../js/include-web.js"></script> <style> .bootstrap-select { width: 168px !important; } .form-control.input-sm { width: 166px; } .form-group label { width: 100px; } .tips { z-index: 1000; } </style> </head> <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;"> <div id="map" style="margin:0 auto;width: 100%;height: 100%;"></div> <script type="text/javascript" include="mapv,elasticsearch" src="../../dist/leaflet/include-leaflet.js"></script> <script type="text/javascript"> var map; var timeControl, liveESService,//实时点查询的ESService trackESService,//历史轨迹查询的ESService liveRenderer,//实时点层 trackLineLayers,//历史轨迹层 trackLineMap,//轨迹线数据 liveDataSet,//渲染用实时点数据集 planeStyles, planeLabels,//航班信息提示框集合 dataUrl = "https://iclient.supermap.io/es"; var flightIdens = [ 'CCA4189', 'CCA4187', 'CBJ5531', 'CSC8747', 'TBA9879', 'CCA4113', 'CES2251', 'CCA4521', 'CSC8927', 'CSC8811', 'CSC8857', 'UEA2711', 'UEA2205', 'CCA4439', 'CCA415', 'CSC8719', 'CSC8555', 'CCA4211', 'HDA825' ]; init(); function init() { initMap(); liveESService = new L.supermap.ElasticSearch(dataUrl, elasticsearch); trackESService = new L.supermap.ElasticSearch(dataUrl, elasticsearch); planeStyles = initPlaneStyles(); } //开始播放 function start() { var options = getControlOptions(); if (!timeControl) { timeControl = new L.supermap.TimeFlowControl(loadLiveData, options); } else { timeControl.updateOptions(options); } timeControl.start(); } //暂停播放 function pause() { if(!timeControl){ return; }else{ timeControl.pause(); } } //停止播放 function stop() { if(!timeControl){ return; }else{ timeControl.stop(); clearAll(); } } //时间控制器回调参数,即每次刷新时执行的操作,此处为向服务器请求数据并绘制。实时刷新执行。 function loadLiveData(currentTime) { var datetime = moment(currentTime).format("YYYY-MM-DDTHH:mm:ss") + "Z"; var options = getServiceParamOptions(); var liveParameters = []; for (var i = 0; i < options.flightIds.length; i++) { var code = options.flightIds[i]; if (code === 'ZUUU') { continue; } liveParameters.push({index: "flights", type: "flight_utc"}); liveParameters.push({ "query": { "bool": { "must": {"match": {"ident": code}}, "filter": {"match": {"datetime": datetime}}, } }, "sort": {"time-ms": {"order": "ASC"}}, "from": 0, "size": 20 }); } liveESService.msearch({body: liveParameters}, function (error, result) { if (error) { widgets.alert.showAlert(JSON.stringify(error), false); timeControl.stop(); return; } result.responses && renderData.call(window, result.responses); }); updateProgress(datetime); } //渲染实时点数据和轨迹图层 function renderData(result) { if (timeControl && !timeControl.getRunning()) { return; } var data = createLiveRendererData(result); if (data.length < 1) { return; } updateDataSet(data); if (!liveRenderer) { liveRenderer = new L.supermap.MapVLayer(liveDataSet, { zIndex: 800, globalCompositeOperation: "lighter", shadowColor: "white", shadowBlur: 2, draw: 'icon', methods: { click: function (evt) { renderLiveLabel.call(window, evt) } } }).addTo(map); } else { liveRenderer.update({data: liveDataSet}); } renderTrackLineLayers(); } //解析点查询结果数据为mapv数据 function createLiveRendererData(results) { var data = []; results && results.map(function (result) { result.hits.hits.map(function (source) { var content = source._source; data.push({ geometry: { type: 'Point', coordinates: [content.x, content.y], }, deg: content.direction, icon: planeStyles[content.ident].img, ident: content.ident, content: content }); trackLineMap = trackLineMap || {}; if (!trackLineMap[content.ident]) { trackLineMap[content.ident] = []; } trackLineMap[content.ident].push([content.x, content.y]); }); }); return data; } //更新点数据集 function updateDataSet(data) { if (!liveDataSet) { liveDataSet = new mapv.DataSet(data); return; } var dat = data.slice(); var innerData = liveDataSet.get(); for (var i = 0; i < dat.length; i++) { for (var j = 0; j < innerData.length; j++) { if (dat[i].ident === innerData[j].ident) { innerData[j] = dat[i]; break; } } //如果是新的飞机Id则追加到飞机数组里 if (j === innerData.length) { innerData.push(dat[i]); } } liveDataSet.set(innerData); } //渲染轨迹图层 function renderTrackLineLayers() { if (!trackLineLayers) { trackLineLayers = {}; } for (var id in trackLineMap) { renderTrackLayerData(id, trackLineMap[id]); } } //渲染飞机id所对应的轨迹 function renderTrackLayerData(id, coordinates) { var trackLayer = trackLineLayers[id]; var trackDataSet = new mapv.DataSet({ geometry: { type: 'LineString', coordinates: coordinates } }); if (!trackLayer) { var options = { zIndex: 1, strokeStyle: planeStyles[id].color, shadowColor: "white", shadowBlur: 1, lineCap: 'butt', lineJoin: "round", lineWidth: 3, draw: 'simple' }; trackLayer = new L.supermap.MapVLayer(trackDataSet, options).addTo(map); trackLineLayers[id] = trackLayer; } else { trackLayer.update({data: trackDataSet}); } } //实时点的提示框 function renderLiveLabel(data) { planeLabels = planeLabels || {}; var content = data && data.content; if (!content) return; var latlng = L.latLng(content.y, content.x); var labelContent = resources.text_flight + ": " + content.ident + "<br>" + resources.text_startPoint + ": " + content.origin + "/" + content.originLabel + "<br>" + resources.text_endPoint + ": " + content.destination + "/" + content.destinationLabel + "<br>" + resources.text_time + ": " + content.datetime; if (planeLabels[content.ident]) { planeLabels[content.ident].remove(); } planeLabels[content.ident] = L.popup({ autoPan: false, maxWidth: 180, offset: L.point(0, -1) }).setContent(labelContent).setLatLng(latlng).addTo(map); } //初始化飞机的样式,颜色随机 function initPlaneStyles() { var planes = {}; var colors = randomColor({ luminosity: 'bright', hue: 'random', alpha: 1, count: flightIdens.length }); $.ajaxSetup({ async: false }); var count = flightIdens.length; $.get('../data/plane.svg', function (svg) { flightIdens.map(function (ident, key) { $(svg).children('svg').css("fill",colors[key]); var svgUrl= "data:image/svg+xml;utf8,"+$(svg).children('svg')[0].outerHTML; var img = new Image(); img.src = svgUrl; planes[ident] = {color: colors[key], img: img}; }); }); return planes; } //获取时间控件设置的参数 function getControlOptions() { var startTime = $("#startTime").val(); var endTime = $("#endTime").val(); startTime = new Date(Date.parse(startTime.replace(/-/g, "/"))).getTime(); endTime = new Date(Date.parse(endTime.replace(/-/g, "/"))).getTime(); var speed = $("#speed").val(); speed = (speed > 0) ? speed : 1000; speed = parseInt(speed); var frequency = $("#frequency").val(); frequency = (frequency > 0) ? frequency : 1000; frequency = parseInt(frequency); return { startTime: startTime, endTime: endTime, speed: speed, frequency: frequency } } //获取ES服务查询参数 function getServiceParamOptions() { var flightIds = $("#flightIds").val(); return { flightIds: flightIds } } //更新当前时间界面 function updateProgress(currentTime) { $("#progress").html(currentTime); } //默认设置参数 function getDefaultControlOptions() { var startMs = 1498781767725; var endMs = 1498935332876; var start = moment(startMs).format("YYYY-MM-DDTHH:mm:ss") + "Z"; var end = moment(endMs).format("YYYY-MM-DDTHH:mm:ss") + "Z"; return { startTime: start, endTime: end, speed: 1000, frequency: 100, } } function initMap() { if (!map) { map = L.map('map', { crs: L.CRS.EPSG3857, center: [31.3677, 108.116], maxZoom: 20, minZoom: 3, zoom: 7 }); var attr = 'Data © <a href="https://www.elastic.co/products/elasticsearch" target="_blank">Elasticsearch</a> Map Data <span>© <a href="http://support.supermap.com.cn/product/iServer.aspx" target="_blank">SuperMap iServer</a></span>'; var host = window.isLocal ? window.server : "https://iserver.supermap.io"; var url = host + "/iserver/services/map-china/rest/maps/ChinaDark"; new L.supermap.TiledMapLayer(url, {attribution: attr}).addTo(map); } initTimeControlView(); } //初始化时间控制控件,仅UI function initTimeControlView() { var control = L.control({position: "topright"}); control.onAdd = function () { var me = this; me._div = L.DomUtil.create('div', 'panel panel-primary controlPane'); me._div.style.width = "300px"; var titleDiv = $("<div class='panel-heading text-center' id='toggle' style='cursor: pointer'>" + "<span class='panel-title text-center'>" + resources.text_console + "</span> " + "<span class='glyphicon glyphicon-triangle-top' id='toggleIcon' ></span></div>").appendTo(me._div); var contentDiv = $("<div class='panel-body content center-block' style='font-size: 14px'></div>").appendTo(me._div); var optionsDiv = $("<div class='' id='options'></div>").appendTo(contentDiv); $("<div class='form-group'><label class='text-right' for='flightIds' >" + resources.text_flightNumber + "<span style='color:red'>*</span></label>" + "<select class='selectpicker ' id='flightIds' multiple " + "data-actions-box='true' " + "data-select-all-Text='" + resources.text_allSelect + "' " + "data-deselect-all-Text='" + resources.text_deSelectAll + "' " + "title='" + resources.text_select + "'>" + initSelectOpitons() + "</select></div><hr/>").appendTo(optionsDiv); function initSelectOpitons() { var str = ''; flightIdens.map(function (ident, key) { str += "<option value=" + ident + " selected>" + ident + "</option> " }); return str; } var defaultOption = getDefaultControlOptions(); $("<div class='form-group form-inline'><label class='text-right' for='startTime' >" + resources.text_startTime + "<span style='color:red'>*</span></label>" + "<input id='startTime' type='text' class='form-control input-sm' placeholder='" + defaultOption.startTime + "' value='" + defaultOption.startTime + "'/></div></div>").appendTo(optionsDiv); $("<div class='form-group form-inline'><label class='text-right' for='endTime' >" + resources.text_finishTime + "<span style='color:red'>*</span></label>" + "<input id='endTime' type='text' class='form-control input-sm' placeholder='" + defaultOption.endTime + "' value='" + defaultOption.endTime + "'/></div></div>").appendTo(optionsDiv); $("<div class='form-group form-inline'><label class='text-right' for='speed' >" + resources.text_refreshStepSize + "(ms)</label>" + "<input id='speed' type='number' min='1' class='form-control input-sm' placeholder='" + defaultOption.speed + "' value='" + defaultOption.speed + "'/></div></div>").appendTo(optionsDiv); $("<div class='form-group form-inline'><label class='text-right' for='frequency' >" + resources.text_refreshFrequency + "(ms)</label>" + "<input id='frequency' type='number' min='1' class='form-control input-sm' placeholder='" + defaultOption.frequency + "' value='" + defaultOption.frequency + "'/></div></div>").appendTo(optionsDiv); var progressDiv = $("<div class='form-group'><div class='form-horizontal text-center'><div class='form-group'>" + "<label for='progress'>" + resources.text_currentTime + "</label><span class='form-control-static' id='progress'>" + resources.text_noStart + "</span>" + "</div></div></div>").appendTo(contentDiv); var controlDiv = $("<section><div class='form-inline text-center'>" + "<input id='start' type='button' class='btn btn-default text-center' value='" + resources.btn_start + "'/> " + "<input id='pause' type='button' class='btn btn-default text-center' value='" + resources.btn_pause + "'/> " + "<input id='stop' type='button' class='btn btn-default text-center' value='" + resources.btn_stop + "'/>" + "</div></section>").appendTo(contentDiv); me._div.addEventListener('mouseover', function () { me._map.dragging.disable(); me._map.scrollWheelZoom.disable(); me._map.doubleClickZoom.disable(); }); me._div.addEventListener('mouseout', function () { me._map.dragging.enable(); me._map.scrollWheelZoom.enable(); me._map.doubleClickZoom.enable(); }); return me._div; }; control.addTo(map); var dateOptions = { format: "YYYY-MM-DD HH:mm:ss", stepping: 1, showClose: true, locale: 'zh-cn' }; $("#startTime").datetimepicker(dateOptions); $("#endTime").datetimepicker(dateOptions); $('#flightIds').selectpicker(); $("#start").on('click', function () { $("#options").slideUp("fast", function () { toggle(this); }); start(); }); $("#pause").on('click', pause); $("#stop").on('click', stop); $("#toggle").on('click', function () { $("#options").slideToggle("fast", function () { toggle(this); }); return false; }); function toggle(ele) { if ($(ele).is(":visible")) { $("#toggleIcon").attr('class', "glyphicon glyphicon-triangle-top"); } else { $("#toggleIcon").attr('class', "glyphicon glyphicon-triangle-bottom"); } } } function clearAll() { if (timeControl) { timeControl.destroy(); timeControl = null; } if (trackLineLayers) { for (var id in trackLineLayers) { map.removeLayer(trackLineLayers[id]); } trackLineLayers = null; } if (trackLineMap) { trackLineMap = null; } if (liveRenderer) { map.removeLayer(liveRenderer); liveRenderer = null; } if (liveDataSet) { liveDataSet = null; } if (planeLabels) { for (var item in planeLabels) { planeLabels[item].remove(); } planeLabels = {}; } } </script> </body> </html> |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |