目錄
參考博文:https://blog.csdn.net/hellfire2007/article/details/80876785
環境搭建:
1.Geoserver - 2.16.1,在http://geoserver.org/release/2.16.1/地址下載版本: Platform Independent Binary
2. GeoWebCache -1.15.1,在https://sourceforge.net/projects/geowebcache/files/geowebcache/1.15.1/ 地址下載版本:geowebcache-1.15.1-war.zip。
3.arcgis瓦片鬆散型。
操作步驟:
1.部署Geoserver
將下載的geoserver-2.16.1-bin.zip,解壓,並將解壓後的文件夾放在磁盤根目錄,如D盤
2.啓動geoserver
在bin文件夾雙擊startup.bat,啓動成功,在瀏覽器輸入http://localhost:8080/geoserver/web/,如出現下圖,說明部署成功。
ps:默認端口8080,默認用戶名/密碼:admin/geoserver
3.部署Geowebcache
將下載的geowebcache-1.15.1-war解壓,然後再講解壓後的geowebcache.war再解壓,得到geowebcache文件夾。
將geowebcache文件夾拷貝到Geoserver下面的webapps中
新建緩存配置目錄arcgis(可隨意命名,只要和對應web.xml一樣即可),並修改web-inf文件夾下的文件web.xml,在</context-param>節點後添加如下節點,記錄新建的目錄:
<context-param>
<param-name>GEOWEBCACHE_CACHE_DIR</param-name>
<param-value>D:\geoserver-2.16.1\webapps\geowebcache\arcgis</param-value>
</context-param>
重啓服務,會發現該目錄下自動生成了幾個文件,注意這裏的geowebcache.xml
添加ArcGIS切片的路徑
修改在上文出現的geoserver-2.16.1\webapps\geowebcache\arcgis\geowebcache.xm文件,在<layer>…</layer>節點中添加如下節點:
注意:啓動服務時該配置文件中所有服務對應的切片方案和切片路徑必須都存在,否則打不開GeoWebCache主頁,顯示“503...”,要刪去不存在的arcgisLayer節點,並重啓服務!
<arcgisLayer>
<name>SFH_geoserverTest</name>
<tilingScheme>D:\geoserver-2.16.1\webapps\geowebcache\arcgisTiles\SFH_geoserverTest\Layers\Conf.xml</tilingScheme>
<tileCachePath>D:\geoserver-2.16.1\webapps\geowebcache\arcgisTiles\SFH_geoserverTest\Layers\_alllayers</tileCachePath>
<hexZoom>false</hexZoom>
<storageFormat>esriMapCacheStorageModeExploded</storageFormat>
</arcgisLayer>
SFH_geoserverTest爲服務名,GeoWebCache服務頁面中可看到改名字,這裏隨便起的。conf.xml就是ArcGIS Server發佈服務設置緩存後生成的配置文件,該目錄就是瓦片所在目錄。
4. 瀏覽服務
再次重啓GeoServer,進入GeoWebCache主頁:http://localhost:8080/geowebcache/home
在以下鏈接中可以看到發佈的服務:
點擊jpeg預覽,不能顯示,應該是默認用的openlayers3,預覽不了。
自己新建一個html頁,引用openlayers5,添加如下代碼,修改相關屬性爲自己的服務,就可在瀏覽器預覽成功了。
<!DOCTYPE html>
<html>
<head>
<title>WMTS</title>
<link rel="stylesheet" href="https://openlayers.org/en/v5.3.0/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://openlayers.org/en/v5.3.0/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
var format = 'image/png';
var tiled = new ol.layer.Tile({
//visible: false,
source: new ol.source.TileWMS({
url: 'http://localhost:8080/geowebcache/service/wms?SERVICE=WMS&',
params: {
'FORMAT': format,
'VERSION': '1.0.0',
tiled: true,
"LAYERS": 'SFH_geoserverTest',
"exceptions": 'application/vnd.ogc.se_inimage',
}
})
});
var view = new ol.View({
projection:"EPSG:4326",
zoom: 4,
center: [123.75,45]
});
var map = new ol.Map({
target: 'map',
layers: [tiled],
view:view
});
</script>
</body>
</html>