components_mapv_vue.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_componentsMapV_Vue"></title>
  9. <script type="text/javascript" include="vue,jquery" src="../js/include-web.js"></script>
  10. <script
  11. include="iclient-mapboxgl-vue,mapbox-gl-enhance,proj4,mapv"
  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" @load="addPopup">
  25. <sm-mapv-layer :data="lineDataSet" :options="lineMapvOptions"></sm-mapv-layer>
  26. <sm-mapv-layer :data="ponitDataSet" :options="pointMapvOptions"></sm-mapv-layer>
  27. </sm-web-map>
  28. </div>
  29. <script>
  30. $.get('../data/wuhan-car', function(rs) {
  31. // 构造数据
  32. var data = [];
  33. var timeData = [];
  34. rs = rs.split('\n');
  35. var maxLength = 0;
  36. for (var i = 0; i < rs.length; i++) {
  37. var item = rs[i].split(',');
  38. var coordinates = [];
  39. if (item.length > maxLength) {
  40. maxLength = item.length;
  41. }
  42. for (j = 0; j < item.length; j += 2) {
  43. if (item.length === 1) {
  44. continue;
  45. }
  46. coordinates.push(proj4('EPSG:3857', 'EPSG:4326', [parseInt(item[j]), parseInt(item[j + 1])]));
  47. timeData.push({
  48. geometry: {
  49. type: 'Point',
  50. coordinates: proj4('EPSG:3857', 'EPSG:4326', [
  51. parseInt(item[j]),
  52. parseInt(item[j + 1]),
  53. ]),
  54. },
  55. count: 1,
  56. time: j,
  57. });
  58. }
  59. data.push({
  60. geometry: {
  61. type: 'LineString',
  62. coordinates: coordinates,
  63. },
  64. });
  65. }
  66. // 构造 dataset 和 mapvOptions
  67. var lineDataSet = new mapv.DataSet(data);
  68. var lineMapvOptions = {
  69. strokeStyle: 'rgba(53,57,255,0.5)',
  70. coordType: 'bd09mc',
  71. shadowColor: 'rgba(53,57,255,0.2)',
  72. shadowBlur: 3,
  73. lineWidth: 3.0,
  74. draw: 'simple',
  75. };
  76. var ponitDataSet = new mapv.DataSet(timeData);
  77. var pointMapvOptions = {
  78. fillStyle: 'rgba(255, 250, 250, 0.2)',
  79. coordType: 'bd09mc',
  80. globalCompositeOperation: 'lighter',
  81. size: 1.5,
  82. animation: {
  83. stepsRange: {
  84. start: 0,
  85. end: 100,
  86. },
  87. trails: 3,
  88. duration: 5,
  89. },
  90. draw: 'simple',
  91. };
  92. new Vue({
  93. el: '#main',
  94. data() {
  95. var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
  96. var attribution =
  97. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  98. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  99. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  100. return {
  101. lineDataSet: lineDataSet,
  102. lineMapvOptions: lineMapvOptions,
  103. ponitDataSet: ponitDataSet,
  104. pointMapvOptions: pointMapvOptions,
  105. mapOptions: {
  106. container: 'map', // container id
  107. style: {
  108. version: 8,
  109. sources: {
  110. 'raster-tiles': {
  111. attribution: attribution,
  112. type: 'raster',
  113. tiles: [
  114. host +
  115. '/iserver/services/map-china400/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}',
  116. ],
  117. tileSize: 256,
  118. },
  119. },
  120. layers: [
  121. {
  122. id: 'simple-tiles',
  123. type: 'raster',
  124. source: 'raster-tiles',
  125. minzoom: 0,
  126. maxzoom: 22,
  127. },
  128. ],
  129. },
  130. center: [114.321317, 30.398428],
  131. zoom: 10,
  132. },
  133. };
  134. },
  135. methods: {
  136. addPopup(e) {
  137. var map = e.map;
  138. new mapboxgl.Popup({ closeOnClick: false })
  139. .setLngLat(map.getCenter())
  140. .setHTML(resources.text_iClient)
  141. .addTo(map);
  142. },
  143. },
  144. });
  145. });
  146. </script>
  147. </body>
  148. </html>