dataFlowService.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_dataFlowService"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. </head>
  11. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  12. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  13. <script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var wsHost = "wss:\//" + (window.isLocal ? document.location.hostname + ":8800" : "iclsvrws.supermap.io");
  17. var map,
  18. urlMap = host + "/iserver/services/map-china400/rest/maps/China",
  19. urlQuery = host + "/iserver/services/map-china400/rest/maps/China_4326",
  20. urlDataFlow = wsHost + "/iserver/services/dataflowTest/dataflow";
  21. map = L.map('map', {
  22. preferCanvas: true,
  23. crs: L.CRS.EPSG3857,
  24. center: [39.88, 116.42],
  25. maxZoom: 18,
  26. zoom: 12
  27. });
  28. L.supermap.tiledMapLayer(urlMap).addTo(map);
  29. SuperMap.SecurityManager.registerToken(urlDataFlow, window.exampleToken);
  30. var popup = L.popup({
  31. offset: L.point(0, 0),
  32. autoPan: true
  33. });
  34. //创建DataFlowLayer,创建DataFlowLayer订阅iServer dataflow服务并将结果加载到地图上
  35. var dataFlowLayer = L.supermap.dataFlowLayer(urlDataFlow, {
  36. style: function (feature) {
  37. return {
  38. fillColor: "red",
  39. fillOpacity: 1,
  40. radius: 6,
  41. weight: 0
  42. };
  43. }
  44. //geometry:{coordinates:[[[116.381741960923,39.8765100055449],[116.414681699817,39.8765100055449],[116.414681699817,39.8415115329708],[116.381741960923, 39.8415115329708],[116.381741960923,39.8765100055449]]],type:"Polygon"},
  45. //excludeField:["id"]
  46. });
  47. dataFlowLayer.on('dataupdated', function (result) {
  48. var feature = result.data;
  49. popup.setLatLng(L.GeoJSON.coordsToLatLng(feature.geometry.coordinates))
  50. .setContent(feature.properties.time);
  51. if (!popup.isOpen()) {
  52. popup.addTo(map);
  53. }
  54. })
  55. dataFlowLayer.addTo(map);
  56. //模拟实时数据 start
  57. //查询一个线数据,每两秒将一个点通过dataFlowService广播给iSevrer的dataflow服务
  58. query();
  59. var timer, featureResult, dataFlowBroadcast;
  60. function query() {
  61. var param = new SuperMap.QueryBySQLParameters({
  62. queryParams: {
  63. name: "Main_Road_L@China#1",
  64. attributeFilter: "SMID = 1755"
  65. }
  66. });
  67. L.supermap
  68. .queryService(urlQuery)
  69. .queryBySQL(param, function (serviceResult) {
  70. featureResult = serviceResult;
  71. dataFlowBroadcast = L.supermap.dataFlowService(urlDataFlow).initBroadcast();
  72. dataFlowBroadcast.on('broadcastSocketConnected', function (e) {
  73. timer = window.setInterval("broadcast()", 2000);
  74. })
  75. });
  76. }
  77. var count = 200;
  78. function broadcast() {
  79. if (count >= featureResult.result.recordsets[0].features.features[0].geometry.coordinates.length) {
  80. window.clearInterval(timer);
  81. return;
  82. }
  83. var point = featureResult.result.recordsets[0].features.features[0].geometry.coordinates[count];
  84. var feature = {
  85. geometry: {
  86. coordinates: [point[0], point[1]],
  87. type: "Point"
  88. },
  89. type: "Feature",
  90. properties: {
  91. id: 1,
  92. time: new Date()
  93. }
  94. };
  95. dataFlowBroadcast.broadcast(feature);
  96. count += 3;
  97. }
  98. //模拟实时数据 end
  99. </script>
  100. </body>
  101. </html>