components_dataflow_react.html 4.1 KB

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