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