k10_sightline_terrain.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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,font-awesome,bootstrap,bootstrap-checkbox,bootstrap-slider,layer,toastr,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. <!-- 面板 -->
  35. <div class="infoview">
  36. <table class="mars-table">
  37. <tr>
  38. <td class="nametd">轨迹方向(heading)</td>
  39. <td>
  40. <input id="model_heading" title="方向heading" />
  41. </td>
  42. <td>
  43. <input id="model_heading_2" readonly="readonly" type="number" min="0" max="360" step="0.01" value="220" title="方向heading" />
  44. </td>
  45. </tr>
  46. <tr>
  47. <td class="nametd">前后侧摆(pitch)</td>
  48. <td>
  49. <input id="model_pitch" title="前后侧摆pitch" />
  50. </td>
  51. <td>
  52. <input id="model_pitch_2" readonly="readonly" type="number" min="-180" max="180" step="0.01" value="75" title="前后侧摆pitch" />
  53. </td>
  54. </tr>
  55. <tr>
  56. <td class="nametd">左右侧摆(roll)</td>
  57. <td>
  58. <input id="model_roll" title="左右侧摆roll" />
  59. </td>
  60. <td>
  61. <input id="model_roll_2" readonly="readonly" type="number" min="-180" max="180" step="0.01" value="0" title="左右侧摆roll" />
  62. </td>
  63. </tr>
  64. <tr class="coneEntityAttr">
  65. <td colspan="2">
  66. <button id="btnSePoint" class="btn btn-primary">设置摄像头位置</button>
  67. <button id="btnGetCenter" class="btn btn-primary">计算与地面交点</button>
  68. </td>
  69. <td>
  70. <div class="checkbox checkbox-primary checkbox-inline">
  71. <input id="chkTestTerrain" class="styled" type="checkbox" />
  72. <label for="chkTestTerrain"> 深度检测 </label>
  73. </div>
  74. </td>
  75. </tr>
  76. </table>
  77. </div>
  78. <script src="./js/common.js"></script>
  79. <script type="text/javascript">
  80. "use script"; //开发环境建议开启严格模式
  81. var map;
  82. var sightline;
  83. var positionSXT;
  84. var positionDM;
  85. var positionJD; //与地面的交点
  86. function initMap(options) {
  87. //合并属性参数,可覆盖config.json中的对应配置
  88. var mapOptions = mars3d.Util.merge(options, {
  89. scene: {
  90. //此处参数会覆盖config.json中的对应配置
  91. center: { lat: 30.841574, lng: 116.18792, alt: 6828, heading: 215, pitch: -28 },
  92. },
  93. });
  94. //创建三维地球场景
  95. map = new mars3d.Map("mars3dContainer", mapOptions);
  96. sightline = new mars3d.thing.Sightline();
  97. map.addThing(sightline);
  98. sightline.on(mars3d.EventType.end, function (e) {
  99. positionJD = e.position;
  100. });
  101. //测试数据
  102. positionSXT = Cesium.Cartesian3.fromDegrees(116.144409, 30.744228, 1045);
  103. var graphicSXT = new mars3d.graphic.PointEntity({
  104. position: positionSXT,
  105. style: {
  106. color: "#ffff00",
  107. pixelSize: 8,
  108. label: {
  109. text: "摄像头",
  110. font_size: 20,
  111. color: "#ffffff",
  112. outline: true,
  113. outlineColor: "#000000",
  114. pixelOffsetY: -20,
  115. },
  116. },
  117. });
  118. map.graphicLayer.addGraphic(graphicSXT);
  119. updateModel();
  120. //滑动条
  121. $("#model_heading")
  122. .slider({ min: 0, max: 360, step: 0.01, value: 220 })
  123. .on("change", (e) => {
  124. if (e?.value) {
  125. $("#model_heading_2").val(e.value.newValue);
  126. updateModel();
  127. }
  128. });
  129. $("#model_heading_2").change(function () {
  130. var value = Number($(this).val());
  131. $("#model_heading").slider("setValue", value);
  132. updateModel();
  133. });
  134. $("#model_pitch")
  135. .slider({ min: -180, max: 180, step: 0.01, value: 75 })
  136. .on("change", (e) => {
  137. if (e?.value) {
  138. $("#model_pitch_2").val(e.value.newValue);
  139. updateModel();
  140. }
  141. });
  142. $("#model_pitch_2").change(function () {
  143. var value = Number($(this).val());
  144. $("#model_pitch").slider("setValue", value);
  145. updateModel();
  146. });
  147. $("#model_roll")
  148. .slider({ min: -180, max: 180, step: 0.01, value: 0 })
  149. .on("change", (e) => {
  150. if (e?.value) {
  151. $("#model_roll_2").val(e.value.newValue);
  152. updateModel();
  153. }
  154. });
  155. $("#model_roll_2").change(function () {
  156. var value = Number($(this).val());
  157. $("#model_roll").slider("setValue", value);
  158. updateModel();
  159. });
  160. $("#chkTestTerrain").change(function () {
  161. var val = $(this).is(":checked");
  162. map.scene.globe.depthTestAgainstTerrain = val;
  163. if (val) {
  164. haoutil.msg("深度监测打开后,您将无法看到地下或被地形遮挡的对象。");
  165. }
  166. });
  167. //创建矢量数据图层
  168. var graphicLayer = new mars3d.layer.GraphicLayer();
  169. map.addLayer(graphicLayer);
  170. //地面点
  171. var graphic = new mars3d.graphic.PointEntity({
  172. position: new Cesium.CallbackProperty(function (time) {
  173. return positionDM;
  174. }, false),
  175. style: {
  176. color: "#0000ff",
  177. pixelSize: 7,
  178. outlineColor: "#ffffff",
  179. outlineWidth: 2,
  180. label: {
  181. text: "目标参考点",
  182. font_size: 18,
  183. color: "#ffffff",
  184. pixelOffsetY: -10,
  185. distanceDisplayCondition: true,
  186. distanceDisplayCondition_far: 500000,
  187. distanceDisplayCondition_near: 0,
  188. },
  189. },
  190. });
  191. graphicLayer.addGraphic(graphic);
  192. var graphicJD = new mars3d.graphic.PointEntity({
  193. position: new Cesium.CallbackProperty(function (time) {
  194. return positionJD;
  195. }, false),
  196. style: {
  197. color: "#00ff00",
  198. pixelSize: 8,
  199. outlineColor: "#ffffff",
  200. outlineWidth: 2,
  201. },
  202. });
  203. graphicJD.bindTooltip("与地形地面的交点");
  204. graphicLayer.addGraphic(graphicJD);
  205. //摄像头朝向的地面点连线
  206. let graphicLine = new mars3d.graphic.PolylineEntity({
  207. positions: new Cesium.CallbackProperty(function (time) {
  208. if (!positionSXT || !positionDM || positionJD != null) {
  209. return [];
  210. }
  211. return [positionSXT, positionDM];
  212. }, false),
  213. style: {
  214. width: 2,
  215. arcType: Cesium.ArcType.NONE,
  216. color: "#ffff00",
  217. },
  218. });
  219. graphicLayer.addGraphic(graphicLine);
  220. $("#btnSePoint").click(function (e) {
  221. map.graphicLayer.clear();
  222. map.graphicLayer.startDraw({
  223. type: "point",
  224. style: {
  225. pixelSize: 8,
  226. color: "#ffff00",
  227. label: {
  228. text: "摄像头",
  229. font_size: 20,
  230. color: "#ffffff",
  231. outline: true,
  232. outlineColor: "#000000",
  233. pixelOffsetY: -20,
  234. },
  235. },
  236. success: function (graphic) {
  237. positionSXT = graphic.positionShow;
  238. positionSXT = mars3d.PointUtil.addPositionsHeight(positionSXT, 5.0); //增加杆子高度
  239. updateModel();
  240. },
  241. });
  242. });
  243. $("#btnGetCenter").click(function () {
  244. if (!positionSXT || !positionDM) {
  245. return [];
  246. }
  247. sightline.clear();
  248. sightline.addAsync(positionSXT, positionDM);
  249. });
  250. }
  251. function updateModel() {
  252. if (!positionSXT) {
  253. return;
  254. }
  255. var heading = Cesium.Math.toRadians(Number($("#model_heading").val()));
  256. var pitch = Cesium.Math.toRadians(Number($("#model_pitch").val()));
  257. var roll = Cesium.Math.toRadians(Number($("#model_roll").val()));
  258. var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
  259. positionDM = mars3d.PointUtil.getRayEarthPosition(positionSXT, hpr, true, map.scene.globe.ellipsoid);
  260. if (!positionDM) {
  261. //与地面无交点时
  262. positionDM = mars3d.PointUtil.getPositionByHprAndLen(positionSXT, hpr, 5000);
  263. }
  264. sightline.clear();
  265. positionJD = null;
  266. }
  267. </script>
  268. </body>
  269. </html>