当前位置:   article > 正文

openlayer 加载geoserver切片geotiff数据_openlayers tif

openlayers tif

首先,下载geotiff数据

下载方法使用全能电子地图下载器(很好用) 下载地图切片(建议不下载1,2层级)

 将下载下来的数据使用导航栏的工具拼接成tiff格式

使用geoserver进行发布

发布成功之后使用geoserver去数据进行切片

提交之后切片成功图片路径GeoServer 2.14.2\data_dir\gwc 将所有切片拷贝到一个切片目录下

 

 查看图层

 至此geoserver切片tiff数据完成

注(以上至geoserver自带jetty启动)

如果tomcat下启动geoserver 注意配置切片路径:

注意:1.默认的切片目录GEOSERVER_DATA_DIR是:
    C:\Users\主机名\AppData\Local\Temp\geowebcache,因此需要在web.xml中对其进行定义。
    在web.xml中添加如下配置重启:

    <context-param>
         <param-name>GEOWEBCACHE_CACHE_DIR</param-name>
         <param-value>D:/apache-tomcat-7.0.52-windows-x64/webapps/geoserver/data/data/Tile</param-value>
     </context-param>

  再次进行seed/trunctate的时候就会将切片生成在该目录下面

openlayer加载就比较简单了直接上代码(使用vue):

  1. this.vectorxx9 = new TileLayer({
  2. source: new TileWMS({
  3. url: 'http://localhost:8089/geoserver/gwc/service/wms',
  4. params: {'LAYERS': 'shp:h8', 'VERSION': '1.1.1', 'FORMAT': "image/png", tiled: true, STYLES: '',},
  5. }),

全部代码如下

  1. <template>
  2. <div id="map">
  3. <input @click="fitToChengdu" value="显示成都" type="button"/>
  4. <input @click="toline" value="加载图层" type="button"/>
  5. <input @click="deleteline" value="删除图层" type="button"/>
  6. <div><span>当前层级:</span><span id="zoom"></span><span>分辨率:</span><span id="resolution"></span></div>
  7. <!-- <div id="anchor"><img src="../png/test.png" alt="示例锚点" v-on:click="testvalue"/></div>-->
  8. </div>
  9. </template>
  10. <script>
  11. import "ol/ol.css";
  12. import {Map, View, Overlay, Feature} from "ol";
  13. import TileLayer from "ol/layer/Tile";
  14. import {Image, Vector} from "ol/layer";
  15. import GeoJSON from "ol/format/GeoJSON";
  16. import {Style, Stroke, Icon} from "ol/style";
  17. import VectorLayer from "ol/layer/Vector";
  18. import OSM from "ol/source/OSM";
  19. import XYZ from "ol/source/XYZ";
  20. import Point from "ol/geom/Point";
  21. import VectorSource from "ol/source/Vector";
  22. import ImageWMS from "ol/source/ImageWMS";
  23. import TileDebug from "ol/source/TileDebug";
  24. import page from "../png/定点.png";
  25. import TileWMS from "ol/source/TileWMS"
  26. export default {
  27. data() {
  28. return {
  29. websocket: null,
  30. centers: [-73.99710639567148, 40.742270050255556],
  31. map: null,
  32. anchor: 'testS',
  33. offlineMapLayer: null,
  34. baseLayer: null,
  35. vectorxx0: null,
  36. vectorxx1: null,
  37. vectorxx2: null,
  38. vectorxx3: null,
  39. vectorxx4: null,
  40. vectorxx5: null,
  41. vectorxx6: null,
  42. vectorxx7: null,
  43. vectorxx8: null,
  44. vectorxx9: null,
  45. vectorxxre: null,
  46. wmsSource: null,
  47. wmsSources: null,
  48. openStreetMapLayer: null,
  49. line: null,
  50. wmsLayer: null,
  51. extent: [108.06 - 550 * 1000 / 200000, 30.67 - 344 * 1000 / 200000, 108.06 + 550 * 1000 / 200000, 30.67 + 344 * 1000 / 200000],
  52. maps: new OSM(),
  53. layer: new VectorLayer({source: new VectorSource()}),
  54. styleicon: ""
  55. };
  56. },
  57. created() {
  58. //页面刚进入时开启长连接
  59. this.initWebSocket()
  60. },
  61. destroyed() {
  62. //页面销毁时关闭长连接
  63. this.websocketclose();
  64. },
  65. mounted() {
  66. this.openStreetMapLayer = new TileLayer({
  67. source: new OSM()
  68. });
  69. this.vectorxx1 = new TileLayer({
  70. source: new TileWMS({
  71. // format: new GeoJSON(),
  72. url: 'http://10.4.4.160:8080/geoserver/china/wms',
  73. params: {'LAYERS': 'china:china', 'VERSION': '1.1.0'},
  74. }),
  75. // style: function(feature, resolution) {
  76. // return new Style({
  77. // stroke: new Stroke({
  78. // color: 'blue',
  79. // width: 1
  80. // })
  81. // });
  82. // }
  83. }),
  84. this.vectorxx2 = new TileLayer({
  85. source: new TileWMS({
  86. // format: new GeoJSON(),
  87. url: 'http://localhost:8089/geoserver/wms',
  88. params: {'LAYERS': 'shp:google1', 'VERSION': '1.1.0'},
  89. }),
  90. // style: function(feature, resolution) {
  91. // return new Style({
  92. // stroke: new Stroke({
  93. // color: 'blue',
  94. // width: 1
  95. // })
  96. // });
  97. // }
  98. });
  99. this.vectorxx7 = new TileLayer({
  100. source: new TileWMS({
  101. url: 'http://localhost:8089/geoserver/wms',
  102. params: {'LAYERS': 'shp:google6', 'VERSION': '1.1.0'},
  103. }),
  104. // style: function(feature, resolution) {
  105. // return new Style({
  106. // stroke: new Stroke({
  107. // color: 'blue',
  108. // width: 1
  109. // })
  110. // });
  111. // }
  112. });
  113. this.vectorxx8 = new TileLayer({
  114. source: new TileWMS({
  115. url: 'http://localhost:8089/geoserver/wms',
  116. params: {'LAYERS': 'shp:china8'},
  117. }),
  118. // style: function(feature, resolution) {
  119. // return new Style({
  120. // stroke: new Stroke({
  121. // color: 'blue',
  122. // width: 1
  123. // })
  124. // });
  125. // }
  126. }); this.vectorxx9 = new TileLayer({
  127. source: new TileWMS({
  128. url: 'http://localhost:8089/geoserver/gwc/service/wms',
  129. params: {'LAYERS': 'shp:h8', 'VERSION': '1.1.1', 'FORMAT': "image/png", tiled: true, STYLES: '',},
  130. }),
  131. // style: function(feature, resolution) {
  132. // return new Style({
  133. // stroke: new Stroke({
  134. // color: 'blue',
  135. // width: 1
  136. // })
  137. // });
  138. // }
  139. });
  140. this.vectorxx3 = new TileLayer({
  141. source: new TileWMS({
  142. // format: new GeoJSON(),
  143. url: 'http://localhost:8089/geoserver/wms',
  144. params: {'LAYERS': 'shp:google2', 'VERSION': '1.1.0'},
  145. }),
  146. // style: function(feature, resolution) {
  147. // return new Style({
  148. // stroke: new Stroke({
  149. // color: 'blue',
  150. // width: 1
  151. // })
  152. // });
  153. // }
  154. });
  155. this.vectorxx5 = new TileLayer({
  156. source: new TileWMS({
  157. // format: new GeoJSON(),
  158. url: 'http://localhost:8089/geoserver/wms',
  159. params: {'LAYERS': 'shp:google4', 'VERSION': '1.1.0'},
  160. }),
  161. // style: function(feature, resolution) {
  162. // return new Style({
  163. // stroke: new Stroke({
  164. // color: 'blue',
  165. // width: 1
  166. // })
  167. // });
  168. // }
  169. }),
  170. this.vectorxx4 = new TileLayer({
  171. source: new TileWMS({
  172. // format: new GeoJSON(),
  173. url: 'http://localhost:8089/geoserver/wms',
  174. params: {'LAYERS': 'shp:google3', 'VERSION': '1.1.0'},
  175. }),
  176. // style: function(feature, resolution) {
  177. // return new Style({
  178. // stroke: new Stroke({
  179. // color: 'blue',
  180. // width: 1
  181. // })
  182. // });
  183. // }
  184. });
  185. this.vectorxx6 = new TileLayer({
  186. source: new TileWMS({
  187. // format: new GeoJSON(),
  188. url: 'http://localhost:8089/geoserver/wms',
  189. params: {'LAYERS': 'shp:google5', 'VERSION': '1.1.0'},
  190. }),
  191. style: {
  192. stroke: new Stroke({
  193. color: 'blue',
  194. width: 1
  195. })
  196. }
  197. });
  198. // this.anchor = new Feature({
  199. // geometry: new Point([104, 30])
  200. // });
  201. // console.log(this.anchor);
  202. // this.anchor.setStyle(new Style({
  203. // image: new Icon({
  204. // src: page,
  205. // anchor: [0.5, 1]
  206. // })
  207. // }));
  208. // this.layer.getSource().addFeature(this.anchor);
  209. // this.offlineMapLayer =new Image({
  210. // // source: new OSM()
  211. // source: new ImageStatic({
  212. // url: page, // 熊猫基地地图
  213. // imageExtent: this.extent // 映射到地图的范围
  214. // })
  215. // })
  216. this.vectorxx0 = new Vector({
  217. source: new VectorSource({
  218. format: new GeoJSON({
  219. geometryName: 'SHAPE'
  220. }),
  221. url: 'http://localhost:8089/geoserver/wordtest/wms?service=WMS&version=1.1.0&request=GetMap&layers=wordtest%3At_pots&bbox=103.07%2C29.67%2C105.07%2C31.67&width=768&height=768&srs=EPSG%3A404000&format=application/openlayers'
  222. }),
  223. style: function (feature, resolution) {
  224. return new Style({
  225. stroke: new Stroke({
  226. color: 'red',
  227. width: 1
  228. })
  229. });
  230. }
  231. });
  232. // this.map.addLayer(this.vectorxx0);
  233. /* 有关html运用*/
  234. // this.anchor = new Overlay({
  235. // element: document.getElementById('anchor')
  236. // });
  237. // // 关键的一点,需要设置附加到地图上的位置
  238. // this.anchor.setPosition([104, 30]);
  239. // this.map.addOverlay(this.anchor);
  240. this.map = new Map({
  241. target: "map",
  242. // logo: {src: '..\\png\\test.png'},
  243. layers: [
  244. // new TileLayer({
  245. // source: this.maps
  246. // }),
  247. // new TileLayer({
  248. // source: new TileDebug({
  249. // projection: 'EPSG:4326',
  250. // tileGrid: this.maps.getTileGrid()
  251. // })
  252. // })
  253. // this.layer
  254. // this.vectorxx1,
  255. // this.vectorxx2,
  256. // this.vectorxx3,
  257. // this.vectorxx4,
  258. // this.vectorxx5,
  259. ],
  260. view: new View({
  261. projection: "EPSG:4326", //使用这个坐标系
  262. // extent: [102, 29, 104, 31],
  263. // center: this.centers, //成都
  264. center: [104.06, 30.67],
  265. zoom: 6,
  266. minZoom: 4,
  267. maxZoom: 8,
  268. }),
  269. });
  270. this.wmsSource = new ImageWMS({
  271. crossOrigin: 'anonymous',
  272. params: {
  273. 'LAYERS': 'mysqlworkspace:city', //图层
  274. 'VERSION': '1.1.0',
  275. },
  276. serverType: 'geoserver',
  277. url: 'http://localhost:8089/geoserver/wms'
  278. });
  279. this.wmsLayer = new Image({
  280. source: this.wmsSource
  281. })
  282. // this.map.addLayer(this.vectorxx2)
  283. // this.map.addLayer(this.vectorxx3)
  284. // this.map.addLayer(this.vectorxx4)
  285. // this.map.addLayer(this.vectorxx5)
  286. // this.map.addLayer(this.vectorxx6)
  287. //
  288. // this.map.addLayer(this.vectorxx1)
  289. // this.map.addLayer(this.vectorxx7)
  290. // this.map.addLayer(this.vectorxx8)
  291. this.map.addLayer(this.vectorxx9)
  292. // this.map.addLayer(this.wmsLayer)
  293. // this.map.addLayer(this.openStreetMapLayer)
  294. },
  295. watch: {
  296. "map": function () {
  297. this.map.getView().on('change:resolution', function () {
  298. document.getElementById('zoom').innerHTML = this.getZoom() + ',';
  299. document.getElementById('resolution').innerHTML = this.getResolution();
  300. if(this.getZoom()==3){
  301. this.map.addLayer(this.vectorxx2)
  302. }
  303. // console.log(this.anchor);
  304. // this.styleicon = this.anchor.getStyle();
  305. //
  306. // // 重新设置图标的缩放率,基于层级10来做缩放
  307. // this.styleicon.getImage().setScale(this.getZoom() / 10);
  308. // this.anchor.setStyle(style);
  309. })
  310. },
  311. },
  312. methods: {
  313. deleteline() {
  314. // this.map.removeLayer(this.vectorxx5)
  315. console.log(this.map.getLayers())
  316. this.map.removeLayer(this.map.getLayers().item(4))
  317. console.log(this.map.getLayers())
  318. },
  319. toline() {
  320. this.getJson()
  321. console.log(this.map.getLayers())
  322. },
  323. fitToChengdu() {
  324. this.map.getView().fit([104, 30.6, 104.12, 30.74], this.map.getSize());
  325. },
  326. testvalue() {
  327. document.getElementById('anchor').innerHTML = "3"
  328. },
  329. //初始化weosocket
  330. initWebSocket() {
  331. const wsuri = "ws://localhost:8888/websocket";//ws地址
  332. this.websocket = new WebSocket(wsuri);
  333. this.websocket.onopen = this.websocketonopen;
  334. this.websocket.onerror = this.websocketonerror;
  335. this.websocket.onmessage = this.websocketonmessage;
  336. this.websocket.onclose = this.websocketclose;
  337. },
  338. websocketonerror() {
  339. console.log("WebSocket连接发生错误");
  340. },
  341. //连接成功建立的回调方法
  342. websocketonopen() {
  343. console.log("open");
  344. },
  345. //接收到消息的回调方法
  346. websocketonmessage(e) {
  347. //注意:长连接我们是后台直接1秒推送一条数据,
  348. //但是点击某个列表时,会发送给后台一个标识,后台根据此标识返回相对应的数据,
  349. //这个时候数据就只能从一个出口出,所以让后台加了一个键,例如键为1时,是每隔1秒推送的数据,为2时是发送标识后再推送的数据,以作区分
  350. console.log(e.data + " 00000000000000000000000000");
  351. // this.toline()
  352. this.getJsons()
  353. },
  354. getJson() {
  355. this.map.removeLayer(this.map.getLayers().item(4))
  356. // this.map.getView().setZoom(4)
  357. /* this.vectorxxre = new Image({
  358. source: new ImageWMS({
  359. format: new GeoJSON(),
  360. url: 'http://localhost:8089/geoserver/wms',
  361. params: {'LAYERS': 'mysqlworkspace:city10', 'VERSION': '1.1.0'},
  362. }),
  363. })*/
  364. this.baseLayer = new TileWMS({
  365. url: 'http://localhost:8089/geoserver/wms',
  366. params: {'LAYERS': 'mysqlworkspace:sqlpot', 'VERSION': '1.1.0'},
  367. serverType: 'geoserver'
  368. });
  369. this.vectorxxre = new TileLayer({
  370. source: this.baseLayer
  371. });
  372. console.log(this.vectorxxre + ".......................")
  373. this.map.addLayer(this.vectorxxre)
  374. },
  375. getJsons() {
  376. // window.location.reload();
  377. // this.map.removeLayer(this.map.getLayers().item(5))
  378. // this.map.removeLayer(this.map.getLayers().item(4))
  379. // this.line = new Image({
  380. // source: new ImageWMS({
  381. // crossOrigin: 'anonymous',
  382. // url: 'http://localhost:8089/geoserver/wms',
  383. // params: {'LAYERS': 'mysqlworkspace:line', 'VERSION': '1.1.0'},
  384. //
  385. // }),
  386. // // style: function(feature, resolution) {
  387. // // return new Style({
  388. // // stroke: new Stroke({
  389. // // color: 'blue',
  390. // // width: 1
  391. // // })
  392. // // });
  393. // // }
  394. // });
  395. // this.baseLayer = new TileWMS({
  396. // url: 'http://localhost:8089/geoserver/wms',
  397. // params: {'LAYERS': 'mysqlworkspace:sqlpot', 'VERSION': '1.1.0'},
  398. // serverType: 'geoserver'
  399. // });
  400. //
  401. // this.vectorxxre = new TileLayer({
  402. // source: this.baseLayer
  403. // });
  404. //
  405. // console.log(this.vectorxxre + ".......................")
  406. // this.map.addLayer(this.vectorxxre)
  407. // this.map.addLayer(this.line)
  408. this.wmsSources = new ImageWMS({
  409. crossOrigin: 'anonymous',
  410. params: {
  411. LAYERS: 'mysqlworkspace:sqlpot',
  412. 'VERSION': '1.1.0',
  413. },
  414. serverType: 'geoserver',
  415. url: 'http://localhost:8089/geoserver/wms'
  416. });
  417. this.wmsLayer.setSource(this.wmsSource);
  418. this.map.getView().setResolution(this.map.getView().getResolution() + Math.random() * 0.00000009);//随机数缩放实现刷新
  419. /* console.log(this.vectorxxre + ".......................")
  420. console.log(this.vectorxx5 + ".......................")
  421. /!* this.vectorxxre = new Image({
  422. source: new ImageWMS({
  423. format: new GeoJSON(),
  424. url: 'http://localhost:8089/geoserver/wms',
  425. params: {'LAYERS': 'mysqlworkspace:city10', 'VERSION': '1.1.0'},
  426. }),
  427. })*!/
  428. this.baseLayer = new TileWMS({
  429. url: 'http://localhost:8089/geoserver/wms',
  430. params: {'LAYERS': 'mysqlworkspace:sqlpot', 'VERSION': '1.1.0'},
  431. serverType: 'geoserver'
  432. });
  433. this.vectorxxre = new TileLayer({
  434. source: this.baseLayer
  435. });
  436. console.log(this.vectorxxre + ".......................")
  437. this.map.addLayer(this.vectorxxre)*/
  438. },
  439. websocketsend(agentData) {//数据发送
  440. this.websocket.send(agentData);
  441. },
  442. websocketclose(e) { //关闭
  443. console.log("connection closed (" + e.code + ")");
  444. },
  445. }
  446. }
  447. </script>
  448. <style>
  449. #map {
  450. height: 100%;
  451. }
  452. /*隐藏ol的一些自带元素*/
  453. .ol-attribution, .ol-zoom {
  454. display: none;
  455. }
  456. /*@keyframes zoom*/
  457. /*{*/
  458. /*from {top: 0; left: 0; width: 32px; height: 32px;}*/
  459. /*50% {top: -16px; left: -16px; width: 64px; height: 64px;}*/
  460. /*to {top: 0; left: 0; width: 32px; height: 32px;}*/
  461. /*}*/
  462. /*@-moz-keyframes zoom !* Firefox *!*/
  463. /*{*/
  464. /*from {top: 0; left: 0; width: 32px; height: 32px;}*/
  465. /*50% {top: -16px; left: -16px; width: 64px; height: 64px;}*/
  466. /*to {top: 0; left: 0; width: 32px; height: 32px;}*/
  467. /*}*/
  468. /*@-webkit-keyframes zoom !* Safari 和 Chrome *!*/
  469. /*{*/
  470. /*from {top: 0; left: 0; width: 32px; height: 32px;}*/
  471. /*50% {top: -16px; left: -16px; width: 64px; height: 64px;}*/
  472. /*to {top: 0; left: 0; width: 32px; height: 32px;}*/
  473. /*}*/
  474. /*@-o-keyframes zoom !* Opera *!*/
  475. /*{*/
  476. /*from {top: 0; left: 0; width: 32px; height: 32px;}*/
  477. /*50% {top: -16px; left: -16px; width: 64px; height: 64px;}*/
  478. /*to {top: 0; left: 0; width: 32px; height: 32px;}*/
  479. /*}*/
  480. /*!* 应用css动画到图标元素上 *!*/
  481. /*#anchor*/
  482. /*{*/
  483. /*display: block;*/
  484. /*position: absolute;*/
  485. /*animation: zoom 5s;*/
  486. /*animation-iteration-count: infinite; !* 一直重复动画 *!*/
  487. /*-moz-animation: zoom 5s; !* Firefox *!*/
  488. /*-moz-animation-iteration-count: infinite; !* 一直重复动画 *!*/
  489. /*-webkit-animation: zoom 5s; !* Safari 和 Chrome *!*/
  490. /*-webkit-animation-iteration-count: infinite; !* 一直重复动画 *!*/
  491. /*-o-animation: zoom 5s; !* Opera *!*/
  492. /*-o-animation-iteration-count: infinite; !* 一直重复动画 *!*/
  493. /*}*/
  494. input {
  495. float: left;
  496. color: red;
  497. }
  498. span {
  499. float: left;
  500. font-size: 15px;
  501. color: red;
  502. }
  503. div {
  504. }
  505. </style>

 

 

 

 

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

闽ICP备14008679号