g10_bim.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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>桥梁(BIM建模) </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,haoutil,turf,mars3d"
  27. ></script>
  28. <link href="css/style.css" rel="stylesheet" />
  29. <style>
  30. /* 设置单个滑轨的样式 */
  31. #oneSlider {
  32. width: 100%;
  33. margin-left: -100px;
  34. }
  35. </style>
  36. </head>
  37. <body class="dark">
  38. <!--加载前进行操作提示,优化用户体验-->
  39. <div id="mask" class="signmask" onclick="removeMask()"></div>
  40. <div id="mars3dContainer" class="mars3d-container"></div>
  41. <!-- 面板 -->
  42. <div class="infoview">
  43. <table class="mars-table">
  44. <tr class="undergroundAttr">
  45. <td>地下模式:</td>
  46. <td>
  47. <div class="checkbox checkbox-primary checkbox-inline">
  48. <input id="chkUnderground" class="styled" type="checkbox" />
  49. <label for="chkUnderground"> 开启/关闭 </label>
  50. </div>
  51. </td>
  52. <td>地表透明度:</td>
  53. <td colspan="2">
  54. <input id="alpha" />
  55. </td>
  56. </tr>
  57. <tr class="undergroundAttr">
  58. <td>地下开挖:</td>
  59. <td>
  60. <div class="checkbox checkbox-primary checkbox-inline">
  61. <input id="chkClippingPlanes" class="styled" type="checkbox" checked />
  62. <label for="chkClippingPlanes"> 是否挖地 </label>
  63. </div>
  64. </td>
  65. <td>开挖深度:</td>
  66. <td><input id="txtHeight" type="number" value="30" min="-500" step="1" max="999" class="form-control" style="width: 100px" />(米)</td>
  67. <td>
  68. <input type="button" class="btn btn-primary" value="矩形" id="btnDrawExtent" />
  69. <input type="button" class="btn btn-primary" value="多边形" id="btnDraw" />
  70. <input type="button" class="btn btn-primary" value="清除" id="clearWJ" />
  71. </td>
  72. </tr>
  73. <tr class="undergroundAttr">
  74. <td>模型裁剪:</td>
  75. <td>裁剪距离:</td>
  76. <td>
  77. <input id="rangeDistance" title="距离" />
  78. </td>
  79. <td colspan="2">
  80. <input type="button" class="btn btn-primary" value="切顶" id="btnClipTop" />
  81. <input type="button" class="btn btn-primary" value="切底" id="btnClipBottom" />
  82. <input type="button" class="btn btn-primary" value="按线切" id="btnClipLine" />
  83. <input type="button" class="btn btn-primary" value="内挖" id="btnClipPoly" />
  84. <input type="button" class="btn btn-primary" value="外切" id="btnClipPoly2" />
  85. <button type="button" id="btnClearClip" class="btn btn-primary">清除</button>
  86. </td>
  87. </tr>
  88. </table>
  89. </div>
  90. <script src="./js/common.js"></script>
  91. <script type="text/javascript">
  92. "use script"; //开发环境建议开启严格模式
  93. var map;
  94. function initMap(options) {
  95. //合并属性参数,可覆盖config.json中的对应配置
  96. var mapOptions = mars3d.Util.merge(options, {
  97. scene: {
  98. center: { lat: 31.8503, lng: 117.101008, alt: 308, heading: 291, pitch: -30 },
  99. baseColor: "rgba(0,0,0.0,0.5)",
  100. globe: {
  101. depthTestAgainstTerrain: true,
  102. },
  103. highDynamicRange: true,
  104. },
  105. });
  106. //创建三维地球场景
  107. map = new mars3d.Map("mars3dContainer", mapOptions);
  108. // 加个模型
  109. var tiles3dLayer = new mars3d.layer.TilesetLayer({
  110. id: 1987,
  111. name: "桥梁",
  112. url: "//data.mars3d.cn/3dtiles/bim-qiaoliang/tileset.json",
  113. maximumScreenSpaceError: 16,
  114. maximumMemoryUsage: 2048,
  115. dynamicScreenSpaceError: true,
  116. cullWithChildrenBounds: false,
  117. luminanceAtZenith: 0.6,
  118. position: { lng: 117.096906, lat: 31.851564, alt: 45 },
  119. rotation: { z: 17.5 },
  120. //高亮时的样式
  121. highlight: {
  122. // all: true, //全部整体高亮,false时是构件高亮
  123. type: mars3d.EventType.click, //默认为鼠标移入高亮,也可以指定click单击高亮
  124. color: "#00FF00",
  125. },
  126. popup: "all",
  127. });
  128. map.addLayer(tiles3dLayer);
  129. // 设置滑动条样式
  130. $("#alpha")
  131. .slider({ id: "oneSlider", min: 0.0, max: 1.0, step: 0.1, value: 0.5 })
  132. .on("change", (e) => {
  133. if (e && e.value) {
  134. underground.alpha = e.value.newValue;
  135. }
  136. });
  137. $("#rangeDistance")
  138. .slider({ min: -50, max: 50, step: 0.1, value: 0 })
  139. .on("change", (e) => {
  140. if (e && e.value) {
  141. tilesetPlanClip.distance = e.value.newValue;
  142. }
  143. });
  144. //单击事件
  145. tiles3dLayer.on(mars3d.EventType.click, function (event) {
  146. console.log("单击了3dtiles图层", event);
  147. });
  148. //模型裁剪
  149. var tilesetPlanClip = new mars3d.thing.TilesetPlanClip({
  150. positions: [
  151. [117.096786, 31.851355, 0],
  152. [117.096834, 31.851464, 0],
  153. [117.09691, 31.851375, 0],
  154. ],
  155. layer: tiles3dLayer,
  156. clipOutSide: false,
  157. edgeColor: Cesium.Color.GREY,
  158. edgeWidth: 2.0,
  159. });
  160. map.addThing(tilesetPlanClip);
  161. //地下模式
  162. var underground = new mars3d.thing.Underground({
  163. alpha: Number($("#alpha").val()),
  164. enabled: $("#chkUnderground").is(":checked"),
  165. });
  166. map.addThing(underground);
  167. $("#chkUnderground").change(function () {
  168. var val = $(this).is(":checked");
  169. underground.enabled = val;
  170. });
  171. // 挖地区域
  172. var terrainClip = new mars3d.thing.TerrainClip({
  173. positions: [
  174. [117.096176, 31.851189, 42.56],
  175. [117.097776, 31.851189, 42.56],
  176. [117.097776, 31.853494, 42.56],
  177. [117.096176, 31.853494, 42.56],
  178. ],
  179. diffHeight: Number($("#txtHeight").val()), //高度
  180. image: "./img/textures/excavate_side_min.jpg",
  181. imageBottom: "./img/textures/excavate_bottom_min.jpg",
  182. splitNum: 80, //井边界插值数
  183. });
  184. map.addThing(terrainClip);
  185. var terrainPlanClip = new mars3d.thing.TerrainPlanClip({
  186. positions: [
  187. [117.096176, 31.851189, 42.56],
  188. [117.097776, 31.851189, 42.56],
  189. [117.097776, 31.853494, 42.56],
  190. [117.096176, 31.853494, 42.56],
  191. ],
  192. });
  193. map.addThing(terrainPlanClip);
  194. $("#chkTestTerrain").change(function () {
  195. var val = $(this).is(":checked");
  196. map.scene.globe.depthTestAgainstTerrain = val;
  197. });
  198. $("#chkClippingPlanes").change(function () {
  199. var val = $(this).is(":checked");
  200. terrainClip.enabled = val;
  201. terrainPlanClip.enabled = val;
  202. });
  203. $("#txtHeight").change(function () {
  204. var num = Number($(this).val());
  205. terrainClip.height = num;
  206. });
  207. $("#clearWJ").click(function () {
  208. terrainClip.clear(); //清除挖地区域
  209. terrainPlanClip.clear();
  210. });
  211. $("#btnDraw").click(function () {
  212. terrainClip.clear(); //清除挖地区域
  213. terrainPlanClip.clear();
  214. map.graphicLayer.startDraw({
  215. type: "polygon",
  216. style: {
  217. color: "#007be6",
  218. opacity: 0.5,
  219. clampToGround: true,
  220. },
  221. success: function (graphic) {
  222. //绘制成功后回调
  223. var positions = graphic.positionsShow;
  224. map.graphicLayer.clear();
  225. console.log(JSON.stringify(mars3d.PointTrans.cartesians2lonlats(positions))); //打印下边界
  226. //挖地区域
  227. terrainClip.positions = positions;
  228. terrainPlanClip.positions = positions;
  229. },
  230. });
  231. });
  232. $("#btnDrawExtent").click(function () {
  233. terrainClip.clear(); //清除挖地区域
  234. terrainPlanClip.clear();
  235. map.graphicLayer.startDraw({
  236. type: "rectangle",
  237. style: {
  238. color: "#007be6",
  239. opacity: 0.8,
  240. outline: false,
  241. },
  242. success: function (graphic) {
  243. //绘制成功后回调
  244. var positions = graphic.getOutlinePositions(false);
  245. map.graphicLayer.clear();
  246. console.log(JSON.stringify(mars3d.PointTrans.cartesians2lonlats(positions))); //打印下边界
  247. //挖地区域
  248. terrainClip.positions = positions;
  249. terrainPlanClip.positions = positions;
  250. },
  251. });
  252. });
  253. $("#btnClearClip").click(function () {
  254. tilesetPlanClip.clear();
  255. });
  256. $("#btnClipTop").click(function () {
  257. tilesetPlanClip.type = mars3d.thing.TilesetPlanClip.Type.ZR;
  258. });
  259. $("#btnClipBottom").click(function () {
  260. tilesetPlanClip.type = mars3d.thing.TilesetPlanClip.Type.Z;
  261. });
  262. $("#btnClipPoly").click(function () {
  263. tilesetPlanClip.clear();
  264. map.graphicLayer.startDraw({
  265. type: "polygon",
  266. style: {
  267. color: "#007be6",
  268. opacity: 0.5,
  269. },
  270. success: function (graphic) {
  271. //绘制成功后回调
  272. var positions = graphic.positionsShow;
  273. map.graphicLayer.clear();
  274. console.log(JSON.stringify(mars3d.PointTrans.cartesians2lonlats(positions))); //打印下边界
  275. tilesetPlanClip.positions = positions;
  276. },
  277. });
  278. });
  279. $("#btnClipPoly2").click(function () {
  280. tilesetPlanClip.clear();
  281. map.graphicLayer.startDraw({
  282. type: "polygon",
  283. style: {
  284. color: "#007be6",
  285. opacity: 0.5,
  286. clampToGround: true,
  287. },
  288. success: function (graphic) {
  289. //绘制成功后回调
  290. var positions = graphic.positionsShow;
  291. map.graphicLayer.clear();
  292. tilesetPlanClip.clipOutSide = true;
  293. tilesetPlanClip.positions = positions;
  294. },
  295. });
  296. });
  297. $("#btnClipLine").click(function () {
  298. tilesetPlanClip.clear();
  299. map.graphicLayer.startDraw({
  300. type: "polyline",
  301. maxPointNum: 2,
  302. style: {
  303. color: "#007be6",
  304. opacity: 0.8,
  305. outline: false,
  306. },
  307. success: function (graphic) {
  308. //绘制成功后回调
  309. var positions = graphic.positionsShow;
  310. map.graphicLayer.clear();
  311. tilesetPlanClip.positions = positions;
  312. },
  313. });
  314. });
  315. }
  316. </script>
  317. </body>
  318. </html>