components_dataflow_vue.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_componentsDataFlow_Vue"></title>
  9. <script type="text/javascript" include="vue" src="../js/include-web.js"></script>
  10. <script
  11. include="iclient-mapboxgl-vue,mapbox-gl-enhance"
  12. src="../../dist/mapboxgl/include-mapboxgl.js"
  13. ></script>
  14. <style>
  15. #main {
  16. margin: 0 auto;
  17. width: 100%;
  18. height: 100%;
  19. }
  20. </style>
  21. </head>
  22. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  23. <div id="main">
  24. <sm-web-map :map-options="mapOptions">
  25. <sm-data-flow-layer
  26. :service-url="dataFlowUrl"
  27. :layer-style="layerStyle"
  28. ></sm-data-flow-layer>
  29. </sm-web-map>
  30. </div>
  31. <script>
  32. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  33. var wsHost = "wss:\//" + (window.isLocal ? document.location.hostname + ":8800" : "iclsvrws.supermap.io");
  34. var attribution =
  35. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  36. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  37. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  38. SuperMap.SecurityManager.registerToken(
  39. "wss://iclsvrws.supermap.io/iserver/services/dataflowTest/dataflow",
  40. window.exampleToken
  41. );
  42. // 模拟 dataflow 实时数据
  43. var featureResult, dataFlowBroadcast, timer;
  44. function broadcast() {
  45. var features = [];
  46. for (var index = 0; index < featureResult.length; index++) {
  47. var count = parseInt(Math.random() * featureResult.length);
  48. var geometry = featureResult[count].geometry;
  49. var feature = {
  50. geometry: geometry,
  51. type: "Feature",
  52. properties: { id: index + 1, time: new Date() }
  53. };
  54. features.push(feature);
  55. }
  56. dataFlowBroadcast.broadcast(features);
  57. }
  58. function query() {
  59. var param = new SuperMap.QueryBySQLParameters({
  60. queryParams: { name: "Capitals@World#3", attributeFilter: "SMID > 0" }
  61. });
  62. var queryService = new mapboxgl.supermap.QueryService(
  63. host + "/iserver/services/map-world/rest/maps/World"
  64. ).queryBySQL(param, function(serviceResult) {
  65. featureResult = serviceResult.result && serviceResult.result.recordsets[0].features.features;
  66. dataFlowBroadcast = new mapboxgl.supermap.DataFlowService(
  67. wsHost + "/iserver/services/dataflowTest/dataflow"
  68. ).initBroadcast();
  69. dataFlowBroadcast.on("broadcastSocketConnected", function(e) {
  70. timer = window.setInterval(broadcast, 2000);
  71. });
  72. });
  73. }
  74. query();
  75. new Vue({
  76. el: "#main",
  77. data() {
  78. return {
  79. dataFlowUrl: wsHost + "/iserver/services/dataflowTest/dataflow",
  80. layerStyle: {
  81. circle: new SuperMap.Components.commontypes.CircleStyle({
  82. "circle-color": "#3fb1e3",
  83. "circle-radius": 6
  84. })
  85. },
  86. mapOptions: {
  87. container: "map",
  88. style: {
  89. version: 8,
  90. sources: {
  91. "raster-tiles": {
  92. attribution: attribution,
  93. type: "raster",
  94. tiles: [
  95. host +
  96. "/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}"
  97. ],
  98. tileSize: 256
  99. }
  100. },
  101. layers: [
  102. {
  103. id: "simple-tiles",
  104. type: "raster",
  105. source: "raster-tiles",
  106. minzoom: 0,
  107. maxzoom: 22
  108. }
  109. ]
  110. },
  111. center: [120.143, 30.236],
  112. zoom: 0
  113. }
  114. };
  115. }
  116. });
  117. </script>
  118. </body>
  119. </html>