MainMap.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <template>
  2. <div id="cesiumContainer"></div>
  3. </template>
  4. <script>
  5. import api from "@/api/data";
  6. import FireHydrant from "@/assets/Images/MapSymbol/FireHydrant.png";
  7. import Flowmeter from "@/assets/Images/MapSymbol/Flowmeter.png";
  8. import LeakageTester from "@/assets/Images/MapSymbol/LeakageTester.png";
  9. import WaterQuality from "@/assets/Images/MapSymbol/WaterQuality.png";
  10. // import guanxianGeojson from "../../public/static/data/guanxian.json";
  11. export default {
  12. data() {
  13. return {
  14. waterClass: null,
  15. };
  16. },
  17. created() {
  18. proj4.defs(
  19. "EPSG:0986",
  20. "+proj=tmerc +lat_0=0 +lon_0=120.666666666667 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs"
  21. );
  22. // $.getJSON("./static/data/guanxian.json", function (result) {
  23. // globalVariable.guanxianGeojson = result
  24. // });
  25. },
  26. mounted() {
  27. this.waterClass = new Cesium.Water();
  28. this.initViewer().then(() => {
  29. this.setViewDefaultlocation().then(() => {
  30. this.mainFunc();
  31. });
  32. });
  33. },
  34. methods: {
  35. initViewer() {
  36. return new Promise((resolve, reject) => {
  37. globalVariable.viewer = new Cesium.Viewer("cesiumContainer", {
  38. // useDefaultRenderLoop: false, //关闭自动渲染
  39. animation: false, //动画控制不显示
  40. timeline: false, //时间线不显示
  41. fullscreenButton: false, //全屏按钮不显示
  42. infoBox: false,
  43. baseLayerPicker: false, //地图切换不显示
  44. // terrainProvider: Cesium.createWorldTerrain(), // 地形
  45. imageryProvider: new Cesium.SingleTileImageryProvider({
  46. url: (function createColorCanvas(color) {
  47. var width = 1,
  48. height = 1;
  49. var canvas = document.createElement("canvas");
  50. canvas.width = width;
  51. canvas.height = height;
  52. var ctx = canvas.getContext("2d");
  53. ctx.fillStyle = color;
  54. ctx.fillRect(0, 0, width, height);
  55. return canvas.toDataURL();
  56. })("#ffffff00"),
  57. rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0),
  58. }),
  59. geocoder: false,
  60. homeButton: false,
  61. selectionIndicator: false, // 去除绿色选择框
  62. sceneModePicker: false,
  63. navigationHelpButton: false,
  64. scene3DOnly: true, // 仅以3D渲染以节省GPU内存
  65. useBrowserRecommendedResolution: true, // 以浏览器建议的分辨率渲染
  66. });
  67. //去除版权标记
  68. globalVariable.viewer._cesiumWidget._creditContainer.style.display =
  69. "none";
  70. resolve();
  71. });
  72. },
  73. // 默认定位
  74. setViewDefaultlocation(time) {
  75. return new Promise((resolve, reject) => {
  76. globalVariable.viewer.camera.flyTo({
  77. destination: Cesium.Cartesian3.fromDegrees(
  78. systemConfig.mapDefault.center.lon,
  79. systemConfig.mapDefault.center.lat,
  80. systemConfig.mapDefault.height
  81. ),
  82. orientation: {
  83. heading: Cesium.Math.toRadians(systemConfig.mapDefault.heading), // 方向
  84. pitch: Cesium.Math.toRadians(systemConfig.mapDefault.pitch), // 倾斜角度
  85. roll: Cesium.Math.toRadians(systemConfig.mapDefault.roll),
  86. },
  87. duration: isNaN(time) ? 3 : time,
  88. pitchAdjustHeight: 1000,
  89. complete: function () {
  90. resolve();
  91. },
  92. });
  93. });
  94. },
  95. mainFunc() {
  96. this.mapConfig();
  97. // 加载地图瓦片
  98. this.addMapTiles("arcgis");
  99. // this.getPointPosition()
  100. // .then((result) => {
  101. // that.bindPopup();
  102. // })
  103. // .catch((err) => {});
  104. this.tilesetAdd();
  105. this.addWater("./static/data/ojk_water_v3.json", {
  106. // this.addWater("./static/data/ojksb.json", {
  107. // normalMap: "img/textures/waterNormals.jpg", // 水正常扰动的法线图
  108. frequency: 8000.0, // 控制波数的数字。
  109. animationSpeed: 0.02, // 控制水的动画速度的数字。
  110. amplitude: 5.0, // 控制水波振幅的数字。
  111. specularIntensity: 0.8, // 控制镜面反射强度的数字。
  112. baseWaterColor: "#006ab4", // rgba颜色对象基础颜色的水。#00ffff,#00baff,#006ab4
  113. blendColor: "#006ab4", // 从水中混合到非水域时使用的rgba颜色对象。
  114. height: -1, //水面高度
  115. clampToGround: true, //是否贴地
  116. opacity: 0.8, //透明度
  117. });
  118. // this.singleClick();
  119. // this.addGWDataPrimitive();
  120. // this.loadBigDataGltf();
  121. },
  122. // cesium 球体配置
  123. mapConfig() {
  124. // 基础球体颜色
  125. globalVariable.viewer.scene.globe.baseColor = Cesium.Color.BLUE;
  126. // 取消大气效果(发光)
  127. globalVariable.viewer.scene.globe.showGroundAtmosphere = true;
  128. globalVariable.viewer.scene.globe.translucency.enabled = true;
  129. // // 地底颜色
  130. // globalVariable.viewer.scene.globe.undergroundColor = undefined;
  131. // 地形遮盖
  132. globalVariable.viewer.scene.globe.depthTestAgainstTerrain = false;
  133. // globalVariable.viewer.scene.globe.translucency.frontFaceAlpha = 1.0;
  134. // globalVariable.viewer.scene.globe.translucency.rectangle = Cesium.Rectangle.fromDegrees(
  135. // 120.87373270003363,
  136. // 27.913116219448348,
  137. // 120.98856425530658,
  138. // 27.97741914289562
  139. // );
  140. // // 地下模式
  141. // globalVariable.viewer.scene.screenSpaceCameraController.enableCollisionDetection = true ;
  142. // globalVariable.viewer.scene.undergroundMode = true;
  143. // // 设置地表透明度
  144. // globalVariable.viewer.scene.globe.translucency.frontFaceAlpha=0
  145. // // 天空盒隐藏
  146. // globalVariable.viewer.scene.skyBox.show = false;
  147. // // 解决抗锯齿问题
  148. // if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {
  149. // //判断是否支持图像渲染像素化处理
  150. // globalVariable.viewer.resolutionScale = window.devicePixelRatio;
  151. // }
  152. // // //是否开启抗锯齿
  153. // globalVariable.viewer.scene.fxaa = true;
  154. // globalVariable.viewer.scene.postProcessStages.fxaa.enabled = true;
  155. // globalVariable.viewer.scene.globe.depthTestAgainstTerrain = true;
  156. // globalVariable.viewer.scene.debugShowFramesPerSecond = true;
  157. // globalVariable.viewer.scene.globe.enableLighting = true;
  158. // globalVariable.viewer.shadows = true;
  159. // //globalVariable.viewer.shadowMap.softShadows = true
  160. // globalVariable.viewer.shadowMap.darkness = 0.7; //阴影透明度--越大越透明
  161. // // 改变时间设置光照效果
  162. // var utc = Cesium.JulianDate.fromDate(new Date("2021/07/04 08:00:00"));
  163. // //北京时间=UTC+8=GMT+8
  164. // globalVariable.viewer.clockViewModel.currentTime = Cesium.JulianDate.addHours(
  165. // utc,
  166. // 8,
  167. // new Cesium.JulianDate()
  168. // );
  169. // globalVariable.viewer.scene.light = new Cesium.DirectionalLight({
  170. // //去除时间原因影响模型颜色
  171. // direction: new Cesium.Cartesian3(
  172. // 0.35492591601301104,
  173. // -0.8909182691839401,
  174. // -0.2833588392420772
  175. // ),
  176. // });
  177. },
  178. // 添加地图底图瓦片
  179. addMapTiles(key) {
  180. switch (key) {
  181. case "tdt":
  182. // 加载天地图影像
  183. globalVariable.viewer.imageryLayers.addImageryProvider(
  184. new Cesium.WebMapTileServiceImageryProvider({
  185. url:
  186. "http://t{s}.tianditu.gov.cn/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=" +
  187. systemConfig.tdt_tk,
  188. // url: "/proxy_tdt/proxy{s}/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk="+systemConfig.tdt_tk,
  189. layer: "img",
  190. style: "default",
  191. tileMatrixSetID: "w",
  192. format: "image/jpeg",
  193. subdomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
  194. tileMatrixSetID: "GoogleMapsCompatible",
  195. show: true,
  196. minimumLevel: 1,
  197. maximumLevel: 18,
  198. // rectangle: Cesium.Rectangle.fromDegrees(90, -90, 180, -180),
  199. })
  200. );
  201. // 加载影像注记
  202. globalVariable.viewer.imageryLayers.addImageryProvider(
  203. new Cesium.WebMapTileServiceImageryProvider({
  204. url:
  205. "http://t{s}.tianditu.gov.cn/cia_w/wmts?tk=" +
  206. systemConfig.tdt_tk,
  207. layer: "cia",
  208. style: "default",
  209. tileMatrixSetID: "w",
  210. format: "tiles",
  211. subdomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
  212. maximumLevel: 20,
  213. })
  214. );
  215. break;
  216. case "xq":
  217. viewer.imageryLayers.addImageryProvider(
  218. new Cesium.UrlTemplateImageryProvider({
  219. url: "http://119.3.233.75/tile/v1.0/gr?l={z}&x={x}&y={y}",
  220. minimumLevel: 1,
  221. maximumLevel: 19,
  222. format: "png",
  223. })
  224. );
  225. break;
  226. case "arcgis":
  227. // 加载ArcGIS在线地图
  228. globalVariable.viewer.imageryLayers.addImageryProvider(
  229. new Cesium.ArcGisMapServerImageryProvider({
  230. url: "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer",
  231. })
  232. );
  233. break;
  234. default:
  235. break;
  236. }
  237. },
  238. // 模型加载
  239. tilesetAdd() {
  240. // 水坝
  241. // this.add3DTilesData(
  242. // systemConfig.modelTilesObj.ojk_shuiba_dm,
  243. // undefined,
  244. // true
  245. // );
  246. // this.add3DTilesData(
  247. // systemConfig.modelTilesObj.ojk_shuiba_snjz,
  248. // undefined,
  249. // true
  250. // );
  251. // this.add3DTilesData(
  252. // systemConfig.modelTilesObj.ojk_shuiba_swjz,
  253. // undefined,
  254. // true
  255. // );
  256. // this.add3DTilesData(
  257. // systemConfig.modelTilesObj.ojk_shuiba_xp,
  258. // undefined,
  259. // true
  260. // );
  261. // globalVariable.ojk_shuiba_zm = this.add3DTilesData(
  262. // systemConfig.modelTilesObj.ojk_shuiba_zm,
  263. // undefined,
  264. // true
  265. // );
  266. // 模型加载;
  267. if (systemConfig.modelTilesObj.plan) {
  268. // 地面
  269. // let pianyi = this.createMatrix4(systemConfig.modelTilesMatrixObj.plan);
  270. globalVariable.plan = this.add3DTilesData(
  271. systemConfig.modelTilesObj.plan,
  272. undefined,
  273. true
  274. );
  275. }
  276. if (systemConfig.modelTilesObj.plan_nowater) {
  277. // 无水地面
  278. // let pianyi = this.createMatrix4(systemConfig.modelTilesMatrixObj.plan);
  279. globalVariable.plan = this.add3DTilesData(
  280. systemConfig.modelTilesObj.plan_nowater,
  281. undefined,
  282. true
  283. );
  284. }
  285. // 建筑
  286. if (systemConfig.modelTilesObj.build) {
  287. globalVariable.build = this.add3DTilesData(
  288. systemConfig.modelTilesObj.build,
  289. undefined,
  290. true
  291. );
  292. }
  293. // 其他建筑(厂房)
  294. if (systemConfig.modelTilesObj.other_build) {
  295. globalVariable.other_build = this.add3DTilesData(
  296. systemConfig.modelTilesObj.other_build,
  297. undefined,
  298. true
  299. );
  300. }
  301. // 管网
  302. if (systemConfig.modelTilesObj.pipe) {
  303. globalVariable.pipe = this.add3DTilesData(
  304. systemConfig.modelTilesObj.pipe,
  305. undefined,
  306. false
  307. );
  308. }
  309. // globalVariable.tileset = [globalVariable.plan, globalVariable.build]
  310. },
  311. addWater(url, style) {
  312. this.waterClass.create(url, style).then((waterPrimitiveArr) => {
  313. this.waterPrimitiveArr = waterPrimitiveArr;
  314. window.waterPrimitiveArr = this.waterPrimitiveArr;
  315. waterPrimitiveArr.map(function (waterPrimitive) {
  316. return globalVariable.viewer.scene.primitives.add(waterPrimitive);
  317. });
  318. });
  319. // setTimeout(() => {
  320. // Cesium.upraiseModel(waterPrimitiveArr, {
  321. // time: 3,
  322. // height: 2,
  323. // defaultHeight: 2,
  324. // });
  325. // Cesium.upraiseModel([globalVariable.ojk_shuiba_zm], {
  326. // time: 3,
  327. // height: 2,
  328. // defaultHeight: 0,
  329. // });
  330. },
  331. // 点位数据
  332. // 1 流量计 2 消火栓 3 漏失监测仪 4 水质检测设备
  333. getPointPosition() {
  334. let that = this;
  335. return new Promise((resolve, reject) => {
  336. if (Object.keys(globalVariable.point_positions).length != 0) {
  337. Object.keys(globalVariable.point_positions).map(function (key) {
  338. globalVariable.viewer.entities.remove(
  339. globalVariable.point_positions[key]
  340. );
  341. });
  342. globalVariable.point_positions = {};
  343. }
  344. api
  345. .getAllPointPosition()
  346. .then((result) => {
  347. if (result.code == 0) {
  348. let data = result.data;
  349. // primitives可加载大量数据,性能方面比entities要好一些
  350. // let billboards = globalVariable.viewer.scene.primitives.add(
  351. // new Cesium.BillboardCollection()
  352. // );
  353. data.map(function (item, index) {
  354. let arr = that.wenzhou2000ToWGS84([item.x, item.y]);
  355. let img = null;
  356. switch (item.equipmentType) {
  357. case 1:
  358. img = Flowmeter;
  359. break;
  360. case 2:
  361. img = FireHydrant;
  362. break;
  363. case 3:
  364. img = LeakageTester;
  365. break;
  366. case 4:
  367. img = WaterQuality;
  368. break;
  369. }
  370. let entity = globalVariable.viewer.entities.add({
  371. id: item.equipmentId,
  372. position: Cesium.Cartesian3.fromDegrees(arr[0], arr[1], 7),
  373. billboard: {
  374. image: img,
  375. width: 34.5,
  376. height: 35.5,
  377. scale: 1.0,
  378. horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  379. verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  380. pixelOffset: new Cesium.Cartesian2(0, 0),
  381. },
  382. // description: '<table><tr><td>事件描述:</td><td>' + item.id + '</td></tr>'+'<tr><td>中心点坐标:'+item.palce+'',
  383. });
  384. item.lon = arr[0];
  385. item.lat = arr[1];
  386. entity.info = item;
  387. entity.callback = that.searchPointInfo;
  388. globalVariable.point_positions[item.equipmentId] = entity;
  389. return;
  390. // billboards.add({
  391. // image: img, // 图片地址
  392. // width: 138,
  393. // height: 142,
  394. // scale: 1.0,
  395. // sizeInMeters: true, //图像的尺寸被指定成图像实际的尺寸
  396. // // Use a bottom, left origin
  397. // horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  398. // verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  399. // position: Cesium.Cartesian3.fromDegrees(arr[0], arr[1], 80), // 点图标的位置
  400. // id: "",
  401. // });
  402. // return item;
  403. });
  404. resolve();
  405. }
  406. })
  407. .catch((err) => {
  408. reject();
  409. });
  410. });
  411. },
  412. // 点位popup窗口事件
  413. bindPopup() {
  414. let that = this;
  415. var handler = new Cesium.ScreenSpaceEventHandler(
  416. globalVariable.viewer.scene.canvas
  417. );
  418. handler.setInputAction(function (event) {
  419. popup({
  420. type: "LEFT_CLICK",
  421. infos: event,
  422. });
  423. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  424. function popup(options) {
  425. if (options.type == "LEFT_CLICK") {
  426. if ($("#markerPopup")) {
  427. $("#markerPopup").remove();
  428. }
  429. clearInterval(that.ponitInterVal);
  430. var evt = options.infos;
  431. var pickedObject = globalVariable.viewer.scene.pick(evt.position);
  432. if (pickedObject && pickedObject.id) {
  433. var clickMarkerId = pickedObject.id._id;
  434. if (globalVariable.point_positions[clickMarkerId]) {
  435. var data = globalVariable.point_positions[clickMarkerId];
  436. if (data.callback) {
  437. data.callback(data.info);
  438. }
  439. }
  440. } else {
  441. return false;
  442. }
  443. }
  444. }
  445. },
  446. // 查询点位坐标
  447. searchPointInfo(data) {
  448. let that = this;
  449. return new Promise((resolve, reject) => {
  450. api
  451. .getSinglePointInfo({ id: data.equipmentId })
  452. .then((result) => {
  453. if (result.code == 0) {
  454. let param = Object.assign({}, data, result.data);
  455. that.setHtml(param);
  456. resolve();
  457. }
  458. })
  459. .catch((err) => {
  460. reject();
  461. });
  462. });
  463. },
  464. // 设置 popup 弹窗
  465. setHtml(data) {
  466. jumpPopup("popup", data);
  467. },
  468. // // 地图左击事件
  469. // singleClick(viewer) {
  470. // var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
  471. // handler.setInputAction(function (event) {
  472. // var earthPosition = viewer.camera.pickEllipsoid(
  473. // event.position,
  474. // viewer.scene.globe.ellipsoid
  475. // );
  476. // var cartographic = Cesium.Cartographic.fromCartesian(
  477. // earthPosition,
  478. // viewer.scene.globe.ellipsoid,
  479. // new Cesium.Cartographic()
  480. // );
  481. // var lat = Cesium.Math.toDegrees(cartographic.latitude);
  482. // var lng = Cesium.Math.toDegrees(cartographic.longitude);
  483. // var height = cartographic.height;
  484. // console.log(lng + "," + lat);
  485. // }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  486. // },
  487. // 加载3DTiles数据
  488. add3DTilesData(url, matrix, show) {
  489. let tileset = new Cesium.Cesium3DTileset({
  490. url: url + "/tileset.json",
  491. skipLevelOfDetail: true, //开启跳级加载
  492. // preferLeaves: true,
  493. maximumScreenSpaceError: 16,
  494. maximumNumberOfLoadedTiles: 2000,
  495. maximumMemoryUsage: 512, //tileset可以使用的最大内存
  496. show: show,
  497. immediatelyLoadDesiredLevelOfDetail: true,
  498. });
  499. globalVariable.viewer.scene.primitives.add(tileset);
  500. tileset.readyPromise.then(function () {
  501. if (matrix) tileset.root.transform = matrix;
  502. });
  503. return tileset;
  504. },
  505. // 创建偏移矩阵
  506. createMatrix4(matrixParam) {
  507. var mx = Cesium.Matrix3.fromRotationX(
  508. Cesium.Math.toRadians(matrixParam.rx)
  509. );
  510. var my = Cesium.Matrix3.fromRotationY(
  511. Cesium.Math.toRadians(matrixParam.ry)
  512. );
  513. var mz = Cesium.Matrix3.fromRotationZ(
  514. Cesium.Math.toRadians(matrixParam.rz)
  515. );
  516. var rotationX = Cesium.Matrix4.fromRotationTranslation(mx);
  517. var rotationY = Cesium.Matrix4.fromRotationTranslation(my);
  518. var rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
  519. //平移 修改经纬度
  520. var position = Cesium.Cartesian3.fromDegrees(
  521. matrixParam.longitude,
  522. matrixParam.latitude,
  523. matrixParam.height
  524. );
  525. var m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
  526. //旋转、平移矩阵相乘
  527. Cesium.Matrix4.multiply(m, rotationX, m);
  528. Cesium.Matrix4.multiply(m, rotationY, m);
  529. Cesium.Matrix4.multiply(m, rotationZ, m);
  530. //缩放 修改缩放比例
  531. var scale = Cesium.Matrix4.fromUniformScale(matrixParam.scale);
  532. Cesium.Matrix4.multiply(m, scale, m);
  533. return m;
  534. },
  535. // 加载大批量gltf文件
  536. loadBigDataGltf() {
  537. let that = this;
  538. globalVariable.treeArr = [];
  539. return new Promise((resolve, reject) => {
  540. $.getJSON("./static/data/GLTF/tree_path.json", function (array) {
  541. //array.length
  542. let instances = [];
  543. for (let i = 0; i < array.length; i += 2) {
  544. const item = array[i];
  545. let lonlat = that.wenzhou2000ToWGS84([
  546. Number(item.x),
  547. Number(item.y),
  548. ]);
  549. globalVariable.treeArr.push(lonlat);
  550. let modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
  551. new Cesium.Cartesian3.fromDegrees(
  552. lonlat[0] + 0.0007,
  553. lonlat[1] - 0.0004,
  554. 5
  555. ),
  556. new Cesium.HeadingPitchRoll(0, 0, 0)
  557. );
  558. Cesium.Matrix4.multiplyByUniformScale(modelMatrix, 2, modelMatrix); // 缩放
  559. instances.push({
  560. modelMatrix: modelMatrix,
  561. });
  562. }
  563. // // for (let i = 0; i < newPositions.length; i++) {
  564. // for (let i = 0; i < 5000; i++) {
  565. // let cartesian = newPositions[i];
  566. // //批量加载
  567. // let modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
  568. // cartesian,
  569. // new Cesium.HeadingPitchRoll(0, 0, 0)
  570. // ); // 旋转
  571. // }
  572. let primitive = new Cesium.ModelInstanceCollection({
  573. url: "./static/data/GLTF/SEWQ01.gltf",
  574. instances: instances,
  575. });
  576. globalVariable.viewer.scene.primitives.add(primitive);
  577. // globalVariable.viewer.camera.setView({
  578. // // 4.730190106068796,26.731048740120254
  579. // destination: newPositions[0], // 设置位置
  580. // orientation: {
  581. // heading: Cesium.Math.toRadians(0), // 方向
  582. // pitch: Cesium.Math.toRadians(-90.0), // 倾斜角度
  583. // roll: 0,
  584. // },
  585. // });
  586. resolve(primitive);
  587. });
  588. });
  589. },
  590. // 加载 GW 数据 primitive
  591. addGWDataPrimitive() {
  592. let data = globalVariable.guanxianGeojson;
  593. // console.log(data);
  594. let collection = new Cesium.PrimitiveCollection();
  595. data.features.forEach((item, index) => {
  596. let coor = item.geometry.coordinates[0].map(function (arr) {
  597. return [arr[0], arr[1], 100];
  598. });
  599. coor = JSON.parse("[" + coor.join(",") + "]");
  600. let line = Cesium.Cartesian3.fromDegreesArrayHeights(coor);
  601. let radius = Number(item.properties.DIAMETER) / 100;
  602. let shape = computeCircle(radius);
  603. let polylineVolumeGeometry = new Cesium.PolylineVolumeGeometry({
  604. polylinePositions: line,
  605. shapePositions: shape,
  606. cornerType: Cesium.CornerType.ROUNDED,
  607. });
  608. let GeometryInstance = new Cesium.GeometryInstance({
  609. geometry: polylineVolumeGeometry,
  610. // attributes: item.properties,
  611. attributes: {
  612. color: Cesium.ColorGeometryInstanceAttribute.fromColor(
  613. new Cesium.Color(1.0, 0.0, 0.0, 1.0)
  614. ),
  615. },
  616. });
  617. let primitive = new Cesium.Primitive({
  618. geometryInstances: GeometryInstance,
  619. appearance: new Cesium.PolylineColorAppearance({
  620. translucent: false,
  621. }),
  622. });
  623. // collection.add(primitive);
  624. // if (index < 2000)
  625. collection.add(primitive);
  626. });
  627. globalVariable.viewer.scene.primitives.add(collection);
  628. function computeCircle(radius) {
  629. let radiusd = 6;
  630. let beishu = 60;
  631. var positions = [];
  632. for (var i = 0; i < radiusd; i++) {
  633. var radians = Cesium.Math.toRadians(i * beishu);
  634. positions.push(
  635. new Cesium.Cartesian2(
  636. radius * Math.cos(radians),
  637. radius * Math.sin(radians)
  638. )
  639. );
  640. }
  641. return positions;
  642. }
  643. },
  644. wenzhou2000ToWGS84(coordinate) {
  645. return proj4("EPSG:0986", "EPSG:4326", coordinate);
  646. },
  647. // 经纬度转墨卡托
  648. lonlattoWebMercator(lon, lat) {
  649. var xy = [];
  650. var x = (lon * 20037508.34) / 180;
  651. var y =
  652. Math.log(Math.tan(((90 + lat) * Math.PI) / 360)) / (Math.PI / 180);
  653. y = (y * 20037508.34) / 180;
  654. xy[0] = x;
  655. xy[1] = y;
  656. return xy;
  657. },
  658. // 墨卡托转经纬度
  659. webMercator2lonlat(x, y) {
  660. var lonlat = [];
  661. var lon = (x / 20037508.34) * 180;
  662. var lat = (y / 20037508.34) * 180;
  663. lat =
  664. (180 / Math.PI) *
  665. (2 * Math.atan(Math.exp((lat * Math.PI) / 180)) - Math.PI / 2);
  666. lonlat[0] = lon;
  667. lonlat[1] = lat;
  668. return lonlat;
  669. },
  670. },
  671. };
  672. </script>
  673. <style lang="less" scoped>
  674. #cesiumContainer {
  675. width: 100%;
  676. height: 100%;
  677. }
  678. </style>