当前位置:   article > 正文

cesium图层管理_cesium 图层管理器

cesium 图层管理器

图层覆盖问题(29条消息) cesium 叠加多个图层时 解决图层有遮挡覆盖问题_yechangfeng111的博客-CSDN博客_cesium图层叠加​​​​​​cesium 之图层管理器篇(附源码下载) - 小专栏 (xiaozhuanlan.com​​​​​​

实现参考于cesium官网demo(下图为效果图)

 

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="X-UA-Compatible" content="chorme" />
  6. <meta
  7. name="viewport"
  8. content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
  9. />
  10. <meta name="description" content="Layer imagery from multiple sources, including WMS servers, Bing Maps, ArcGIS Online, OpenStreetMaps, and more, and adjust the alpha of each independently.">
  11. <meta name="cesium-sandcastle-labels" content="Showcases">
  12. <title>Cesium Demo</title>
  13. <script type="text/javascript" src="./Sandcastle-header.js"></script>
  14. <script
  15. type="text/javascript"
  16. src="./scripts/CesiumUnminified/Cesium.js"
  17. ></script>
  18. </head>
  19. <body
  20. class="sandcastle-loading"
  21. data-sandcastle-bucket="bucket-requirejs.html"
  22. >
  23. <style>
  24. @import url(./scripts/templates/bucket.css);
  25. #toolbar {
  26. background: rgba(42, 42, 42, 0.8);
  27. padding: 4px;
  28. border-radius: 4px;
  29. }
  30. #toolbar input {
  31. vertical-align: middle;
  32. padding-top: 2px;
  33. padding-bottom: 2px;
  34. }
  35. #toolbar table tr {
  36. transform: translateY(0);
  37. transition: transform 0.4s ease-out;
  38. }
  39. #toolbar table tr.up {
  40. transform: translateY(33px);
  41. transition: none;
  42. }
  43. #toolbar table tr.down {
  44. transform: translateY(-33px);
  45. transition: none;
  46. }
  47. </style>
  48. <div id="cesiumContainer" class="fullSize"></div>
  49. <div id="loadingOverlay"><h1>Loading...</h1></div>
  50. <div id="toolbar">
  51. <table>
  52. <tbody data-bind="foreach: layers">
  53. <tr data-bind="css: { up: $parent.upLayer === $data, down: $parent.downLayer === $data }">
  54. <td><input type="checkbox" data-bind="checked: show"></td>
  55. <td>
  56. <span data-bind="text: name, visible: !$parent.isSelectableLayer($data)"></span>
  57. <select data-bind="visible: $parent.isSelectableLayer($data), options: $parent.baseLayers, optionsText: 'name', value: $parent.selectedLayer"></select>
  58. </td>
  59. <td>
  60. <input type="range" min="0" max="1" step="0.01" data-bind="value: alpha, valueUpdate: 'input'">
  61. </td>
  62. <td>
  63. <button type="button" class="cesium-button" data-bind="click: function() { $parent.raise($data, $index()); }, visible: $parent.canRaise($index())">
  64. </button>
  65. </td>
  66. <td>
  67. <button type="button" class="cesium-button" data-bind="click: function() { $parent.lower($data, $index()); }, visible: $parent.canLower($index())">
  68. </button>
  69. </td>
  70. </tr>
  71. </tbody>
  72. </table>
  73. </div>
  74. <script id="cesium_sandcastle_script">
  75. function startup(Cesium) {
  76. 'use strict';
  77. //Sandcastle_Begin
  78. const viewer = new Cesium.Viewer("cesiumContainer", {
  79. //隐藏按钮
  80. baseLayerPicker: false,
  81. navigationHelpButton: false,//是否显示右上角的帮助按钮
  82. timeline: false,//是否显示时间轴
  83. animation:false,
  84. });
  85. viewer._cesiumWidget._creditContainer.style.display = 'none';
  86. viewer.camera.setView({
  87. destination : new Cesium.Cartesian3(-1774408.6308292362, 5568754.171715988, 4612464.604996003),
  88. orientation: {
  89. heading : 6.283185307179586, // east, default value is 0.0 (north)指向
  90. pitch : -1.5706877029806772, // default value (looking down)视角
  91. roll : 0.0 // default value
  92. }
  93. });
  94. const imageryLayers = viewer.imageryLayers;
  95. const viewModel = {
  96. layers: [],
  97. baseLayers: [],
  98. upLayer: null,
  99. downLayer: null,
  100. selectedLayer: null,
  101. isSelectableLayer: function (layer) {
  102. return this.baseLayers.indexOf(layer) >= 0;
  103. },
  104. raise: function (layer, index) {
  105. imageryLayers.raise(layer);
  106. viewModel.upLayer = layer;
  107. viewModel.downLayer = viewModel.layers[Math.max(0, index - 1)];
  108. updateLayerList();
  109. window.setTimeout(function () {
  110. viewModel.upLayer = viewModel.downLayer = null;
  111. }, 10);
  112. },
  113. lower: function (layer, index) {
  114. imageryLayers.lower(layer);
  115. viewModel.upLayer =
  116. viewModel.layers[
  117. Math.min(viewModel.layers.length - 1, index + 1)
  118. ];
  119. viewModel.downLayer = layer;
  120. updateLayerList();
  121. window.setTimeout(function () {
  122. viewModel.upLayer = viewModel.downLayer = null;
  123. }, 10);
  124. },
  125. canRaise: function (layerIndex) {
  126. return layerIndex > 0;
  127. },
  128. canLower: function (layerIndex) {
  129. return layerIndex >= 0 && layerIndex < imageryLayers.length - 1;
  130. },
  131. };
  132. const baseLayers = viewModel.baseLayers;
  133. Cesium.knockout.track(viewModel);
  134. //图层设置
  135. function setupLayers() {
  136. // Create all the base layers that this example will support.
  137. // These base layers aren't really special. It's possible to have multiple of them
  138. // enabled at once, just like the other layers, but it doesn't make much sense because
  139. // all of these layers cover the entire globe and are opaque.
  140. addBaseLayerOption("Bing Maps Aerial", undefined); // the current base layer
  141. addBaseLayerOption(
  142. "天地图影像底图",
  143. new Cesium.WebMapTileServiceImageryProvider({
  144. url: 'http://t0.tianditu.com/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=84e1639ed5e3026ecec77cd1c0837ead',
  145. layer: 'img',
  146. style: 'default',
  147. format: 'tiles',
  148. tileMatrixSetID: 'w',
  149. credit: new Cesium.Credit('天地图全球影像服务'),
  150. })
  151. );
  152. addBaseLayerOption(
  153. "天地图地形底图",
  154. new Cesium.WebMapTileServiceImageryProvider({
  155. url: 'http://t0.tianditu.gov.cn/ter_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=ter&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=84e1639ed5e3026ecec77cd1c0837ead',
  156. layer: 'img',
  157. style: 'default',
  158. format: 'tiles',
  159. tileMatrixSetID: 'w',
  160. credit: new Cesium.Credit('天地图全球影像服务'),
  161. })
  162. );
  163. addBaseLayerOption(
  164. "天地图矢量底图",
  165. new Cesium.WebMapTileServiceImageryProvider({
  166. url: 'http://t0.tianditu.gov.cn/vec_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=vec&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=84e1639ed5e3026ecec77cd1c0837ead',
  167. layer: 'img',
  168. style: 'default',
  169. format: 'tiles',
  170. tileMatrixSetID: 'w',
  171. credit: new Cesium.Credit('天地图全球影像服务'),
  172. })
  173. );
  174. addBaseLayerOption(
  175. "街道底图",
  176. new Cesium.ArcGisMapServerImageryProvider({
  177. url:
  178. "https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer",
  179. })
  180. );
  181. addBaseLayerOption(
  182. "OSM",
  183. new Cesium.OpenStreetMapImageryProvider()
  184. );
  185. // Create the additional layers
  186. addAdditionalLayerOption(
  187. "形变速率图层",
  188. new Cesium.ArcGisMapServerImageryProvider({
  189. url:'http://localhost:6080/arcgis/rest/services//%E9%BB%84%E6%B2%B3%E4%B8%AD%E4%B8%8A%E6%B8%B8%E5%BD%A2%E5%8F%98%E9%80%9F%E7%8E%87/MapServer?f=jsapi',
  190. })
  191. );
  192. addAdditionalLayerOption(
  193. "活动构造图层",
  194. new Cesium.ArcGisMapServerImageryProvider({
  195. url:'http://localhost:6080/arcgis/rest/services//%E9%BB%84%E6%B2%B3%E4%B8%AD%E4%B8%8A%E6%B8%B8%E6%9E%84%E9%80%A0/MapServer?f=jsapi',
  196. })
  197. );
  198. addAdditionalLayerOption(
  199. "地质图层",
  200. new Cesium.ArcGisMapServerImageryProvider({
  201. url:'http://localhost:6080/arcgis/rest/services//%E9%BB%84%E6%B2%B3%E4%B8%AD%E4%B8%8A%E6%B8%B8%E5%9C%B0%E8%B4%A8/MapServer?f=jsapi',
  202. })
  203. );
  204. addAdditionalLayerOption(
  205. "地貌图层",
  206. new Cesium.ArcGisMapServerImageryProvider({
  207. url : 'http://localhost:6080/arcgis/rest/services//%E9%BB%84%E6%B2%B3%E4%B8%AD%E4%B8%8A%E6%B8%B8%E5%9C%B0%E8%B2%8C/MapServer?f=jsapi',
  208. })
  209. );
  210. addAdditionalLayerOption(
  211. "注记",
  212. new Cesium.WebMapTileServiceImageryProvider({
  213. url: "http://t0.tianditu.com/cia_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=cia&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=84e1639ed5e3026ecec77cd1c0837ead",
  214. layer: "tdtImgAnnoLayer",
  215. style: "default",
  216. format: "image/jpeg",
  217. tileMatrixSetID: "GoogleMapsCompatible",
  218. show: false
  219. })
  220. );
  221. addAdditionalLayerOption(
  222. "格网",
  223. new Cesium.GridImageryProvider(),
  224. 1.0,
  225. false
  226. );
  227. addAdditionalLayerOption(
  228. "坐标系",
  229. new Cesium.TileCoordinatesImageryProvider(),
  230. 1.0,
  231. false
  232. );
  233. }
  234. function addBaseLayerOption(name, imageryProvider) {
  235. let layer;
  236. if (typeof imageryProvider === "undefined") {
  237. layer = imageryLayers.get(0);
  238. viewModel.selectedLayer = layer;
  239. } else {
  240. layer = new Cesium.ImageryLayer(imageryProvider);
  241. }
  242. layer.name = name;
  243. baseLayers.push(layer);
  244. }
  245. function addAdditionalLayerOption(name, imageryProvider, alpha, show) {
  246. const layer = imageryLayers.addImageryProvider(imageryProvider);
  247. layer.alpha = Cesium.defaultValue(alpha, 0.5);
  248. layer.show = Cesium.defaultValue(show, true);
  249. layer.name = name;
  250. Cesium.knockout.track(layer, ["alpha", "show", "name"]);
  251. }
  252. function updateLayerList() {
  253. const numLayers = imageryLayers.length;
  254. viewModel.layers.splice(0, viewModel.layers.length);
  255. for (let i = numLayers - 1; i >= 0; --i) {
  256. viewModel.layers.push(imageryLayers.get(i));
  257. }
  258. }
  259. setupLayers();
  260. updateLayerList();
  261. //Bind the viewModel to the DOM elements of the UI that call for it.
  262. const toolbar = document.getElementById("toolbar");
  263. Cesium.knockout.applyBindings(viewModel, toolbar);
  264. Cesium.knockout
  265. .getObservable(viewModel, "selectedLayer")
  266. .subscribe(function (baseLayer) {
  267. // Handle changes to the drop-down base layer selector.
  268. let activeLayerIndex = 0;
  269. const numLayers = viewModel.layers.length;
  270. for (let i = 0; i < numLayers; ++i) {
  271. if (viewModel.isSelectableLayer(viewModel.layers[i])) {
  272. activeLayerIndex = i;
  273. break;
  274. }
  275. }
  276. const activeLayer = viewModel.layers[activeLayerIndex];
  277. const show = activeLayer.show;
  278. const alpha = activeLayer.alpha;
  279. imageryLayers.remove(activeLayer, false);
  280. imageryLayers.add(baseLayer, numLayers - activeLayerIndex - 1);
  281. baseLayer.show = show;
  282. baseLayer.alpha = alpha;
  283. updateLayerList();
  284. });
  285. //Sandcastle_End
  286. Sandcastle.finishedLoading();
  287. }
  288. if (typeof Cesium !== 'undefined') {
  289. window.startupCalled = true;
  290. startup(Cesium);
  291. }
  292. </script>
  293. </body>
  294. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/110017
推荐阅读
相关标签
  

闽ICP备14008679号