g15_dth_fc.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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,layer,haoutil,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. <div class="checkbox checkbox-primary checkbox-inline">
  37. <input id="chkShowColor" class="styled" type="checkbox" checked />
  38. <label for="chkShowColor"> 是否显示各层颜色 </label>
  39. </div>
  40. </div>
  41. <script src="./js/common.js"></script>
  42. <script type="text/javascript">
  43. "use script"; //开发环境建议开启严格模式
  44. var map;
  45. var geoJsonLayerDTH;
  46. function initMap(options) {
  47. //合并属性参数,可覆盖config.json中的对应配置
  48. var mapOptions = mars3d.Util.merge(options, {
  49. scene: {
  50. center: { lat: 43.823957, lng: 125.136704, alt: 286, heading: 11, pitch: -24 },
  51. },
  52. });
  53. //创建三维地球场景
  54. map = new mars3d.Map("mars3dContainer", mapOptions);
  55. //模型
  56. var tiles3dLayer = new mars3d.layer.TilesetLayer({
  57. pid: 2030,
  58. type: "3dtiles",
  59. name: "校园",
  60. url: "//data.mars3d.cn/3dtiles/qx-xuexiao/tileset.json",
  61. position: { alt: 15.8 },
  62. maximumScreenSpaceError: 1,
  63. maximumMemoryUsage: 1024,
  64. center: { lat: 43.821193, lng: 125.143124, alt: 990, heading: 342, pitch: -50 },
  65. });
  66. map.addLayer(tiles3dLayer);
  67. //创建单体化图层
  68. geoJsonLayerDTH = new mars3d.layer.GeoJsonLayer({
  69. name: "分层单体化",
  70. url: "//data.mars3d.cn/file/geojson/dth-xuexiao-fc.json",
  71. onCreateGraphic: createDthGraphic, //自定义解析数据
  72. });
  73. map.addLayer(geoJsonLayerDTH);
  74. geoJsonLayerDTH.bindPopup((e) => {
  75. let item = e.graphic.attr;
  76. let html = `楼层:第${item.thisFloor}层 (共${item.allFloor}层)<br/>
  77. 备注:${item.remark} `;
  78. return html;
  79. });
  80. $("#chkShowColor").change(function () {
  81. let val = $(this).is(":checked");
  82. geoJsonLayerDTH.closePopup();
  83. if (val) {
  84. geoJsonLayerDTH.eachGraphic((graphic, index) => {
  85. graphic.setStyle({
  86. opacity: 0.2,
  87. });
  88. });
  89. } else {
  90. geoJsonLayerDTH.eachGraphic((graphic) => {
  91. graphic.setStyle({
  92. opacity: 0.01,
  93. });
  94. });
  95. }
  96. });
  97. }
  98. //添加单体化矢量对象
  99. function createDthGraphic(options) {
  100. var points = options.positions; //各顶点的坐标
  101. var attr = options.attr; //楼层层高配置信息
  102. var minHight = attr.bottomHeight; //当前层的 底部海拔高度
  103. var maxHight = attr.topHeight; //当前层的 顶部海拔高度
  104. var primitive = new mars3d.graphic.PolygonPrimitive({
  105. positions: points,
  106. style: {
  107. height: minHight,
  108. extrudedHeight: maxHight,
  109. //单体化默认显示样式
  110. color: getColor(),
  111. opacity: 0.3,
  112. classification: true,
  113. //单体化鼠标移入或单击后高亮的样式
  114. highlight: {
  115. type: mars3d.EventType.click,
  116. color: "#ffff00",
  117. opacity: 0.6,
  118. },
  119. },
  120. attr: attr,
  121. });
  122. geoJsonLayerDTH.addGraphic(primitive);
  123. }
  124. //颜色
  125. var index = 0;
  126. var colors = ["#99CCCC", "#66FF66", "#FF6666", "#00CCFF", "#00FF33", "#CC0000", "#CC00CC", "#CCFF00", "#0000FF"];
  127. function getColor() {
  128. var i = index++ % colors.length;
  129. return colors[i];
  130. }
  131. </script>
  132. </body>
  133. </html>