f45_digitalCity.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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-slider,layer,haoutil,turf,mars3d"
  27. ></script>
  28. <link href="css/style.css" rel="stylesheet" />
  29. <style type="text/css">
  30. /**一个简单文本DIV面板**/
  31. .marsBlackPanel {
  32. min-width: 90px;
  33. min-height: 35px;
  34. position: absolute;
  35. left: 16px;
  36. bottom: 31px;
  37. cursor: default;
  38. opacity: 0.96;
  39. box-sizing: border-box;
  40. }
  41. .marsBlackPanel::before {
  42. content: "";
  43. width: calc(100% + 22px);
  44. height: 39px;
  45. position: absolute;
  46. bottom: -39px;
  47. left: -22px;
  48. background: url(img/marker/popupLbl.png) 0px 0px no-repeat;
  49. background-position: 0px 0px;
  50. background-size: cover;
  51. }
  52. .marsBlackPanel-text {
  53. width: 100%;
  54. height: 100%;
  55. text-align: center;
  56. padding: 1px 20px;
  57. font-size: 23px;
  58. font-family: "MicrosoftYaHei";
  59. font-weight: 100;
  60. color: yellow;
  61. line-height: 33px;
  62. -webkit-box-sizing: border-box;
  63. box-sizing: border-box;
  64. white-space: nowrap;
  65. }
  66. </style>
  67. </head>
  68. <body class="dark">
  69. <!--加载前进行操作提示,优化用户体验-->
  70. <div id="mask" class="signmask" onclick="removeMask()"></div>
  71. <div id="mars3dContainer" class="mars3d-container"></div>
  72. <script src="./js/common.js"></script>
  73. <script type="text/javascript">
  74. "use script"; //开发环境建议开启严格模式
  75. var map;
  76. function initMap(options) {
  77. //合并属性参数,可覆盖config.json中的对应配置
  78. var mapOptions = mars3d.Util.merge(options, {
  79. scene: {
  80. center: { lat: 31.253607, lng: 121.519759, alt: 1492, heading: 203, pitch: -33 },
  81. },
  82. layers: [
  83. {
  84. type: "3dtiles",
  85. name: "上海市建筑物",
  86. url: "//data.mars3d.cn/3dtiles/jzw-shanghai/tileset.json",
  87. maximumScreenSpaceError: 1,
  88. maximumMemoryUsage: 1024,
  89. style: {
  90. color: "rgb(0, 99, 255)",
  91. },
  92. marsJzwStyle: true,
  93. popup: [
  94. { field: "objectid", name: "编号" },
  95. { field: "name", name: "名称" },
  96. { field: "height", name: "楼高", unit: "米" },
  97. ],
  98. show: true,
  99. },
  100. {
  101. type: "geojson",
  102. name: "市区一级道路",
  103. url: "//data.mars3d.cn/file/geojson/shanghai-road.json",
  104. symbol: {
  105. styleOptions: {
  106. width: 2.0,
  107. material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ODLine, {
  108. bgColor: new Cesium.Color(0.1, 0.7, 0.5, 0.4),
  109. color: new Cesium.Color(Math.random() * 0.5 + 0.5, Math.random() * 0.8 + 0.2, 0.0, 1.0),
  110. speed: 20 + 1.0 * Math.random(),
  111. startTime: Math.random(),
  112. }),
  113. },
  114. },
  115. popup: "{Name}",
  116. show: true,
  117. },
  118. ],
  119. });
  120. // delete mapOptions.control;
  121. //创建三维地球场景
  122. map = new mars3d.Map("mars3dContainer", mapOptions);
  123. map.basemap = 2017; //切换到蓝色底图
  124. // 3d模型裁剪
  125. var tilesetPlanClip = new mars3d.thing.TilesetPlanClip({
  126. layer: map.getLayer("上海市建筑物", "name"),
  127. clipOutSide: true,
  128. positions: [
  129. [121.477666, 31.217061, 19.1],
  130. [121.531567, 31.217061, 19.1],
  131. [121.531567, 31.258551, 19.1],
  132. [121.477666, 31.258551, 19.1],
  133. ],
  134. });
  135. map.addThing(tilesetPlanClip);
  136. //特效
  137. var bloomEffect = new mars3d.effect.BloomEffect({
  138. enabled: true,
  139. });
  140. map.addEffect(bloomEffect);
  141. // 围绕旋转
  142. let rotatePoint = new mars3d.thing.RotatePoint({
  143. direction: true, //方向 true逆时针,false顺时针
  144. time: 50, //给定飞行一周所需时间(单位 秒),控制速度
  145. });
  146. map.addThing(rotatePoint);
  147. // rotatePoint.start();
  148. //添加矢量数据
  149. addCityGraphics();
  150. }
  151. function addCityGraphics() {
  152. //创建Graphic图层
  153. var graphicLayer = new mars3d.layer.GraphicLayer();
  154. map.addLayer(graphicLayer);
  155. // 模型的中心点
  156. var position = [121.510608, 31.234322, 0]; // 用于围绕旋转 + 中心点扩散 + 旋转的图片
  157. var center = Cesium.Cartesian3.fromDegrees(position[0], position[1], 140); // 用于div标注和远眺的线
  158. // 中心扩散点
  159. var circleDiffuseWallGlow = new mars3d.graphic.DiffuseWall({
  160. name: "中心扩散点",
  161. position: position,
  162. style: {
  163. diffHeight: 500, //高度
  164. radius: 150, //半径
  165. color: "#7ffeff",
  166. speed: 6, //速度
  167. },
  168. });
  169. graphicLayer.addGraphic(circleDiffuseWallGlow);
  170. // 旋转的图片 -- 中心围墙
  171. var WallImagePositions = mars3d.PolyUtil.getEllipseOuterPositions({
  172. position: position,
  173. radius: 50, //半径
  174. count: 50, //共返回(count*4)个点
  175. });
  176. var rotatWallImage = new mars3d.graphic.WallPrimitive({
  177. positions: WallImagePositions,
  178. style: {
  179. diffHeight: 190,
  180. closure: true,
  181. material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.RectSlide, {
  182. image: "img/tietu/circular.png",
  183. speed: 2,
  184. }),
  185. },
  186. });
  187. graphicLayer.addGraphic(rotatWallImage);
  188. // 旋转的图片 -- 底部
  189. var rotation = Cesium.Math.toRadians(50);
  190. function getRotationValue() {
  191. rotation -= 0.007;
  192. return rotation;
  193. }
  194. var rotatCicleImage = new mars3d.graphic.CircleEntity({
  195. position: position,
  196. style: {
  197. radius: 500,
  198. height: 50,
  199. material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.Image2, {
  200. image: "img/textures/circle_bg.png",
  201. }),
  202. rotation: new Cesium.CallbackProperty(getRotationValue, false),
  203. stRotation: new Cesium.CallbackProperty(getRotationValue, false),
  204. },
  205. });
  206. graphicLayer.addGraphic(rotatCicleImage);
  207. //
  208. var graphic = new mars3d.graphic.ModelEntity({
  209. name: "四凌锥体",
  210. position: [position[0], position[1], 180],
  211. style: {
  212. url: "//data.mars3d.cn/gltf/mars/zhui.glb",
  213. scale: 30,
  214. },
  215. });
  216. graphicLayer.addGraphic(graphic);
  217. //开始 自旋转效果
  218. graphic.rotateStart({
  219. direction: true, //控制方向, true逆时针,false顺时针
  220. time: 6, //time:给定飞行一周所需时间(单位 秒),控制速度
  221. });
  222. // divgraphic标注
  223. var divgraphic = new mars3d.graphic.DivGraphic({
  224. position: center,
  225. style: {
  226. html: `<div class="marsBlackPanel">
  227. <div class="marsBlackPanel-text">中心坐标</div>
  228. </div>`,
  229. horizontalOrigin: Cesium.HorizontalOrigin.LEFT, //横向定位
  230. verticalOrigin: Cesium.VerticalOrigin.CENTER, //垂直定位
  231. },
  232. });
  233. graphicLayer.addGraphic(divgraphic);
  234. // 扫描圆形
  235. var scanCircle = new mars3d.graphic.CircleEntity({
  236. position: Cesium.Cartesian3.fromDegrees(121.501618, 31.235704, 24.2),
  237. style: {
  238. radius: 480.0,
  239. material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.CircleScan, {
  240. image: "img/textures/circleScan.png",
  241. color: "#ffffff",
  242. }),
  243. stRotation: new Cesium.CallbackProperty(getRotationValue, false),
  244. classificationType: Cesium.ClassificationType.BOTH,
  245. clampToGround: true,
  246. },
  247. });
  248. graphicLayer.addGraphic(scanCircle);
  249. // 远眺的线 ,数据获取的pointArr
  250. queryAreasData().then((res) => {
  251. var lineMaterial = mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ODLine, {
  252. color: new Cesium.Color(1, 1, 1),
  253. bgColor: new Cesium.Color(0.1, 0.7, 0.5, 0.4),
  254. speed: 5 + 1.0 * Math.random(),
  255. startTime: Math.random(),
  256. });
  257. for (var i = 0, len = res.length; i < len; i++) {
  258. let item = res[i];
  259. let color = ["#ffff00", "#81d8ff", "#fff9ed"];
  260. let thisPoint = Cesium.Cartesian3.fromDegrees(item.point[0], item.point[1], 1);
  261. let positions = mars3d.PolyUtil.getLinkedPointList(center, thisPoint, 40000, 100); //计算曲线点
  262. var primitive = new mars3d.graphic.PolylinePrimitive({
  263. positions: positions,
  264. style: {
  265. width: 4,
  266. material: lineMaterial, //动画线材质
  267. },
  268. });
  269. primitive.bindPopup(item.name);
  270. graphicLayer.addGraphic(primitive);
  271. // 圆椎体
  272. var coneGlow = new mars3d.graphic.LightCone({
  273. position: Cesium.Cartesian3.fromDegrees(item.point[0], item.point[1], 10),
  274. style: {
  275. radius: 10,
  276. height: 200,
  277. color: color[i % color.length],
  278. },
  279. popup: item.name,
  280. });
  281. graphicLayer.addGraphic(coneGlow);
  282. }
  283. });
  284. //竖直飞线
  285. var arrData = [];
  286. for (var j = 0; j < 100; ++j) {
  287. var startPt = randomPoint();
  288. let endPt = startPt.clone();
  289. endPt.alt = haoutil.math.random(600, 1000);
  290. let startTime = haoutil.math.random(0, 10000);
  291. let speed = haoutil.math.random(1, 35);
  292. arrData.push({
  293. positions: [startPt, endPt],
  294. style: {
  295. width: 1,
  296. material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ODLine, {
  297. color: "rgb(255, 255, 2)",
  298. bgColor: "rgb(0,0,0,0.1)",
  299. startTime: startTime,
  300. speed: speed,
  301. }),
  302. },
  303. });
  304. }
  305. var upPoly = new mars3d.graphic.PolylineCombine({
  306. instances: arrData,
  307. });
  308. graphicLayer.addGraphic(upPoly);
  309. }
  310. //数据获取 返回pointArr
  311. function queryAreasData() {
  312. return new Promise(function (resolve, reject) {
  313. $.ajax({
  314. url: "//data.mars3d.cn/file/geojson/shanghai-point.json",
  315. type: "get",
  316. dataType: "json",
  317. success: function (result) {
  318. let pointArr = [];
  319. result.features.forEach((obj) => {
  320. pointArr.push({
  321. name: obj.properties.Name,
  322. point: obj.geometry.coordinates,
  323. });
  324. });
  325. resolve(pointArr);
  326. },
  327. error: function (data) {
  328. reject(data);
  329. },
  330. });
  331. });
  332. }
  333. //取区域内的随机图标;用于线对象的合并渲染
  334. function randomPoint() {
  335. var jd = haoutil.math.random(121.500525 * 1000, 121.518298 * 1000) / 1000;
  336. var wd = haoutil.math.random(31.231515 * 1000, 31.24228 * 1000) / 1000;
  337. return new mars3d.LatLngPoint(jd, wd, 50);
  338. }
  339. </script>
  340. </body>
  341. </html>