f45_flypath.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  6. <meta name="author" content="火星科技 http://mars3d.cn " />
  7. <meta name="apple-touch-fullscreen" content="yes" />
  8. <meta name="apple-mobile-web-app-capable" content="yes" />
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  10. <meta name="format-detection" content="telephone=no" />
  11. <meta name="x5-fullscreen" content="true" />
  12. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  13. <!-- 标题及搜索关键字 -->
  14. <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  15. <meta
  16. name="description"
  17. content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型 gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包 地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
  18. />
  19. <link rel="shortcut icon" type="image/x-icon" href="" />
  20. <title>动态轨迹路线 </title>
  21. <!--第三方lib-->
  22. <script
  23. type="text/javascript"
  24. src="../lib/include-lib.js"
  25. libpath="../lib/"
  26. include="jquery,jquery.range,font-awesome,bootstrap,bootstrap-checkbox,layer,haoutil,turf,mars3d"
  27. ></script>
  28. <link href="css/style.css" rel="stylesheet" />
  29. </head>
  30. <body class="dark">
  31. <!--加载前进行操作提示,优化用户体验-->
  32. <div id="mask" class="signmask" onclick="removeMask()"></div>
  33. <div id="mars3dContainer" class="mars3d-container"></div>
  34. <div class="infoview" id="toolbar">
  35. <input id="viewAircraft" type="button" class="btn btn-primary" value="跟踪视角" />
  36. <input id="viewTopDown" type="button" class="btn btn-primary" value="上方视角" />
  37. <input id="viewSide" type="button" class="btn btn-primary" value="侧方视角" />
  38. </div>
  39. <script src="./js/common.js"></script>
  40. <script type="text/javascript">
  41. "use script"; //开发环境建议开启严格模式
  42. var map;
  43. var graphicLayer;
  44. var pathEntity = null;
  45. function initMap(options) {
  46. //合并属性参数,可覆盖config.json中的对应配置
  47. var mapOptions = mars3d.Util.merge(options, {
  48. scene: {
  49. center: { lat: 32.550222, lng: 117.366824, alt: 2696, heading: 273, pitch: -67 },
  50. },
  51. control: {
  52. animation: true, //是否创建动画小器件,左下角仪表
  53. timeline: true, //是否显示时间线控件
  54. },
  55. });
  56. //创建三维地球场景
  57. map = new mars3d.Map("mars3dContainer", mapOptions);
  58. //创建矢量数据图层
  59. graphicLayer = new mars3d.layer.GraphicLayer();
  60. map.addLayer(graphicLayer);
  61. queryFlyPathApiData().then(function (res) {
  62. initPath(res);
  63. });
  64. //添加事件
  65. $("#viewAircraft").on("click", function () {
  66. map.trackedEntity = pathEntity.entity;
  67. pathEntity.flyToPoint({
  68. radius: 500, //距离目标点的距离
  69. heading: 40,
  70. pitch: -50,
  71. duration: 0.01,
  72. });
  73. });
  74. $("#viewTopDown").on("click", function () {
  75. map.trackedEntity = undefined;
  76. map.flyToPoint(pathEntity.positionShow, {
  77. radius: 2000,
  78. heading: -90,
  79. pitch: -89,
  80. });
  81. });
  82. $("#viewSide").on("click", function () {
  83. map.trackedEntity = undefined;
  84. map.flyToPoint(pathEntity.positionShow, {
  85. radius: 3000,
  86. heading: -90,
  87. pitch: -25,
  88. });
  89. });
  90. }
  91. // 访问后端接口,取数据
  92. function queryFlyPathApiData() {
  93. return new Promise(function (resolve, reject) {
  94. $.ajax({
  95. url: "//data.mars3d.cn/file/apidemo/flypath.json",
  96. type: "get",
  97. dataType: "json",
  98. success: function (result) {
  99. console.log(result);
  100. resolve(result);
  101. },
  102. error: function (data) {
  103. reject(data);
  104. },
  105. });
  106. });
  107. }
  108. function initPath(data) {
  109. var property = new Cesium.SampledPositionProperty();
  110. var start;
  111. var stop;
  112. for (var i = 0, len = data.length; i < len; i++) {
  113. var item = data[i];
  114. var lng = Number(item.x.toFixed(6)); //经度
  115. var lat = Number(item.y.toFixed(6)); //纬度
  116. var height = item.z; //高度
  117. var time = item.time; //时间
  118. var position = null;
  119. if (lng && lat) {
  120. position = Cesium.Cartesian3.fromDegrees(lng, lat, height);
  121. }
  122. var juliaDate = null;
  123. if (time) {
  124. juliaDate = Cesium.JulianDate.fromIso8601(time);
  125. }
  126. if (position && juliaDate) {
  127. property.addSample(juliaDate, position);
  128. }
  129. if (i == 0) {
  130. start = juliaDate;
  131. } else if (i == len - 1) {
  132. stop = juliaDate;
  133. }
  134. var primitive = new mars3d.graphic.PointPrimitive({
  135. position: position,
  136. style: {
  137. pixelSize: 4,
  138. color: "#cccccc",
  139. },
  140. popup: "编号:" + item.id + "<br/>时间:" + time,
  141. });
  142. graphicLayer.addGraphic(primitive);
  143. }
  144. //设置时钟属性
  145. map.clock.startTime = start.clone();
  146. map.clock.stopTime = stop.clone();
  147. map.clock.currentTime = start.clone();
  148. map.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
  149. map.clock.multiplier = 5;
  150. if (map.viewer.timeline) {
  151. map.viewer.timeline.zoomTo(start, stop);
  152. }
  153. //创建path对象
  154. pathEntity = new mars3d.graphic.PathEntity({
  155. position: property,
  156. orientation: new Cesium.VelocityOrientationProperty(property),
  157. style: {
  158. resolution: 1,
  159. leadTime: 0,
  160. trailTime: 3600,
  161. color: "#ff0000",
  162. width: 3,
  163. },
  164. label: {
  165. text: "飞机1号",
  166. font_size: 19,
  167. font_family: "楷体",
  168. color: Cesium.Color.AZURE,
  169. outline: true,
  170. outlineColor: Cesium.Color.BLACK,
  171. outlineWidth: 2,
  172. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  173. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  174. pixelOffset: new Cesium.Cartesian2(10, -25), //偏移量
  175. },
  176. model: {
  177. url: "//data.mars3d.cn/gltf/mars/wrj.glb",
  178. scale: 0.1,
  179. minimumPixelSize: 20,
  180. },
  181. popup: "飞行1号",
  182. });
  183. graphicLayer.addGraphic(pathEntity);
  184. //圆锥追踪体
  185. var coneTrack = new mars3d.graphic.ConeTrack({
  186. position: property,
  187. style: {
  188. length: 100,
  189. angle: 12, //半场角度
  190. color: "#ff0000",
  191. opacity: 0.5,
  192. },
  193. });
  194. graphicLayer.addGraphic(coneTrack);
  195. }
  196. </script>
  197. </body>
  198. </html>