mapVLayerPolylineTime.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_mapvPolylineTime"></title>
  9. <script type="text/javascript" include="jquery" 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" include="mapv" src="../../dist/leaflet/include-leaflet.js"></script>
  14. <script type="text/javascript">
  15. var map = L.map('map', {
  16. center: [30.41, 114.32],
  17. zoom: 11,
  18. });
  19. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  20. var url = host + "/iserver/services/map-china400/rest/maps/ChinaDark";
  21. L.supermap.tiledMapLayer(url).addTo(map);
  22. loadData();
  23. //示例数据来源为百度MapV的加偏数据,iClient未做纠偏处理
  24. function loadData() {
  25. $.get('../data/wuhan-car', function (rs) {
  26. var data = [];
  27. var timeData = [];
  28. rs = rs.split("\n");
  29. var maxLength = 0;
  30. //leaflet只识别经纬度坐标,需要将数据中的米坐标转成经纬度坐标
  31. var projection = L.CRS.EPSG3857.projection;
  32. var ggPoints;
  33. for (var i = 0; i < rs.length; i++) {
  34. var item = rs[i].split(',');
  35. var coordinates = [];
  36. if (item.length > maxLength) {
  37. maxLength = item.length;
  38. }
  39. if (item.length < 2) {
  40. continue;
  41. }
  42. for (j = 0; j < item.length; j += 2) {
  43. //需要将数据中的米坐标转成经纬度坐标
  44. var latLng = projection.unproject(L.point([item[j], item[j + 1]]));
  45. coordinates.push([latLng.lng, latLng.lat]);
  46. timeData.push({
  47. geometry: {
  48. type: 'Point',
  49. coordinates: [latLng.lng, latLng.lat]
  50. },
  51. count: 1,
  52. time: j
  53. });
  54. }
  55. ggPoints = coordinates;
  56. data.push({
  57. geometry: {
  58. type: 'LineString',
  59. coordinates: coordinates
  60. }
  61. });
  62. }
  63. var dataSet1 = new mapv.DataSet(data);
  64. var options1 = {
  65. strokeStyle: 'rgba(53,57,255,0.5)',
  66. shadowColor: 'rgba(53,57,255,0.2)',
  67. shadowBlur: 3,
  68. lineWidth: 3.0,
  69. draw: 'simple'
  70. };
  71. //线图层
  72. var dataAttr = resources.text_dataSources + "<a target='_blank' href='https://mapv.baidu.com/examples/baidu-map-polyline-time.html'> MapV</a> ";
  73. L.supermap.mapVLayer(dataSet1, options1, {attributionPrefix: dataAttr, attribution: ""}).addTo(map);
  74. var dataSet2 = new mapv.DataSet(timeData);
  75. var options2 = {
  76. fillStyle: 'rgba(255, 250, 250, 0.2)',
  77. globalCompositeOperation: "lighter",
  78. size: 1.5,
  79. animation: {
  80. stepsRange: {
  81. start: 0,
  82. end: 100
  83. },
  84. trails: 3,
  85. duration: 5,
  86. },
  87. draw: 'simple'
  88. };
  89. //动态轨迹图层
  90. L.supermap.mapVLayer(dataSet2, options2).addTo(map);
  91. setTimeout(function () {
  92. map.openPopup(resources.text_iClient, map.getCenter());
  93. }, 1000)
  94. });
  95. }
  96. </script>
  97. </body>
  98. </html>