MainMap.vue 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. <template>
  2. <div id="cesiumContainer">
  3. <!-- <div class="get_now_camera_view">
  4. <van-button @click="consoleCameraPosition"> 当前视角 </van-button>
  5. <van-button @click="setViewDefaultlocation"> 复位 </van-button>
  6. </div>
  7. <van-popup
  8. v-model:show="dialogVisible"
  9. :style="{ height: '50%', width: '80%' }"
  10. :closed="hideInfoDailog"
  11. >
  12. <div>
  13. <div style="font-size: 16px">{{ dialogInfoStr }}</div>
  14. <van-button @click="hideInfoDailog">关 闭</van-button>
  15. <van-button :class="'copy_info_dialog'" type="primary">
  16. 复 制
  17. </van-button>
  18. </div>
  19. </van-popup> -->
  20. </div>
  21. <Tool></Tool>
  22. </template>
  23. <script>
  24. // import Clipboard from "clipboard";
  25. import { defineAsyncComponent } from "vue";
  26. import Water from "@/utils/Water";
  27. export default {
  28. data() {
  29. return {
  30. dialogVisible: false,
  31. dialogInfoStr: "",
  32. clipboard: null,
  33. correctCamera: false,
  34. waterObj: null, // 水面实例
  35. flylineObj: [], // 飞线数组
  36. topK: [
  37. {
  38. lon: 121.12265818599361,
  39. lat: 31.153907327111906,
  40. h: 12.178229477117695,
  41. },
  42. {
  43. lon: 121.12264787421734,
  44. lat: 31.15395149031556,
  45. h: 12.178192986180326,
  46. },
  47. {
  48. lon: 121.12278546708409,
  49. lat: 31.153975342725264,
  50. h: 12.178415363887282,
  51. },
  52. {
  53. lon: 121.12281310059657,
  54. lat: 31.15385762853425,
  55. h: 12.178399877503464,
  56. },
  57. {
  58. lon: 121.1228576094918,
  59. lat: 31.15386519051712,
  60. h: 12.178394232107442,
  61. },
  62. {
  63. lon: 121.1228909000206,
  64. lat: 31.153723309251856,
  65. h: 12.17857353611858,
  66. },
  67. {
  68. lon: 121.12294578609598,
  69. lat: 31.153732796983615,
  70. h: 12.178675754028028,
  71. },
  72. {
  73. lon: 121.12298033312791,
  74. lat: 31.153585333373417,
  75. h: 12.17876227737616,
  76. },
  77. {
  78. lon: 121.1228480316718,
  79. lat: 31.15356239349922,
  80. h: 12.178326652099466,
  81. },
  82. {
  83. lon: 121.12283863696666,
  84. lat: 31.153602052352188,
  85. h: 12.178301731797035,
  86. },
  87. {
  88. lon: 121.12279132401528,
  89. lat: 31.153593731079162,
  90. h: 12.17821160134978,
  91. },
  92. {
  93. lon: 121.12280904366847,
  94. lat: 31.153517944755357,
  95. h: 12.178387628978598,
  96. },
  97. {
  98. lon: 121.12256003807408,
  99. lat: 31.15347475524662,
  100. h: 12.178108003497535,
  101. },
  102. {
  103. lon: 121.12255140331416,
  104. lat: 31.153510889388823,
  105. h: 12.178086221333002,
  106. },
  107. {
  108. lon: 121.12251427275822,
  109. lat: 31.153504509859477,
  110. h: 12.17756730102783,
  111. },
  112. { lon: 121.1224291079002, lat: 31.15386748647, h: 12.177529555001517 },
  113. ],
  114. };
  115. },
  116. components: {
  117. Tool: defineAsyncComponent(() => import("@/components/Tool.vue")),
  118. },
  119. created() {},
  120. mounted() {
  121. let that = this;
  122. // this.clipboard = new Clipboard(".copy_info_dialog", {
  123. // // 点击copy按钮,直接通过text直接返回复印的内容
  124. // text: function () {
  125. // return that.dialogInfoStr;
  126. // },
  127. // });
  128. this.waterObj = new Water();
  129. window.controlCZ = this.controlCZ;
  130. this.$root.$.appContext.config.globalProperties.$flyTo = this.flyTo;
  131. // this.setfixGltf();
  132. this.initViewer().then(() => {
  133. this.mapConfig();
  134. // 默认视角
  135. this.setViewDefaultlocation().then(() => {
  136. that.mainFunc();
  137. });
  138. });
  139. window.getNowCameraPosition1 = this.getNowCameraPosition;
  140. window.getNowCameraPosition = function () {
  141. this.getNowCameraPosition().then((result) => {
  142. this.showInfoDailog(result.info);
  143. });
  144. };
  145. return;
  146. },
  147. methods: {
  148. setfixGltf() {
  149. var fixGltf = function (gltf) {
  150. if (!gltf.extensionsUsed) {
  151. return;
  152. }
  153. var v = gltf.extensionsUsed.indexOf("KHR_technique_webgl");
  154. var t = gltf.extensionsRequired.indexOf("KHR_technique_webgl");
  155. // 中招了。。
  156. if (v !== -1) {
  157. gltf.extensionsRequired.splice(t, 1, "KHR_techniques_webgl");
  158. gltf.extensionsUsed.splice(v, 1, "KHR_techniques_webgl");
  159. gltf.extensions = gltf.extensions || {};
  160. gltf.extensions["KHR_techniques_webgl"] = {};
  161. gltf.extensions["KHR_techniques_webgl"].programs = gltf.programs;
  162. gltf.extensions["KHR_techniques_webgl"].shaders = gltf.shaders;
  163. gltf.extensions["KHR_techniques_webgl"].techniques = gltf.techniques;
  164. var techniques = gltf.extensions["KHR_techniques_webgl"].techniques;
  165. gltf.materials.forEach(function (mat, index) {
  166. gltf.materials[index].extensions["KHR_technique_webgl"].values =
  167. gltf.materials[index].values;
  168. gltf.materials[index].extensions["KHR_techniques_webgl"] =
  169. gltf.materials[index].extensions["KHR_technique_webgl"];
  170. var vtxfMaterialExtension =
  171. gltf.materials[index].extensions["KHR_techniques_webgl"];
  172. for (var value in vtxfMaterialExtension.values) {
  173. var us = techniques[vtxfMaterialExtension.technique].uniforms;
  174. for (var key in us) {
  175. if (us[key] === value) {
  176. vtxfMaterialExtension.values[key] =
  177. vtxfMaterialExtension.values[value];
  178. delete vtxfMaterialExtension.values[value];
  179. break;
  180. }
  181. }
  182. }
  183. });
  184. techniques.forEach(function (t) {
  185. for (var attribute in t.attributes) {
  186. var name = t.attributes[attribute];
  187. t.attributes[attribute] = t.parameters[name];
  188. }
  189. for (var uniform in t.uniforms) {
  190. var name = t.uniforms[uniform];
  191. t.uniforms[uniform] = t.parameters[name];
  192. }
  193. });
  194. }
  195. };
  196. Object.defineProperties(Cesium.Model.prototype, {
  197. _cachedGltf: {
  198. set: function (value) {
  199. this._vtxf_cachedGltf = value;
  200. if (this._vtxf_cachedGltf && this._vtxf_cachedGltf._gltf) {
  201. fixGltf(this._vtxf_cachedGltf._gltf);
  202. }
  203. },
  204. get: function () {
  205. return this._vtxf_cachedGltf;
  206. },
  207. },
  208. });
  209. },
  210. consoleCameraPosition() {
  211. this.getNowCameraPosition().then((result) => {
  212. this.showInfoDailog(
  213. JSON.stringify(result.result).replaceAll("{", "").replaceAll("}", "")
  214. );
  215. });
  216. },
  217. initViewer() {
  218. return new Promise((resolve, reject) => {
  219. // globalVariable.viewer = new Cesium.Viewer("cesiumContainer", {
  220. // // useDefaultRenderLoop: false, //关闭自动渲染
  221. // animation: false, //动画控制不显示
  222. // timeline: false, //时间线不显示
  223. // fullscreenButton: false, //全屏按钮不显示
  224. // infoBox: false,
  225. // baseLayerPicker: false, //地图切换不显示
  226. // // terrainProvider: Cesium.createWorldTerrain(), // 地形
  227. // imageryProvider: new Cesium.SingleTileImageryProvider({
  228. // url: (function createColorCanvas(color) {
  229. // var width = 1,
  230. // height = 1;
  231. // var canvas = document.createElement("canvas");
  232. // canvas.width = width;
  233. // canvas.height = height;
  234. // var ctx = canvas.getContext("2d");
  235. // ctx.fillStyle = color;
  236. // ctx.fillRect(0, 0, width, height);
  237. // return canvas.toDataURL();
  238. // })("#ffffff00"),
  239. // rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0),
  240. // }),
  241. // geocoder: false,
  242. // homeButton: false,
  243. // selectionIndicator: false, // 去除绿色选择框
  244. // sceneModePicker: false,
  245. // navigationHelpButton: false,
  246. // scene3DOnly: true, // 仅以3D渲染以节省GPU内存
  247. // useBrowserRecommendedResolution:
  248. // systemConfig.useBrowserRecommendedResolution, // 以浏览器建议的分辨率渲染
  249. // // 设置为了去掉天空盒子
  250. // orderIndependentTranslucency: true,
  251. // // maximumRenderTimeChange: Infinity, // 无操作时自动渲染帧率,设为数字会消耗性能,Infinity为无操作不渲染
  252. // // // 开启 webgl 2.0
  253. // // contextOptions: {
  254. // // requestWebgl2: true,
  255. // // },
  256. // // resolutionScale: 1, //清晰度 0-1
  257. // // targetFrameRate: 165, //设置最大频率数
  258. // // maximumScreenSpaceError: 8, //屏幕空间最大误差
  259. // });
  260. globalVariable.viewer = new Cesium.Viewer("cesiumContainer", {
  261. animation: false, // 是否创建动画小器件,左下角仪表
  262. baseLayerPicker: false, // 是否显示图层选择器
  263. fullscreenButton: false, // 是否显示全屏按钮
  264. vrButton: false, // 是否创建VRButton小工具
  265. geocoder: false, // 是否显示geocoder小器件,右上角查询按钮
  266. homeButton: false, // 是否显示Home按钮
  267. infoBox: false, // 是否显示信息框
  268. sceneModePicker: false, // 是否显示3D/2D选择器
  269. selectionIndicator: false, // 是否显示选取指示器组件
  270. timeline: false, // 是否显示时间轴
  271. navigationHelpButton: false, // 是否显示右上角的帮助按钮
  272. navigationInstructionsInitiallyVisible: false, // 如果导航指示最初应可见,则为True;如果用户明确单击按钮后才显示,则为false。
  273. scene3DOnly: true, // 如果设置为true,则所有几何图形以3D模式绘制以节约GPU资源
  274. shouldAnimate: false, // 默认情况下,如果时钟应尝试提前模拟时间,则为true,否则为false。此选项优先于设置
  275. clock: new Cesium.Clock(), // 用于控制当前时间的时钟对象
  276. clockViewModel: new Cesium.ClockViewModel(
  277. new Cesium.Clock({
  278. startTime: Cesium.JulianDate.fromIso8601("2013-12-25"),
  279. currentTime: Cesium.JulianDate.fromIso8601("2013-12-25"),
  280. stopTime: Cesium.JulianDate.fromIso8601("2013-12-26"),
  281. clockRange: Cesium.ClockRange.LOOP_STOP,
  282. clockStep: Cesium.ClockStep.SYSTEM_CLOCK_MULTIPLIER,
  283. })
  284. ), // 用于控制当前时间的时钟对象
  285. selectedImageryProviderViewModel: undefined, // 当前图像图层的显示模型,仅baseLayerPicker设为true有意义
  286. imageryProviderViewModels:
  287. Cesium.createDefaultImageryProviderViewModels(), // 可供BaseLayerPicker选择的图像图层ProviderViewModel数组
  288. selectedTerrainProviderViewModel: undefined, // 当前地形图层的显示模型,仅baseLayerPicker设为true有意义
  289. terrainProviderViewModels:
  290. Cesium.createDefaultTerrainProviderViewModels(), // 可供BaseLayerPicker选择的地形图层ProviderViewModel数组
  291. imageryProvider: new Cesium.SingleTileImageryProvider({
  292. url: (function createColorCanvas(color) {
  293. // 返回空白
  294. var width = 1,
  295. height = 1;
  296. var canvas = document.createElement("canvas");
  297. canvas.width = width;
  298. canvas.height = height;
  299. var ctx = canvas.getContext("2d");
  300. ctx.fillStyle = color;
  301. ctx.fillRect(0, 0, width, height);
  302. return canvas.toDataURL();
  303. })("#ffffff00"),
  304. rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0),
  305. }), // 图像图层提供者,仅baseLayerPicker设为false有意义
  306. // terrainProvider: new Cesium.EllipsoidTerrainProvider(), // 地形图层提供者,仅baseLayerPicker设为false有意义
  307. // skyBox: new Cesium.SkyBox({
  308. // sources: {
  309. // positiveX: "Cesium-1.7.1/Skybox/px.jpg",
  310. // negativeX: "Cesium-1.7.1/Skybox/mx.jpg",
  311. // positiveY: "Cesium-1.7.1/Skybox/py.jpg",
  312. // negativeY: "Cesium-1.7.1/Skybox/my.jpg",
  313. // positiveZ: "Cesium-1.7.1/Skybox/pz.jpg",
  314. // negativeZ: "Cesium-1.7.1/Skybox/mz.jpg",
  315. // },
  316. // }), // 用于渲染星空的SkyBox对象
  317. fullscreenElement: document.body, // 全屏时渲染的HTML元素,
  318. useDefaultRenderLoop: true, // 如果需要控制渲染循环,则设为true
  319. targetFrameRate: undefined, // 使用默认render loop时的帧率
  320. showRenderLoopErrors: false, // 如果设为true,将在一个HTML面板中显示错误信息
  321. automaticallyTrackDataSourceClocks: true, // 自动追踪最近添加的数据源的时钟设置
  322. sceneMode: Cesium.SceneMode.SCENE3D, // 初始场景模式
  323. mapProjection: new Cesium.WebMercatorProjection(), // 地图投影体系
  324. dataSources: new Cesium.DataSourceCollection(), // 需要进行可视化的数据源的集合
  325. // contextOptions: {
  326. // // 传递给Scene对象的上下文参数(scene.options) 截图需要的
  327. // // webgl: {
  328. // // alpha: true,
  329. // // depth: true,
  330. // // stencil: true,
  331. // // antialias: true,
  332. // // premultipliedAlpha: true,
  333. // // // 通过canvas.toDataURL()实现截图需要将该项设置为true
  334. // // preserveDrawingBuffer: true,
  335. // // failIfMajorPerformanceCaveat: true,
  336. // // },
  337. // webgl: {
  338. // webgl: {
  339. // alpha: false, // (boolean)值表明canvas包含一个alpha缓冲区。
  340. // depth: true, // (boolean)值表明绘制缓冲区包含一个深度至少为16位的缓冲区。
  341. // stencil: false, // 表明绘制缓冲区包含一个深度至少为8位的模版缓冲区boolean值。
  342. // antialias: true, // (boolean)值表明是否开启抗锯齿
  343. // //指示浏览器在运行WebGL上下文时使用相应的GPU电源配置。 可能值如下:
  344. // // "default":自动选择,默认值。
  345. // // "high-performance": 高性能模式。
  346. // // "low-power": 节能模式。
  347. // powerPreference: "low-power",
  348. // premultipliedAlpha: true, // 表明排版引擎讲假设绘制缓冲区包含预混合alpha通道的boolean值。
  349. // preserveDrawingBuffer: false, // 如果这个值为true缓冲区将不会被清除,会保存下来,直到被清除或被使用者覆盖。
  350. // failIfMajorPerformanceCaveat: false, // 表明在一个系统性能低的环境是否创建该上下文的boolean值。
  351. // },
  352. // allowTextureFilterAnisotropic: true,
  353. // },
  354. // },
  355. });
  356. if (systemConfig.msaaSamples != 0) {
  357. globalVariable.viewer.scene.msaaSamples = systemConfig.msaaSamples;
  358. }
  359. //去除版权标记
  360. globalVariable.viewer._cesiumWidget._creditContainer.style.display =
  361. "none";
  362. resolve();
  363. });
  364. },
  365. mainFunc() {
  366. let that = this;
  367. // camera范围限制
  368. this.bindLimitCameraFunc();
  369. // 取消滑动事件
  370. this.controlCZ(systemConfig.mapControl);
  371. // 自定义滑动事件
  372. this.wetherScroll(this.changeCamera);
  373. // // 加载地图瓦片
  374. // this.addMapTiles("arcgis");
  375. window.bindLimitCameraFunc = this.bindLimitCameraFunc;
  376. window.unbindLimitCameraFunc = this.unbindLimitCameraFunc;
  377. // entity点击事件
  378. this.entityClickEvent();
  379. // 键盘/地图点击事件
  380. // this.singleClick(viewer); // 地图点击
  381. this.singleClick2(); // 模型点击
  382. keyboardMapRoamingInit(globalVariable.viewer);
  383. // this.addGltf("http://192.168.1.37/model_data/QPXZFUZX/20220921/obj/output/gltf/Image60/1C.gltf", 121.1225983493769, 31.153846152219288, 0);
  384. // this.addGltf("http://192.168.1.37/model_data/QPXZFUZX/20220921/obj/output/gltf/Image60/2C.gltf", 121.1225983493769, 31.153846152219288, 0);
  385. // this.addGltf("http://192.168.1.37/model_data/QPXZFUZX/20220921/obj/output/gltf/Image60/3C.gltf", 121.1225983493769, 31.153846152219288, 0);
  386. // return;
  387. let keyArr = Object.keys(systemConfig.tilesConfig);
  388. for (let i = 0; i < keyArr.length; i++) {
  389. const str = keyArr[i];
  390. globalVariable.tilesArr[str] = this.add3DTilesData(
  391. systemConfig.dataUrl + str + "/tileset.json", //
  392. {
  393. light: systemConfig.tilesConfig[str].light,
  394. }
  395. );
  396. }
  397. // // 飞线加载
  398. // this.addFlyLine();
  399. // 水面加载
  400. this.addWaterPanel();
  401. // // 树木加载
  402. // this.addTree();
  403. },
  404. // bindCameraNo() {
  405. // globalVariable.viewer.scene.preUpdate.addEventListener(this.cameraddte);
  406. // },
  407. // unbindCamera() {
  408. // globalVariable.viewer.scene.preUpdate.removeEventListener(
  409. // this.cameraddte
  410. // );
  411. // },
  412. // cameraddte() {
  413. // // 获取当前位置,当前方向,强制禁止X轴、Y轴
  414. // var heading = Cesium.Math.toDegrees(globalVariable.viewer.camera.heading);
  415. // var pitch = Cesium.Math.toDegrees(globalVariable.viewer.camera.pitch); //Cesium.Math.toDegrees作用是把弧度转换成度数
  416. // var roll = Cesium.Math.toDegrees(globalVariable.viewer.camera.roll);
  417. // var positionCartesian = globalVariable.viewer.camera.position;
  418. // // var position = Cesium.Cartographic.fromCartesian(positionCartesian);
  419. // // var lon = Cesium.Math.toDegrees(position.longitude);
  420. // // var lat = Cesium.Math.toDegrees(position.latitude);
  421. // // var h = globalVariable.viewer.camera.positionCartographic.height;
  422. // globalVariable.viewer.camera.setView({
  423. // destination: positionCartesian, //赤道上空1000km高度
  424. // orientation: {
  425. // heading: Cesium.Math.toRadians(heading), // 相机方向指向当地东向
  426. // pitch: 0.0, // 再将相机方向转向地心,此时Up方向指向当地东向
  427. // roll: 0.0,
  428. // },
  429. // });
  430. // },
  431. // entity Click
  432. entityClickEvent() {
  433. let viewClickHandle = new Cesium.ScreenSpaceEventHandler(
  434. globalVariable.viewer.scene.canvas
  435. );
  436. viewClickHandle.setInputAction(function (evt) {
  437. var pickedObject = globalVariable.viewer.scene.pick(evt.position);
  438. if (pickedObject && pickedObject.id) {
  439. var clickMarkerId = pickedObject.id._id;
  440. if (globalVariable.point_positions[clickMarkerId]) {
  441. var data = globalVariable.point_positions[clickMarkerId];
  442. if (data.callback) {
  443. data.callback(data.infos);
  444. }
  445. }
  446. } else {
  447. return false;
  448. }
  449. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  450. },
  451. changeCamera(direction) {
  452. switch (direction) {
  453. case "left":
  454. globalVariable.viewer.camera.lookLeft((Math.PI / 180) * 2);
  455. break;
  456. case "right":
  457. globalVariable.viewer.camera.lookRight((Math.PI / 180) * 2);
  458. break;
  459. default:
  460. break;
  461. }
  462. },
  463. wetherScroll(func) {
  464. let startX = 0;
  465. let startY = 0;
  466. let endX = 0;
  467. let endY = 0;
  468. let distanceX = 0;
  469. let distanceY = 0;
  470. let body = document.getElementById("cesiumContainer");
  471. var clientHeight = document.documentElement.clientHeight;
  472. var clientWidth = document.documentElement.clientWidth;
  473. body.addEventListener("touchstart", function (event) {
  474. var touch = event.targetTouches[0];
  475. //滑动起点的坐标
  476. startX = touch.pageX;
  477. startY = touch.pageY;
  478. // console.log("startX:"+startX+","+"startY:"+startY);
  479. });
  480. body.addEventListener("touchmove", function (event) {
  481. var touch = event.targetTouches[0];
  482. //手势滑动时,手势坐标不断变化,取最后一点的坐标为最终的终点坐标
  483. endX = touch.pageX;
  484. endY = touch.pageY;
  485. distanceX = endX - startX;
  486. distanceY = endY - startY;
  487. if (startX != Math.abs(distanceX)) {
  488. //在滑动的距离超过屏幕高度的20%时,做某种操作
  489. if (Math.abs(distanceX) > clientWidth * 0.001) {
  490. //向下滑实行函数someAction1,向上滑实行函数someAction2
  491. //向左滑实行函数someAction1,向右滑实行函数someAction2
  492. distanceX < 0 ? func("left") : func("right");
  493. startX = endX;
  494. startY = endY;
  495. }
  496. }
  497. // console.log("endX:"+endX+","+"endY:"+endY);
  498. });
  499. body.addEventListener("touchend", function (event) {
  500. // distanceX = endX - startX;
  501. // distanceY = endY - startY;
  502. // // console.log("distanceX:"+distanceX+","+"distanceY:"+distanceY);
  503. // //移动端设备的屏幕宽度
  504. // var clientHeight = document.documentElement.clientHeight;
  505. // // console.log(clientHeight;*0.2);
  506. // //判断是否滑动了,而不是屏幕上单击了
  507. // if (startY != Math.abs(distanceY)) {
  508. // //在滑动的距离超过屏幕高度的20%时,做某种操作
  509. // if (Math.abs(distanceY) > clientHeight * 0.2) {
  510. // //向下滑实行函数someAction1,向上滑实行函数someAction2
  511. // distanceY < 0 ? someAction1() : someAction2();
  512. // }
  513. // }
  514. startX = 0;
  515. startY = 0;
  516. endX = 0;
  517. endY = 0;
  518. distanceX = 0;
  519. distanceY = 0;
  520. });
  521. },
  522. // 禁用/开启 操作
  523. controlCZ(bool) {
  524. globalVariable.viewer.scene.screenSpaceCameraController.enableLook = bool;
  525. globalVariable.viewer.scene.screenSpaceCameraController.enableRotate =
  526. bool;
  527. globalVariable.viewer.scene.screenSpaceCameraController.enableTilt = bool;
  528. globalVariable.viewer.scene.screenSpaceCameraController.enableTranslate =
  529. bool;
  530. globalVariable.viewer.scene.screenSpaceCameraController.enableZoom = bool;
  531. },
  532. // 添加地图底图瓦片
  533. addMapTiles(key) {
  534. let viewer = globalVariable.viewer;
  535. switch (key) {
  536. case "tdt":
  537. // 加载天地图影像
  538. viewer.imageryLayers.addImageryProvider(
  539. new Cesium.WebMapTileServiceImageryProvider({
  540. url:
  541. "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=" +
  542. systemConfig.tdt_tk,
  543. // 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,
  544. layer: "img",
  545. style: "default",
  546. tileMatrixSetID: "w",
  547. format: "image/jpeg",
  548. subdomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
  549. tileMatrixSetID: "GoogleMapsCompatible",
  550. show: true,
  551. minimumLevel: 1,
  552. maximumLevel: 18,
  553. // rectangle: Cesium.Rectangle.fromDegrees(90, -90, 180, -180),
  554. })
  555. );
  556. //加载影像注记
  557. viewer.imageryLayers.addImageryProvider(
  558. new Cesium.WebMapTileServiceImageryProvider({
  559. url:
  560. "http://t{s}.tianditu.gov.cn/cia_w/wmts?tk=" +
  561. systemConfig.tdt_tk,
  562. layer: "cia",
  563. style: "default",
  564. tileMatrixSetID: "w",
  565. format: "tiles",
  566. subdomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
  567. maximumLevel: 20,
  568. })
  569. );
  570. break;
  571. case "xq":
  572. viewer.imageryLayers.addImageryProvider(
  573. new Cesium.UrlTemplateImageryProvider({
  574. url: "http://119.3.233.75/tile/v1.0/gr?l={z}&x={x}&y={y}",
  575. minimumLevel: 1,
  576. maximumLevel: 19,
  577. format: "png",
  578. })
  579. );
  580. break;
  581. case "arcgis":
  582. // 加载ArcGIS在线地图
  583. viewer.imageryLayers.addImageryProvider(
  584. new Cesium.ArcGisMapServerImageryProvider({
  585. url: "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer",
  586. })
  587. );
  588. break;
  589. default:
  590. break;
  591. }
  592. viewer = null;
  593. },
  594. // 默认定位
  595. setViewDefaultlocation() {
  596. return new Promise((resolve, reject) => {
  597. this.$flyTo({
  598. lon: systemConfig.mapDefault.center.lon,
  599. lat: systemConfig.mapDefault.center.lat,
  600. h: systemConfig.mapDefault.height,
  601. heading: systemConfig.mapDefault.heading,
  602. pitch: systemConfig.mapDefault.pitch,
  603. roll: systemConfig.mapDefault.roll,
  604. time: 1,
  605. pitchAdjustHeight: 1000,
  606. callback: null,
  607. }).then(() => {
  608. resolve();
  609. });
  610. });
  611. },
  612. flyTo(item) {
  613. return new Promise((resolve, reject) => {
  614. globalVariable.viewer.camera.flyTo({
  615. destination: Cesium.Cartesian3.fromDegrees(
  616. item.lon,
  617. item.lat,
  618. item.h
  619. ),
  620. orientation: {
  621. heading: Cesium.Math.toRadians(item.heading), // 方向
  622. pitch: Cesium.Math.toRadians(item.pitch), // 倾斜角度
  623. roll: Cesium.Math.toRadians(item.roll),
  624. },
  625. duration: isNaN(item.time) ? 2 : item.time,
  626. pitchAdjustHeight: item.pitchAdjustHeight || 1000,
  627. complete: function () {
  628. if (item) {
  629. if (item.callback) item.callback(item);
  630. }
  631. resolve();
  632. },
  633. });
  634. });
  635. },
  636. // cesium 球体配置
  637. mapConfig() {
  638. // 大气效果(发光)
  639. globalVariable.viewer.scene.globe.showGroundAtmosphere = false;
  640. // 是否将地球渲染为半透明的球体
  641. globalVariable.viewer.scene.globe.translucency.enabled = true;
  642. // 基础球体颜色
  643. globalVariable.viewer.scene.globe.baseColor = Cesium.Color.TRANSPARENT;
  644. // 地底颜色
  645. globalVariable.viewer.scene.globe.undergroundColor = undefined;
  646. // 开启场景光照
  647. // globalVariable.viewer.scene.globe.enableLighting = true;
  648. // 控制太阳光
  649. globalVariable.viewer.scene.sun.show = systemConfig.sunShow;
  650. // 控制阴影
  651. globalVariable.viewer.shadows = systemConfig.shadows;
  652. // 阴影强度
  653. globalVariable.viewer.shadowMap.darkness = systemConfig.shadowMapDarkness;
  654. // globalVariable.viewer.terrainShadows = Cesium.ShadowMode.RECEIVE_ONLY;
  655. // // globalVariable.viewer.shadowMap.softShadows = truee
  656. // globalVariable.viewer.shadowMap.darkness = 0.7; //阴影透明度--越大越透明
  657. if (systemConfig.DirectionalLightShow) {
  658. globalVariable.viewer.scene.light = new Cesium.DirectionalLight({
  659. color: new Cesium.Color(
  660. systemConfig.DirectionalLightColor.r,
  661. systemConfig.DirectionalLightColor.g,
  662. systemConfig.DirectionalLightColor.b,
  663. systemConfig.DirectionalLightColor.a
  664. ),
  665. // //去除时间原因影响模型颜色
  666. // direction: Cesium.Cartesian3.fromDegrees(
  667. // 121.1217914833498,
  668. // 31.154385387088624,
  669. // 2000
  670. // ),
  671. direction: new Cesium.Cartesian3(
  672. systemConfig.DirectionalLightDirection.x,
  673. systemConfig.DirectionalLightDirection.y,
  674. systemConfig.DirectionalLightDirection.z
  675. ),
  676. intensity: systemConfig.DirectionalLightIntensity,
  677. });
  678. }
  679. // globalVariable.viewer._cesiumWidget._supportsImageRenderingPixelated =
  680. // Cesium.FeatureDetection.supportsImageRenderingPixelated();
  681. // globalVariable.viewer._cesiumWidget._forceResize = true;
  682. // 解决抗锯齿问题
  683. // // 方法一
  684. // if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {
  685. // //判断是否支持图像渲染像素化处理
  686. // var vtxf_dpr = window.devicePixelRatio;
  687. // // 适度降低分辨率
  688. // while (vtxf_dpr >= 2.0) {
  689. // vtxf_dpr /= 2.0;
  690. // }
  691. // //alert(dpr);
  692. // globalVariable.viewer.resolutionScale = vtxf_dpr;
  693. // }
  694. // 方法二
  695. if (Cesium.FeatureDetection.supportsImageRenderingPixelated()) {
  696. //判断是否支持图像渲染像素化处理
  697. var vtxf_dpr = window.devicePixelRatio;
  698. globalVariable.viewer.resolutionScale = vtxf_dpr;
  699. }
  700. // //是否开启抗锯齿
  701. globalVariable.viewer.scene.fxaa = systemConfig.fxaa;
  702. globalVariable.viewer.scene.postProcessStages.fxaa.enabled =
  703. systemConfig.fxaaEnabled;
  704. // // 天空盒隐藏
  705. // globalVariable.viewer.scene.skyBox.show = false;
  706. // 配置天空盒子
  707. this.deploySkyBox();
  708. // // 地形遮盖
  709. // globe.depthTestAgainstTerrain = false;
  710. // let inter = setInterval(() => {
  711. // // 改变时间设置光照效果
  712. // // let date = new Date().getTime();
  713. // let utc = Cesium.JulianDate.fromDate(new Date("2022-06-22"));
  714. // //北京时间=UTC+8=GMT+8 不用加8
  715. // viewer.clockViewModel.currentTime = Cesium.JulianDate.addHours(
  716. // utc,
  717. // 0,
  718. // new Cesium.JulianDate()
  719. // );
  720. // }, 100);
  721. // globe.translucency.frontFaceAlpha = 1.0;
  722. // globe.translucency.rectangle = Cesium.Rectangle.fromDegrees(
  723. // 120.87373270003363,
  724. // 27.913116219448348,
  725. // 120.98856425530658,
  726. // 27.97741914289562
  727. // );
  728. // // 地下模式
  729. // viewer.scene.screenSpaceCameraController.enableCollisionDetection = true ;
  730. // viewer.scene.undergroundMode = true;
  731. // // 设置地表透明度
  732. // viewer.scene.globe.translucency.frontFaceAlpha = 0
  733. // viewer.scene.globe.depthTestAgainstTerrain = true;
  734. // viewer.scene.debugShowFramesPerSecond = true;
  735. // viewer.shadows = true;
  736. // // viewer.shadowMap.softShadows = true
  737. // viewer.shadowMap.darkness = 0.7; //阴影透明度--越大越透明
  738. // // 改变时间设置光照效果
  739. // var utc = Cesium.JulianDate.fromDate(new Date("2021/07/04 08:00:00"));
  740. // //北京时间=UTC+8=GMT+8
  741. // viewer.clockViewModel.currentTime = Cesium.JulianDate.addHours(
  742. // utc,
  743. // 8,
  744. // new Cesium.JulianDate()
  745. // );
  746. },
  747. // 限制camera的移动范围
  748. bindLimitCameraFunc() {
  749. // globalVariable.viewer.scene.preRender.addEventListener(function () {});
  750. // viewer.scene.screenSpaceCameraController.maximumZoomDistance = 20000;
  751. // viewer.scene.screenSpaceCameraController.minimumZoomDistance = 10;
  752. globalVariable.viewer.camera.changed.addEventListener(
  753. this.limitCameraFunc
  754. );
  755. },
  756. unbindLimitCameraFunc() {
  757. globalVariable.viewer.camera.changed.removeEventListener(
  758. this.limitCameraFunc
  759. );
  760. },
  761. limitCameraFunc() {
  762. let that = this;
  763. if (!this.correctCamera) {
  764. this.getNowCameraPosition()
  765. .then((result) => {
  766. let cameraLon = result.result.lon;
  767. let cameraLat = result.result.lat;
  768. let cameraHeight = result.result.h;
  769. // systemConfig.mapDefault.bbox.west;
  770. // systemConfig.mapDefault.bbox.east;
  771. // systemConfig.mapDefault.bbox.north;
  772. // systemConfig.mapDefault.bbox.south;
  773. if (
  774. cameraLon > systemConfig.mapDefault.bbox.east ||
  775. cameraLon < systemConfig.mapDefault.bbox.west ||
  776. cameraLat > systemConfig.mapDefault.bbox.north ||
  777. cameraLat < systemConfig.mapDefault.bbox.south ||
  778. cameraHeight > systemConfig.mapDefault.defaultH
  779. ) {
  780. that.correctCamera = true;
  781. that.setViewDefaultlocation().then(() => {
  782. huifu();
  783. });
  784. }
  785. cameraLon = null;
  786. cameraLat = null;
  787. cameraHeight = null;
  788. })
  789. .catch((err) => {});
  790. }
  791. function huifu() {
  792. that.correctCamera = false;
  793. }
  794. },
  795. // 配置天空盒
  796. deploySkyBox() {
  797. // 自定义的近地天空盒
  798. let groundSkybox = new Cesium.GroundSkyBox({
  799. sources: {
  800. negativeX: "./static/images/skybox/Left.jpg",
  801. negativeY: "./static/images/skybox/Front.jpg",
  802. negativeZ: "./static/images/skybox/Down.jpg",
  803. positiveX: "./static/images/skybox/Right.jpg",
  804. positiveY: "./static/images/skybox/Back.jpg",
  805. positiveZ: "./static/images/skybox/Up.jpg",
  806. },
  807. });
  808. // // 自带的默认天空盒
  809. // let defaultSkybox = viewer.scene.skyBox;
  810. globalVariable.viewer.scene.skyBox = groundSkybox;
  811. globalVariable.viewer.scene.skyAtmosphere.show = false;
  812. // // 监听并判断相机位置,切换天空盒
  813. // globalVariable.viewer.scene.preUpdate.addEventListener(() => {
  814. // let position = viewer.scene.camera.position;
  815. // let cameraHeight = Cesium.Cartographic.fromCartesian(position).height;
  816. // if (cameraHeight < 240000) {
  817. // viewer.scene.skyBox = groundSkybox;
  818. // viewer.scene.skyAtmosphere.show = false;
  819. // } else {
  820. // viewer.scene.skyBox = defaultSkybox;
  821. // viewer.scene.skyAtmosphere.show = true;
  822. // }
  823. // });
  824. },
  825. // 获取当前camera的详细位置
  826. getNowCameraPosition() {
  827. let that = this;
  828. return new Promise((resolve, reject) => {
  829. var camera = globalVariable.viewer.camera;
  830. var heading = Cesium.Math.toDegrees(
  831. globalVariable.viewer.camera.heading
  832. );
  833. var pitch = Cesium.Math.toDegrees(globalVariable.viewer.camera.pitch); //Cesium.Math.toDegrees作用是把弧度转换成度数
  834. var roll = Cesium.Math.toDegrees(globalVariable.viewer.camera.roll);
  835. var h = globalVariable.viewer.camera.positionCartographic.height;
  836. var camera = globalVariable.viewer.camera.position;
  837. var position = Cesium.Cartographic.fromCartesian(camera);
  838. var lon = Cesium.Math.toDegrees(position.longitude);
  839. var lat = Cesium.Math.toDegrees(position.latitude);
  840. console.log(heading)
  841. console.log(pitch)
  842. console.log(roll)
  843. console.log(lon)
  844. console.log(lat)
  845. console.log(h)
  846. let str = `
  847. lon:${lon}
  848. lat:${lat}
  849. h:${h}
  850. heading:${heading}
  851. pitch:${pitch}
  852. roll:${roll}
  853. `;
  854. resolve({
  855. str: "",
  856. result: {
  857. lon: lon,
  858. lat: lat,
  859. h: h,
  860. heading: heading,
  861. pitch: pitch,
  862. roll: roll,
  863. },
  864. });
  865. });
  866. // that.showInfoDailog(str);
  867. },
  868. // 地图(地球表面,无地形)左击事件
  869. singleClick() {
  870. var handler = new Cesium.ScreenSpaceEventHandler(
  871. globalVariable.viewer.scene.canvas
  872. );
  873. handler.setInputAction(function (event) {
  874. var earthPosition = globalVariable.viewer.camera.pickEllipsoid(
  875. event.position,
  876. globalVariable.viewer.scene.globe.ellipsoid
  877. );
  878. var cartographic = Cesium.Cartographic.fromCartesian(
  879. earthPosition,
  880. globalVariable.viewer.scene.globe.ellipsoid,
  881. new Cesium.Cartographic()
  882. );
  883. var lat = Cesium.Math.toDegrees(cartographic.latitude);
  884. var lng = Cesium.Math.toDegrees(cartographic.longitude);
  885. var height = cartographic.height;
  886. console.log(lng + "," + lat);
  887. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  888. },
  889. // 地图(模型上)左击事件
  890. singleClick2() {
  891. let that = this;
  892. var handler = new Cesium.ScreenSpaceEventHandler(
  893. globalVariable.viewer.scene.canvas
  894. );
  895. handler.setInputAction(function (event) {
  896. var pick = globalVariable.viewer.scene.pickPosition(event.position);
  897. var pickModel = globalVariable.viewer.scene.pick(event.position);
  898. if (pickModel && pick && !pickModel.id) {
  899. var height = Cesium.Cartographic.fromCartesian(pick).height;
  900. var lat = Cesium.Math.toDegrees(
  901. Cesium.Cartographic.fromCartesian(pick).latitude
  902. );
  903. var lon = Cesium.Math.toDegrees(
  904. Cesium.Cartographic.fromCartesian(pick).longitude
  905. );
  906. // cartesian = Cesium.Cartesian3.fromDegrees(lng, lat, height);
  907. // console.log("模型高度点", cartesian);
  908. let str = `
  909. lon:${lon}
  910. lat:${lat}
  911. height:${height}
  912. `;
  913. that.showInfoDailog(
  914. JSON.stringify({
  915. lon: lon,
  916. lat: lat,
  917. h: height,
  918. })
  919. .replaceAll("{", "")
  920. .replaceAll("}", "")
  921. );
  922. }
  923. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  924. },
  925. showInfoDailog(str) {
  926. this.dialogVisible = true;
  927. this.dialogInfoStr = str;
  928. },
  929. hideInfoDailog() {
  930. this.dialogVisible = false;
  931. },
  932. // 加载顶部东线动线特效
  933. addAnimatedLineToHousetop() {},
  934. // 加载飞线
  935. addFlyLine() {
  936. let that = this;
  937. this.topK.map(function (item) {
  938. let startPoint = item;
  939. let endPoint = Object.assign({}, startPoint);
  940. endPoint.h = getRandom(199, 200);
  941. let positions = [
  942. startPoint.lon,
  943. startPoint.lat,
  944. 0,
  945. endPoint.lon,
  946. endPoint.lat,
  947. endPoint.h,
  948. ];
  949. addLine(positions);
  950. });
  951. // for (var j = 0; j < 50; ++j) {
  952. // let startPoint = randomPoint();
  953. // let endPoint = Object.assign({}, startPoint);
  954. // endPoint.h = getRandom(199, 200);
  955. // // this.addFlyingLineByEntity(
  956. // // Cesium.Cartesian3.fromDegreesArrayHeights([
  957. // // startPoint.lon,
  958. // // startPoint.lat,
  959. // // startPoint.h,
  960. // // endPoint.lon,
  961. // // endPoint.lat,
  962. // // endPoint.h,
  963. // // ])
  964. // // );
  965. // // continue;
  966. // }
  967. function addLine(positions) {
  968. // 创建长方体对象
  969. const PolylineGeometry = new Cesium.PolylineGeometry({
  970. positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
  971. width: 2,
  972. });
  973. const instance = new Cesium.GeometryInstance({
  974. geometry: PolylineGeometry,
  975. });
  976. // this.flylineObj.push(
  977. globalVariable.viewer.scene.primitives.add(
  978. new Cesium.Primitive({
  979. geometryInstances: [instance],
  980. appearance: that.getFlylineMaterial(1),
  981. depthFailAppearance: that.getFlylineMaterial(1),
  982. releaseGeometryInstances: false,
  983. compressVertices: false,
  984. })
  985. );
  986. // );
  987. }
  988. function randomPoint() {
  989. var jingd = 1000000;
  990. var jd =
  991. getRandom(
  992. systemConfig.mapDefault.bbox.west * jingd,
  993. systemConfig.mapDefault.bbox.east * jingd
  994. ) / jingd;
  995. var wd =
  996. getRandom(
  997. systemConfig.mapDefault.bbox.south * jingd,
  998. systemConfig.mapDefault.bbox.north * jingd
  999. ) / jingd;
  1000. return {
  1001. lon: jd,
  1002. lat: wd,
  1003. h: 0,
  1004. };
  1005. }
  1006. function getRandom(t, e) {
  1007. return Math.floor(Math.random() * (e - t + 1) + t);
  1008. }
  1009. },
  1010. // 创建飞线材质 1
  1011. getFlylineMaterial(index) {
  1012. // 创建材质,在MaterialAppearance中若不添加基础材质,模型将会透明
  1013. let material = new Cesium.Material.fromType("Color");
  1014. material.uniforms.color = Cesium.Color.ORANGE;
  1015. let fragmentShaderSource;
  1016. if (index === 1) {
  1017. // 飞线效果-飞线间隔,宽度2
  1018. fragmentShaderSource = `
  1019. varying vec2 v_st;
  1020. varying float v_width;
  1021. varying float v_polylineAngle;
  1022. varying vec4 v_positionEC;
  1023. varying vec3 v_normalEC;
  1024. void main()
  1025. {
  1026. vec2 st = v_st;
  1027. float xx = fract(st.s*2.0 - czm_frameNumber/60.0);
  1028. float r = xx;
  1029. float g = 200.0;
  1030. float b = 200.0;
  1031. float a = xx;
  1032. gl_FragColor = vec4(r,g,b,a);
  1033. }
  1034. `;
  1035. } else if (index === 2) {
  1036. fragmentShaderSource = `
  1037. varying vec2 v_st;
  1038. varying float v_width;
  1039. varying float v_polylineAngle;
  1040. varying vec4 v_positionEC;
  1041. varying vec3 v_normalEC;
  1042. void main()
  1043. {
  1044. vec2 st = v_st;
  1045. float xx = fract(st.s*2.0 - czm_frameNumber/60.0);
  1046. float r = xx;
  1047. float g = sin(czm_frameNumber/30.0);
  1048. float b = cos(czm_frameNumber/30.0);
  1049. float a = xx;
  1050. gl_FragColor = vec4(r,g,b,a);
  1051. }
  1052. `;
  1053. } else if (index === 3) {
  1054. fragmentShaderSource = `
  1055. varying vec2 v_st;
  1056. varying float v_width;
  1057. varying float v_polylineAngle;
  1058. varying vec4 v_positionEC;
  1059. varying vec3 v_normalEC;
  1060. void main()
  1061. {
  1062. vec2 st = v_st;
  1063. float xx = sin(st.s*6.0 -czm_frameNumber/5.0) - cos(st.t*6.0);
  1064. float r = 0.0;
  1065. float g = xx;
  1066. float b = xx;
  1067. float a = xx;
  1068. gl_FragColor = vec4(r,g,b,a);
  1069. }
  1070. `;
  1071. } else if (index === 4) {
  1072. fragmentShaderSource = `
  1073. varying vec2 v_st;
  1074. varying float v_width;
  1075. varying float v_polylineAngle;
  1076. varying vec4 v_positionEC;
  1077. varying vec3 v_normalEC;
  1078. void main()
  1079. {
  1080. vec2 st = v_st;
  1081. float xx = fract(st.s*10.0 + st.t - czm_frameNumber/60.0);
  1082. if (st.t<0.5) {
  1083. xx = fract(st.s*10.0 - st.t - czm_frameNumber/60.0);
  1084. }
  1085. float r = 0.0;
  1086. float g = xx;
  1087. float b = xx;
  1088. float a = xx;
  1089. if (st.t>0.8||st.t<0.2) {
  1090. g = 1.0;
  1091. b = 1.0;
  1092. a = 0.4;
  1093. }
  1094. gl_FragColor = vec4(r,g,b,a);
  1095. }
  1096. `;
  1097. }
  1098. // 自定义材质
  1099. const aper = new Cesium.PolylineMaterialAppearance({
  1100. material: material,
  1101. translucent: true,
  1102. vertexShaderSource: `
  1103. #define CLIP_POLYLINE
  1104. void clipLineSegmentToNearPlane(
  1105. vec3 p0,
  1106. vec3 p1,
  1107. out vec4 positionWC,
  1108. out bool clipped,
  1109. out bool culledByNearPlane,
  1110. out vec4 clippedPositionEC)
  1111. {
  1112. culledByNearPlane = false;
  1113. clipped = false;
  1114. vec3 p0ToP1 = p1 - p0;
  1115. float magnitude = length(p0ToP1);
  1116. vec3 direction = normalize(p0ToP1);
  1117. float endPoint0Distance = czm_currentFrustum.x + p0.z;
  1118. float denominator = -direction.z;
  1119. if (endPoint0Distance > 0.0 && abs(denominator) < czm_epsilon7)
  1120. {
  1121. culledByNearPlane = true;
  1122. }
  1123. else if (endPoint0Distance > 0.0)
  1124. {
  1125. float t = endPoint0Distance / denominator;
  1126. if (t < 0.0 || t > magnitude)
  1127. {
  1128. culledByNearPlane = true;
  1129. }
  1130. else
  1131. {
  1132. p0 = p0 + t * direction;
  1133. p0.z = min(p0.z, -czm_currentFrustum.x);
  1134. clipped = true;
  1135. }
  1136. }
  1137. clippedPositionEC = vec4(p0, 1.0);
  1138. positionWC = czm_eyeToWindowCoordinates(clippedPositionEC);
  1139. }
  1140. vec4 getPolylineWindowCoordinatesEC(vec4 positionEC, vec4 prevEC, vec4 nextEC, float expandDirection, float width, bool usePrevious, out float angle)
  1141. {
  1142. #ifdef POLYLINE_DASH
  1143. vec4 positionWindow = czm_eyeToWindowCoordinates(positionEC);
  1144. vec4 previousWindow = czm_eyeToWindowCoordinates(prevEC);
  1145. vec4 nextWindow = czm_eyeToWindowCoordinates(nextEC);
  1146. vec2 lineDir;
  1147. if (usePrevious) {
  1148. lineDir = normalize(positionWindow.xy - previousWindow.xy);
  1149. }
  1150. else {
  1151. lineDir = normalize(nextWindow.xy - positionWindow.xy);
  1152. }
  1153. angle = atan(lineDir.x, lineDir.y) - 1.570796327;
  1154. angle = floor(angle / czm_piOverFour + 0.5) * czm_piOverFour;
  1155. #endif
  1156. vec4 clippedPrevWC, clippedPrevEC;
  1157. bool prevSegmentClipped, prevSegmentCulled;
  1158. clipLineSegmentToNearPlane(prevEC.xyz, positionEC.xyz, clippedPrevWC, prevSegmentClipped, prevSegmentCulled, clippedPrevEC);
  1159. vec4 clippedNextWC, clippedNextEC;
  1160. bool nextSegmentClipped, nextSegmentCulled;
  1161. clipLineSegmentToNearPlane(nextEC.xyz, positionEC.xyz, clippedNextWC, nextSegmentClipped, nextSegmentCulled, clippedNextEC);
  1162. bool segmentClipped, segmentCulled;
  1163. vec4 clippedPositionWC, clippedPositionEC;
  1164. clipLineSegmentToNearPlane(positionEC.xyz, usePrevious ? prevEC.xyz : nextEC.xyz, clippedPositionWC, segmentClipped, segmentCulled, clippedPositionEC);
  1165. if (segmentCulled)
  1166. {
  1167. return vec4(0.0, 0.0, 0.0, 1.0);
  1168. }
  1169. vec2 directionToPrevWC = normalize(clippedPrevWC.xy - clippedPositionWC.xy);
  1170. vec2 directionToNextWC = normalize(clippedNextWC.xy - clippedPositionWC.xy);
  1171. if (prevSegmentCulled)
  1172. {
  1173. directionToPrevWC = -directionToNextWC;
  1174. }
  1175. else if (nextSegmentCulled)
  1176. {
  1177. directionToNextWC = -directionToPrevWC;
  1178. }
  1179. vec2 thisSegmentForwardWC, otherSegmentForwardWC;
  1180. if (usePrevious)
  1181. {
  1182. thisSegmentForwardWC = -directionToPrevWC;
  1183. otherSegmentForwardWC = directionToNextWC;
  1184. }
  1185. else
  1186. {
  1187. thisSegmentForwardWC = directionToNextWC;
  1188. otherSegmentForwardWC = -directionToPrevWC;
  1189. }
  1190. vec2 thisSegmentLeftWC = vec2(-thisSegmentForwardWC.y, thisSegmentForwardWC.x);
  1191. vec2 leftWC = thisSegmentLeftWC;
  1192. float expandWidth = width * 0.5;
  1193. if (!czm_equalsEpsilon(prevEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1) && !czm_equalsEpsilon(nextEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1))
  1194. {
  1195. vec2 otherSegmentLeftWC = vec2(-otherSegmentForwardWC.y, otherSegmentForwardWC.x);
  1196. vec2 leftSumWC = thisSegmentLeftWC + otherSegmentLeftWC;
  1197. float leftSumLength = length(leftSumWC);
  1198. leftWC = leftSumLength < czm_epsilon6 ? thisSegmentLeftWC : (leftSumWC / leftSumLength);
  1199. vec2 u = -thisSegmentForwardWC;
  1200. vec2 v = leftWC;
  1201. float sinAngle = abs(u.x * v.y - u.y * v.x);
  1202. expandWidth = clamp(expandWidth / sinAngle, 0.0, width * 2.0);
  1203. }
  1204. vec2 offset = leftWC * expandDirection * expandWidth * czm_pixelRatio;
  1205. return vec4(clippedPositionWC.xy + offset, -clippedPositionWC.z, 1.0) * (czm_projection * clippedPositionEC).w;
  1206. }
  1207. vec4 getPolylineWindowCoordinates(vec4 position, vec4 previous, vec4 next, float expandDirection, float width, bool usePrevious, out float angle)
  1208. {
  1209. vec4 positionEC = czm_modelViewRelativeToEye * position;
  1210. vec4 prevEC = czm_modelViewRelativeToEye * previous;
  1211. vec4 nextEC = czm_modelViewRelativeToEye * next;
  1212. return getPolylineWindowCoordinatesEC(positionEC, prevEC, nextEC, expandDirection, width, usePrevious, angle);
  1213. }
  1214. attribute vec3 position3DHigh;
  1215. attribute vec3 position3DLow;
  1216. attribute vec3 prevPosition3DHigh;
  1217. attribute vec3 prevPosition3DLow;
  1218. attribute vec3 nextPosition3DHigh;
  1219. attribute vec3 nextPosition3DLow;
  1220. attribute vec2 expandAndWidth;
  1221. attribute vec2 st;
  1222. attribute float batchId;
  1223. varying float v_width;
  1224. varying vec2 v_st;
  1225. varying float v_polylineAngle;
  1226. varying vec4 v_positionEC;
  1227. varying vec3 v_normalEC;
  1228. void main()
  1229. {
  1230. float expandDir = expandAndWidth.x;
  1231. float width = abs(expandAndWidth.y) + 0.5;
  1232. bool usePrev = expandAndWidth.y < 0.0;
  1233. vec4 p = czm_computePosition();
  1234. vec4 prev = czm_computePrevPosition();
  1235. vec4 next = czm_computeNextPosition();
  1236. float angle;
  1237. vec4 positionWC = getPolylineWindowCoordinates(p, prev, next, expandDir, width, usePrev, angle);
  1238. gl_Position = czm_viewportOrthographic * positionWC;
  1239. v_width = width;
  1240. v_st.s = st.s;
  1241. v_st.t = st.t;
  1242. // v_st.t = czm_writeNonPerspective(st.t, gl_Position.w);
  1243. v_polylineAngle = angle;
  1244. vec4 eyePosition = czm_modelViewRelativeToEye * p;
  1245. v_positionEC = czm_inverseModelView * eyePosition; // position in eye coordinates
  1246. //v_normalEC = czm_normal * normal; // normal in eye coordinates
  1247. }
  1248. `,
  1249. fragmentShaderSource: fragmentShaderSource,
  1250. });
  1251. return aper;
  1252. },
  1253. // 添加水面
  1254. addWaterPanel() {
  1255. let d = [];
  1256. for (let i = 0; i < systemConfig.water.length; i += 2) {
  1257. let x = systemConfig.water[i];
  1258. let y = systemConfig.water[i + 1];
  1259. d.push(x);
  1260. d.push(y);
  1261. d.push(1);
  1262. }
  1263. let geometry = new Cesium.PolygonGeometry({
  1264. polygonHierarchy: new Cesium.PolygonHierarchy(
  1265. Cesium.Cartesian3.fromRadiansArrayHeights(d)
  1266. ),
  1267. height: -2,
  1268. });
  1269. let waterFace = this.waterObj.create(geometry, {
  1270. // normalMap: "img/textures/waterNormals.jpg", // 水正常扰动的法线图
  1271. frequency: 8000.0, // 控制波数的数字。
  1272. animationSpeed: 0.02, // 控制水的动画速度的数字。
  1273. amplitude: 5.0, // 控制水波振幅的数字。
  1274. specularIntensity: 0.8, // 控制镜面反射强度的数字。
  1275. baseWaterColor: "#006ab4", // rgba颜色对象基础颜色的水。#00ffff,#00baff,#006ab4
  1276. blendColor: "#006ab4", // 从水中混合到非水域时使用的rgba颜色对象。
  1277. // height: 100, //水面高度
  1278. clampToGround: true, //是否贴地
  1279. opacity: 0.7, //透明度
  1280. });
  1281. globalVariable.viewer.scene.primitives.add(waterFace);
  1282. },
  1283. // 添加树木
  1284. addTree() {
  1285. let keys = Object.keys(systemConfig.tree);
  1286. keys.map(function (key, index) {
  1287. let treeObj = systemConfig.tree[key];
  1288. for (let i = 0; i < treeObj.positions.length; i += 2) {
  1289. const x = treeObj.positions[i];
  1290. const y = treeObj.positions[i + 1];
  1291. let position = Cesium.Cartesian3.fromRadians(x, y, 0);
  1292. globalVariable.viewer.entities.add({
  1293. // 设置方向
  1294. // orientation: orientation,
  1295. position: position,
  1296. model: {
  1297. // 引入模型
  1298. uri:
  1299. systemConfig.dataUrl +
  1300. systemConfig.gltfConfig +
  1301. "/" +
  1302. treeObj.name +
  1303. ".gltf",
  1304. // 模型的近似最小像素大小,而不考虑缩放。这可以用来确保即使观看者缩小也可以看到模型。如果为0.0,则不强制使用最小大小
  1305. minimumPixelSize: 0,
  1306. // // 模型的颜色(与模型的渲染颜色混合的属性)
  1307. // color: Cesium.Color.WHITE.withAlpha(1),
  1308. // 模型的最大比例大小
  1309. maximumScale: 2000,
  1310. // // 设置模型轮廓(边框)颜色
  1311. // silhouetteColor: Cesium.Color.BLACK,
  1312. // // 设置模型轮廓(边框)大小
  1313. // silhouetteSize: 2,
  1314. // // 是否执行模型动画
  1315. // runAnimations: true,
  1316. // 应用于图像的统一比例。比例大于会1.0放大标签,而比例小于会1.0缩小标签。
  1317. scale: 1.0,
  1318. // 是否显示
  1319. show: true,
  1320. },
  1321. });
  1322. }
  1323. });
  1324. },
  1325. // 加载3DTiles数据
  1326. add3DTilesData(url, options) {
  1327. if (!options) {
  1328. options = {
  1329. show: true,
  1330. light: 1,
  1331. matrix: null,
  1332. };
  1333. } else {
  1334. options.show = typeof options.show == "boolean" ? options.show : true;
  1335. options.light = isNaN(options.light) ? 1 : options.light;
  1336. }
  1337. let that = this;
  1338. // let pointLight = this.pointLight();
  1339. let tileset = new Cesium.Cesium3DTileset({
  1340. url: url,
  1341. // skipLevelOfDetail: true, //开启跳级加载
  1342. // preferLeaves: true,
  1343. // shadows: Cesium.ShadowMode.DISABLED,
  1344. // maximumScreenSpaceError: 256,
  1345. // maximumNumberOfLoadedTiles: 500,
  1346. // maximumMemoryUsage: 128, //tileset可以使用的最大内存
  1347. show: options.show,
  1348. // immediatelyLoadDesiredLevelOfDetail: true,
  1349. // progressiveResolutionHeightFraction: 0.5, // 数值偏于0能够让初始加载变得模糊
  1350. // dynamicScreenSpaceErrorDensity: 1, // 数值加大,能让周边加载变快
  1351. // dynamicScreenSpaceErrorFactor: 1, // 不知道起了什么作用没,反正放着吧先
  1352. // dynamicScreenSpaceError: true, // 根据测试,有了这个后,会在真正的全屏加载完之后才清晰化房屋
  1353. // customShader: pointLight,
  1354. // imageBasedLighting:,
  1355. // lightColor: new Cesium.Cartesian3(
  1356. // options.light,
  1357. // options.light,
  1358. // options.light
  1359. // ),
  1360. });
  1361. globalVariable.viewer.scene.primitives.add(tileset);
  1362. tileset.readyPromise.then(function () {
  1363. if (options.matrix)
  1364. tileset.root.transform = that.createMatrix4(options.matrix);
  1365. // globalVariable.viewer.zoomTo(tileset);
  1366. });
  1367. // tileset.tileLoad.addEventListener(function (tile) {
  1368. // let content = tile.content;
  1369. // let featuresLength = content.featuresLength;
  1370. // console.log("要素数量为:");
  1371. // console.log(featuresLength);
  1372. // console.log("第一个要素为:");
  1373. // let feature = content.getFeature(0);
  1374. // console.log(feature);
  1375. // });
  1376. return tileset;
  1377. },
  1378. // 创建偏移矩阵
  1379. createMatrix4(matrixParam, defaultModelMatrix) {
  1380. let tileModelTool = matrixParam;
  1381. var mx = Cesium.Matrix3.fromRotationX(
  1382. Cesium.Math.toRadians(tileModelTool.rx)
  1383. );
  1384. var my = Cesium.Matrix3.fromRotationY(
  1385. Cesium.Math.toRadians(tileModelTool.ry)
  1386. );
  1387. var mz = Cesium.Matrix3.fromRotationZ(
  1388. Cesium.Math.toRadians(tileModelTool.rz)
  1389. );
  1390. var rotationX = Cesium.Matrix4.fromRotationTranslation(mx);
  1391. var rotationY = Cesium.Matrix4.fromRotationTranslation(my);
  1392. var rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
  1393. var m;
  1394. if (defaultModelMatrix) {
  1395. m = defaultModelMatrix;
  1396. } else {
  1397. //平移 修改经纬度
  1398. var position = Cesium.Cartesian3.fromDegrees(
  1399. tileModelTool.longitude,
  1400. tileModelTool.latitude,
  1401. tileModelTool.height
  1402. );
  1403. m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
  1404. }
  1405. //旋转、平移矩阵相乘
  1406. Cesium.Matrix4.multiply(m, rotationX, m);
  1407. Cesium.Matrix4.multiply(m, rotationY, m);
  1408. Cesium.Matrix4.multiply(m, rotationZ, m);
  1409. //缩放 修改缩放比例
  1410. var scale = Cesium.Matrix4.fromUniformScale(tileModelTool.scale);
  1411. Cesium.Matrix4.multiply(m, scale, m);
  1412. return m;
  1413. },
  1414. // 加载大批量gltf文件
  1415. loadBigDataGltf() {
  1416. let that = this;
  1417. globalVariable.treeArr = [];
  1418. return new Promise((resolve, reject) => {
  1419. $.getJSON("./static/data/GLTF/tree_path.json", function (array) {
  1420. //array.length
  1421. let instances = [];
  1422. for (let i = 0; i < array.length; i += 10) {
  1423. const item = array[i];
  1424. let lonlat = that.webMercator2lonlat(item.x, item.y);
  1425. globalVariable.treeArr.push(lonlat);
  1426. let modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
  1427. new Cesium.Cartesian3.fromDegrees(
  1428. lonlat[0] + 116.2026998939312,
  1429. lonlat[1] + 1.1932712598797461,
  1430. 10
  1431. ),
  1432. new Cesium.HeadingPitchRoll(0, 0, 0)
  1433. );
  1434. Cesium.Matrix4.multiplyByUniformScale(modelMatrix, 2, modelMatrix); // 缩放
  1435. instances.push({
  1436. modelMatrix: modelMatrix,
  1437. });
  1438. }
  1439. // // for (let i = 0; i < newPositions.length; i++) {
  1440. // for (let i = 0; i < 5000; i++) {
  1441. // let cartesian = newPositions[i];
  1442. // //批量加载
  1443. // let modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
  1444. // cartesian,
  1445. // new Cesium.HeadingPitchRoll(0, 0, 0)
  1446. // ); // 旋转
  1447. // }
  1448. let primitive = new Cesium.ModelInstanceCollection({
  1449. url: "./static/data/GLTF/SEWQ01.gltf",
  1450. instances: instances,
  1451. });
  1452. globalVariable.viewer.scene.primitives.add(primitive);
  1453. // globalVariable.viewer.camera.setView({
  1454. // // 4.730190106068796,26.731048740120254
  1455. // destination: newPositions[0], // 设置位置
  1456. // orientation: {
  1457. // heading: Cesium.Math.toRadians(0), // 方向
  1458. // pitch: Cesium.Math.toRadians(-90.0), // 倾斜角度
  1459. // roll: 0,
  1460. // },
  1461. // });
  1462. resolve(primitive);
  1463. });
  1464. });
  1465. },
  1466. // 点光源
  1467. pointLight() {
  1468. // 自定义光源
  1469. return new Cesium.CustomShader({
  1470. lightingModel: Cesium.LightingModel.UNLIT,
  1471. uniforms: {
  1472. u_cameraDirectionWC: {
  1473. type: Cesium.UniformType.VEC3,
  1474. value: globalVariable.viewer.scene.camera.positionWC,
  1475. },
  1476. u_lightColor1: {
  1477. type: Cesium.UniformType.VEC4,
  1478. value: new Cesium.Cartesian4(0.2, 0.2, 0.2, 0.05),
  1479. },
  1480. u_lightPos1: {
  1481. type: Cesium.UniformType.VEC3,
  1482. // 大门头顶
  1483. value: Cesium.Cartesian3.fromRadians(
  1484. 2.113986007449123,
  1485. 0.5437488254764549,
  1486. 59
  1487. ),
  1488. // 一楼门厅
  1489. // value: Cesium.Cartesian3.fromRadians(
  1490. // 2.113987467160011,
  1491. // 0.5437379383404595,
  1492. // 2,
  1493. // ),
  1494. // 门口室外
  1495. // value: Cesium.Cartesian3.fromDegrees(
  1496. // 121.122485613095,
  1497. // 31.1542436101541,
  1498. // 10.649243861995
  1499. // ),
  1500. },
  1501. // u_lightColor2: {
  1502. // type: Cesium.UniformType.VEC4,
  1503. // value: new Cesium.Cartesian4(0.2, 0.8, 0.2, 0.2),
  1504. // },
  1505. // u_lightPos2: {
  1506. // type: Cesium.UniformType.VEC3,
  1507. // value: Cesium.Cartesian3.fromRadians(
  1508. // 3.1001573234522195,
  1509. // 0.5437380338095784,
  1510. // 2.1
  1511. // ),
  1512. // },
  1513. // u_lightColor3: {
  1514. // type: Cesium.UniformType.VEC4,
  1515. // value: lightPoint3.color,
  1516. // },
  1517. // u_lightPos3: {
  1518. // type: Cesium.UniformType.VEC3,
  1519. // value: lightPoint3.postion,
  1520. // },
  1521. },
  1522. fragmentShaderText: `
  1523. vec4 makeLight(vec4 lightColorHdr,vec3 lightPos,
  1524. vec3 positionWC,vec3 positionEC,vec3 normalEC,czm_pbrParameters pbrParameters)
  1525. {
  1526. vec3 color = vec3(0.0);
  1527. float mx1 = 1.0;
  1528. vec3 light1Dir = positionWC - lightPos;
  1529. float distance1 = length(light1Dir);
  1530. if(distance1 < 60.0){
  1531. vec4 l1 = czm_view * vec4(lightPos, 1.0);
  1532. vec3 lightDirectionEC = l1.xyz - positionEC;
  1533. mx1 = 1.0 - distance1 / 60.0;
  1534. color = czm_pbrLighting(
  1535. positionEC,
  1536. normalEC,
  1537. lightDirectionEC,
  1538. lightColorHdr.xyz,
  1539. pbrParameters
  1540. ).xyz;
  1541. }
  1542. mx1 = max(color.r,max(color.g,color.b)) * pow(mx1,1.0) * 10.0;
  1543. return vec4(color,mx1);
  1544. }
  1545. void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
  1546. {
  1547. // material.diffuse = vec3(1.0);
  1548. vec3 positionWC = fsInput.attributes.positionWC;
  1549. vec3 normalEC = fsInput.attributes.normalEC;
  1550. vec3 positionEC = fsInput.attributes.positionEC;
  1551. vec3 lightColorHdr = czm_lightColorHdr;
  1552. vec3 lightDirectionEC = czm_lightDirectionEC;
  1553. lightDirectionEC = (czm_view * vec4(u_cameraDirectionWC,1.0)).xyz - positionEC;
  1554. czm_pbrParameters pbrParameters;
  1555. pbrParameters.diffuseColor = material.diffuse;
  1556. pbrParameters.f0 = vec3(0.5);
  1557. pbrParameters.roughness = 1.0;
  1558. vec3 ligth1Color0 = czm_pbrLighting(
  1559. positionEC,
  1560. normalEC,
  1561. lightDirectionEC,
  1562. lightColorHdr,
  1563. pbrParameters
  1564. );
  1565. vec4 ligth1ColorR = makeLight(u_lightColor1,u_lightPos1,positionWC,positionEC,normalEC,pbrParameters);
  1566. // vec4 ligth1ColorG = makeLight(u_lightColor2,u_lightPos2,positionWC,positionEC,normalEC,pbrParameters);
  1567. vec3 finalColor = mix(material.diffuse.rgb, ligth1ColorR.rgb, ligth1ColorR.a);
  1568. // finalColor = mix(finalColor, ligth1ColorG.rgb, ligth1ColorG.a);
  1569. material.diffuse = finalColor;
  1570. // material.ambient = finalColor;
  1571. }
  1572. `,
  1573. });
  1574. },
  1575. wenzhou2000ToWGS84(coordinate) {
  1576. return proj4("EPSG:0986", "EPSG:4326", coordinate);
  1577. },
  1578. // 经纬度转墨卡托
  1579. lonlattoWebMercator(lon, lat) {
  1580. var xy = [];
  1581. var x = (lon * 20037508.34) / 180;
  1582. var y =
  1583. Math.log(Math.tan(((90 + lat) * Math.PI) / 360)) / (Math.PI / 180);
  1584. y = (y * 20037508.34) / 180;
  1585. xy[0] = x;
  1586. xy[1] = y;
  1587. return xy;
  1588. },
  1589. // 墨卡托转经纬度
  1590. webMercator2lonlat(x, y) {
  1591. var lonlat = [];
  1592. var lon = (x / 20037508.34) * 180;
  1593. var lat = (y / 20037508.34) * 180;
  1594. lat =
  1595. (180 / Math.PI) *
  1596. (2 * Math.atan(Math.exp((lat * Math.PI) / 180)) - Math.PI / 2);
  1597. lonlat[0] = lon;
  1598. lonlat[1] = lat;
  1599. return lonlat;
  1600. },
  1601. addGltf(url, x, y, z) {
  1602. let origin = Cesium.Cartesian3.fromDegrees(x, y, z);
  1603. // 创建一个本地的东北向上坐标系,其原点为经度-120度,纬度44.0度。
  1604. // 可以随时更改模型的modelMatrix属性以移动或旋转模型。
  1605. let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
  1606. let model = globalVariable.viewer.scene.primitives.add(
  1607. Cesium.Model.fromGltf({
  1608. url: url,
  1609. modelMatrix: modelMatrix,
  1610. scale: 1,
  1611. })
  1612. );
  1613. },
  1614. },
  1615. };
  1616. </script>
  1617. <style lang="less" scoped>
  1618. #cesiumContainer {
  1619. width: 100%;
  1620. height: 100%;
  1621. .get_now_camera_view {
  1622. position: absolute;
  1623. z-index: 1;
  1624. }
  1625. }
  1626. </style>