k15_contourLine.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <!-- 2017-12-7 14:56:03 | 修改 木遥(微信: http://marsgis.cn/weixin.html ) -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  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. <script
  22. type="text/javascript"
  23. src="../lib/include-lib.js"
  24. libpath="../lib/"
  25. include="jquery,jquery.minicolors,font-awesome,bootstrap,bootstrap-checkbox,bootstrap-slider,layer,haoutil,turf,mars3d"
  26. ></script>
  27. <link href="css/style.css" rel="stylesheet" />
  28. <style>
  29. .flatTable {
  30. border: 1px solid rgba(255, 255, 255, 0.5);
  31. }
  32. .flatTable tr td,
  33. th {
  34. border: 1px solid rgba(255, 255, 255, 0.5);
  35. text-align: center;
  36. }
  37. </style>
  38. </head>
  39. <body class="dark">
  40. <!--加载前进行操作提示,优化用户体验-->
  41. <div id="mask" class="signmask" onclick="removeMask()"></div>
  42. <div id="mars3dContainer" class="mars3d-container"></div>
  43. <div id="toolbar" class="infoview">
  44. <table class="mars-table">
  45. <tr>
  46. <td>限定区域</td>
  47. <td colspan="3">
  48. <input type="button" class="btn btn-primary" value="添加矩形" id="btnDrawExtent" />
  49. <input type="button" class="btn btn-primary" value="添加多边形" id="btnDraw" />
  50. <input type="button" class="btn btn-primary" value="清除" id="clearWJ" />
  51. </td>
  52. </tr>
  53. <tr>
  54. <td>等高线:</td>
  55. <td>
  56. <div class="checkbox checkbox-primary checkbox-inline">
  57. <input id="chkEnabled" class="styled" type="checkbox" checked />
  58. <label for="chkEnabled"> 显示 </label>
  59. </div>
  60. </td>
  61. <td colspan="2">
  62. <input type="text" id="txtColor" class="form-control" style="width: 100px" value="#FF0000" />
  63. </td>
  64. </tr>
  65. <tr>
  66. <td></td>
  67. <td>间隔</td>
  68. <td>
  69. <input id="txtSpacing" style="width: 136px" />
  70. </td>
  71. <td>米</td>
  72. </tr>
  73. <tr>
  74. <td></td>
  75. <td>线宽</td>
  76. <td>
  77. <input id="txtWidth" style="width: 125px" />
  78. </td>
  79. <td>px</td>
  80. </tr>
  81. <tr>
  82. <td>地表渲染:</td>
  83. <td colspan="3">
  84. <div class="radio radio-info radio-inline">
  85. <input type="radio" id="shadingMaterials1" name="shadingMaterials" value="none" checked />
  86. <label for="shadingMaterials1">无阴影 </label>
  87. </div>
  88. <div class="radio radio-info radio-inline">
  89. <input type="radio" id="shadingMaterials2" name="shadingMaterials" value="elevation" />
  90. <label for="shadingMaterials2">高程 </label>
  91. </div>
  92. <div class="radio radio-info radio-inline">
  93. <input type="radio" id="shadingMaterials3" name="shadingMaterials" value="slope" />
  94. <label for="shadingMaterials3">坡度 </label>
  95. </div>
  96. <div class="radio radio-info radio-inline">
  97. <input type="radio" id="shadingMaterials4" name="shadingMaterials" value="aspect" />
  98. <label for="shadingMaterials4">坡向 </label>
  99. </div>
  100. </td>
  101. </tr>
  102. <tr>
  103. <td>状态控制</td>
  104. <td colspan="3">
  105. <div class="checkbox checkbox-info checkbox-inline">
  106. <input type="checkbox" id="showElse" value="this" name="jiaodu" checked />
  107. <label for="showElse">显示其他区域</label>
  108. </div>
  109. </td>
  110. </tr>
  111. </table>
  112. <!-- 操作单个记录 -->
  113. <table class="mars-table flatTable">
  114. <thead>
  115. <th>区域</th>
  116. <th>操作</th>
  117. </thead>
  118. <tbody id="tbPoly"></tbody>
  119. </table>
  120. </div>
  121. <script src="./js/common.js"></script>
  122. <script type="text/javascript">
  123. "use script"; //开发环境建议开启严格模式
  124. var map;
  125. var contourLine;
  126. function initMap(options) {
  127. //合并属性参数,可覆盖config.json中的对应配置
  128. var mapOptions = mars3d.Util.merge(options, {
  129. scene: {
  130. center: { lat: 30.706401, lng: 116.08272, alt: 26859, heading: 5, pitch: -55 },
  131. showSun: false,
  132. showMoon: false,
  133. showSkyBox: false,
  134. showSkyAtmosphere: false,
  135. fog: false,
  136. globe: {
  137. showGroundAtmosphere: false,
  138. enableLighting: false,
  139. },
  140. },
  141. });
  142. //创建三维地球场景
  143. map = new mars3d.Map("mars3dContainer", mapOptions);
  144. contourLine = new mars3d.thing.ContourLine({
  145. spacing: 100,
  146. width: 1.5,
  147. color: Cesium.Color.RED,
  148. minHeight: -414.0,
  149. maxHeight: 8777.0,
  150. //地表渲染的配色方案
  151. colorScheme: {
  152. elevation: {
  153. step: [0.0, 0.045, 0.1, 0.15, 0.37, 0.54, 1.0],
  154. color: ["#000000", "#2747E0", "#D33B7D", "#D33038", "#FF9742", "#FF9742", "#ffd700"],
  155. },
  156. slope: {
  157. step: [0.0, 0.29, 0.5, Math.sqrt(2) / 2, 0.87, 0.91, 1.0],
  158. color: ["#000000", "#2747E0", "#D33B7D", "#D33038", "#FF9742", "#FF9742", "#ffd700"],
  159. },
  160. aspect: {
  161. step: [0.0, 0.2, 0.4, 0.6, 0.8, 0.9, 1.0],
  162. color: ["#000000", "#2747E0", "#D33B7D", "#D33038", "#FF9742", "#FF9742", "#ffd700"],
  163. },
  164. },
  165. });
  166. map.addThing(contourLine);
  167. //演示的示例区域
  168. let areaItem = contourLine.addArea([
  169. [116.003125, 30.948354, 1103.66],
  170. [116.23964, 30.946376, 563.02],
  171. [116.223677, 30.802558, 522.04],
  172. [115.997891, 30.807484, 440.83],
  173. ]);
  174. addTableItem(areaItem);
  175. $("#chkEnabled").change(function () {
  176. var val = $(this).is(":checked");
  177. contourLine.contourShow = val;
  178. });
  179. $("input[type=radio][name=shadingMaterials]").change(function () {
  180. contourLine.shadingType = this.value;
  181. });
  182. $("#txtColor").minicolors({
  183. position: "bottom left",
  184. control: "saturation",
  185. change: function (hex) {
  186. contourLine.color = Cesium.Color.fromCssColorString(hex);
  187. },
  188. });
  189. $("#txtSpacing")
  190. .slider({ min: 10.0, max: 500.0, step: 1.0, value: 100 })
  191. .on("change", (e) => {
  192. if (e?.value) {
  193. contourLine.spacing = e.value.newValue;
  194. }
  195. });
  196. $("#txtWidth")
  197. .slider({ min: 1.0, max: 10.0, step: 0.1, value: 1.5 })
  198. .on("change", (e) => {
  199. if (e?.value) {
  200. contourLine.width = e.value.newValue;
  201. }
  202. });
  203. $("#btnDraw").click(function () {
  204. map.graphicLayer.startDraw({
  205. type: "polygon",
  206. style: {
  207. color: "#007be6",
  208. opacity: 0.5,
  209. outline: false,
  210. },
  211. success: function (graphic) {
  212. //绘制成功后回调
  213. var positions = graphic.positionsShow;
  214. map.graphicLayer.clear();
  215. console.log(JSON.stringify(mars3d.PointTrans.cartesians2lonlats(positions))); //打印下边界
  216. let areaItem = contourLine.addArea(positions);
  217. addTableItem(areaItem);
  218. },
  219. });
  220. });
  221. $("#btnDrawExtent").click(function () {
  222. map.graphicLayer.startDraw({
  223. type: "rectangle",
  224. style: {
  225. color: "#007be6",
  226. opacity: 0.8,
  227. outline: false,
  228. },
  229. success: function (graphic) {
  230. //绘制成功后回调
  231. var positions = graphic.getOutlinePositions(false);
  232. map.graphicLayer.clear();
  233. console.log(JSON.stringify(mars3d.PointTrans.cartesians2lonlats(positions))); //打印下边界
  234. let areaItem = contourLine.addArea(positions);
  235. addTableItem(areaItem);
  236. },
  237. });
  238. });
  239. $("#showElse").change(function () {
  240. var val = $(this).is(":checked");
  241. contourLine.showElseArea = val;
  242. });
  243. $("#clearWJ").click(function () {
  244. contourLine.clear();
  245. $("#showElse").prop("checked", true);
  246. // 清除表格
  247. var tbody = document.getElementById("tbPoly");
  248. tbody.innerHTML = "";
  249. });
  250. }
  251. // 区域表格添加一行记录
  252. function addTableItem(item) {
  253. // 增加tr和td表格
  254. var tbody = document.getElementById("tbPoly");
  255. var tr = document.createElement("tr");
  256. tr.innerHTML = `
  257. <tr>
  258. <td>区域${item.id}</td>
  259. <td>
  260. <a class="flyTo" href="javascript:void(0)" title="飞行定位到区域"><i class="fa fa-send-o"></i></a>&nbsp;&nbsp;
  261. <a class="remove" href="javascript:void(0)" title="删除区域"><i class="fa fa-trash"></i></a>
  262. </td>
  263. </tr>`;
  264. tbody.appendChild(tr);
  265. //绑定单击事件 定位
  266. tr.querySelector(".flyTo").addEventListener("click", function (e) {
  267. map.flyToPositions(item.positions);
  268. });
  269. // 移动至绘制区域
  270. tr.querySelector(".remove").addEventListener("click", function (e) {
  271. contourLine.removeArea(item);
  272. tbody.removeChild(tr);
  273. });
  274. }
  275. </script>
  276. </body>
  277. </html>