f20_primitive_frustum.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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>Frustum 四棱锥体 </title>
  21. <!--第三方lib-->
  22. <script
  23. type="text/javascript"
  24. src="../lib/include-lib.js"
  25. libpath="../lib/"
  26. include="jquery,font-awesome,bootstrap,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. <!-- 面板 -->
  35. <div class="infoview">
  36. <input id="btnSelPoint" type="button" class="btn btn-primary" value="追踪目标点" />
  37. <!-- <button id="btnGetRegion" class="btn btn-primary">获取区域边界值</button>
  38. <button id="btnGetCenter" class="btn btn-primary">获取中心点坐标</button>
  39. <button id="btnRemoveAll" class="btn btn-primary">清除</button> -->
  40. </div>
  41. <!-- 图层管理相关处理js -->
  42. <script type="text/javascript" src="./js/graphicManager.js"></script>
  43. <script src="./js/common.js"></script>
  44. <script type="text/javascript">
  45. "use script"; //开发环境建议开启严格模式
  46. var map;
  47. function initMap(options) {
  48. //合并属性参数,可覆盖config.json中的对应配置
  49. var mapOptions = mars3d.Util.merge(options, {
  50. scene: {
  51. center: { lat: 30.808451, lng: 116.295952, alt: 15993, heading: 2, pitch: -29 },
  52. },
  53. });
  54. //创建三维地球场景
  55. map = new mars3d.Map("mars3dContainer", mapOptions);
  56. //创建矢量数据图层
  57. var graphicLayer = new mars3d.layer.GraphicLayer();
  58. map.addLayer(graphicLayer);
  59. //图层管理的相关处理,代码在\js\graphicManager.js
  60. initLayerManager(graphicLayer);
  61. //加一些演示数据
  62. addGraphic_01(graphicLayer);
  63. addGraphic_02(graphicLayer);
  64. addGraphic_03(graphicLayer);
  65. }
  66. function addGraphic_01(graphicLayer) {
  67. let position = [116.359147, 30.990366, 6000];
  68. //加个飞机
  69. var graphicFJ = new mars3d.graphic.ModelPrimitive({
  70. position: position,
  71. style: {
  72. url: "//data.mars3d.cn/gltf/mars/feiji.glb",
  73. scale: 1,
  74. minimumPixelSize: 50,
  75. heading: 150,
  76. },
  77. });
  78. graphicLayer.addGraphic(graphicFJ);
  79. //四凌锥追踪体
  80. var graphicFrustum = new mars3d.graphic.FrustumPrimitive({
  81. position: position,
  82. targetPosition: [116.317411, 30.972581, 1439.7], //可选
  83. style: {
  84. angle: 10,
  85. // length: 4000, //targetPosition存在时无需传
  86. color: "#02ff00",
  87. opacity: 0.4,
  88. outline: true,
  89. outlineColor: "#ffffff",
  90. outlineOpacity: 1.0,
  91. },
  92. asynchronous: false,
  93. });
  94. graphicLayer.addGraphic(graphicFrustum);
  95. $("#btnSelPoint").click(function () {
  96. map.graphicLayer.startDraw({
  97. type: "point",
  98. style: {
  99. pixelSize: 8,
  100. color: "#ffff00",
  101. },
  102. success: function (graphic) {
  103. var position = graphic.positionShow;
  104. map.graphicLayer.clear();
  105. graphicFrustum.targetPosition = position;
  106. },
  107. });
  108. });
  109. $("#btnGetRegion").click(function () {
  110. var coords = graphicFrustum.getRayEarthPositions();
  111. //显示边界点
  112. map.graphicLayer.clear();
  113. coords.forEach(function (item) {
  114. var primitive = new mars3d.graphic.PointPrimitive({
  115. position: item,
  116. style: {
  117. color: "#ff0000",
  118. pixelSize: 8,
  119. outline: true,
  120. outlineColor: "#ffffff",
  121. outlineWidth: 2,
  122. clampToGround: true,
  123. },
  124. });
  125. map.graphicLayer.addGraphic(primitive);
  126. });
  127. });
  128. $("#btnGetCenter").click(function () {
  129. map.graphicLayer.clear();
  130. var groundPosition = graphicFrustum.groundPosition;
  131. if (!groundPosition) {
  132. haoutil.alert("当前与地球无交点");
  133. return;
  134. }
  135. var primitive = new mars3d.graphic.PointPrimitive({
  136. position: groundPosition,
  137. style: {
  138. color: "#ff0000",
  139. pixelSize: 8,
  140. outline: true,
  141. outlineColor: "#ffffff",
  142. outlineWidth: 2,
  143. clampToGround: true,
  144. },
  145. });
  146. map.graphicLayer.addGraphic(primitive);
  147. });
  148. $("#btnRemoveAll").click(function () {
  149. map.graphicLayer.clear();
  150. });
  151. }
  152. function addGraphic_02(graphicLayer) {
  153. var graphic = new mars3d.graphic.FrustumPrimitive({
  154. position: [116.25813, 30.983059, 5000],
  155. style: {
  156. angle: 7,
  157. length: 4000,
  158. color: "#FF0000",
  159. opacity: 0.4,
  160. outline: true,
  161. outlineColor: "#ffffff",
  162. outlineOpacity: 1.0,
  163. label: { text: "鼠标移入会高亮", pixelOffsetY: -30 },
  164. //高亮时的样式(默认为鼠标移入,也可以指定type:'click'单击高亮),构造后也可以openHighlight、closeHighlight方法来手动调用
  165. highlight: {
  166. opacity: 0.8,
  167. },
  168. },
  169. asynchronous: false,
  170. });
  171. graphicLayer.addGraphic(graphic);
  172. }
  173. function addGraphic_03(graphicLayer) {
  174. //加个卫星
  175. var graphicFJ = new mars3d.graphic.ModelPrimitive({
  176. position: [116.303349, 31.070789, 7000],
  177. style: {
  178. url: "//data.mars3d.cn/gltf/mars/weixin.gltf",
  179. scale: 1,
  180. minimumPixelSize: 50,
  181. heading: 70,
  182. },
  183. });
  184. graphicLayer.addGraphic(graphicFJ);
  185. var graphic = new mars3d.graphic.FrustumPrimitive({
  186. position: [116.303349, 31.070789, 7000],
  187. style: {
  188. angle: 10,
  189. angle2: 0.01,
  190. length: 7000,
  191. heading: 70,
  192. color: "#00ffff",
  193. opacity: 0.7,
  194. },
  195. asynchronous: false,
  196. });
  197. graphicLayer.addGraphic(graphic);
  198. }
  199. </script>
  200. </body>
  201. </html>