1、將GeowebCache的war包解壓到tomcat的webapp下,打開war包中的WEB-INF中的web.xml文件,同時創建一個你想保存geowencache的切片的空文件夾,例如我命名叫arcgis
web.xml文件中 添加<context-param>節點,param-value是你所建的文件夾
<context-param> <param-name>GEOWEBCACHE_CACHE_DIR</param-name> <param-value>D:\Program Files\Apache Tomcat\webapps\geowebcache\WEB-INF\arcgis</param-value> </context-param>
2、在重啟動tomcat 之后我們在arcgis文件夾中可以看到
3、打開webwebcache.xml文件,在<layer>…</layer>節點中添加如下節點:
<arcgisLayer> <name>arcgis_cache</name> <tilingScheme>E:\\tile\\arcgis\\Layers\\conf.xml</tilingScheme> <tileCachePath>E:\\tile\\arcgis\Layers\\_alllayers</tileCachePath> <hexZoom>false</hexZoom> </arcgisLayer>
4、配置完以后我發現我無法啟動geowebcache,日志報錯
10 四月 18:12:15 (main) WARN [support.XmlWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gwcXmlConfig' defined in ServletContext resource [/WEB-INF/geowebcache-core-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: No ArcGISCacheGridsetConfiguration could be found 10 四月 18:12:15 (main) ERROR [context.ContextLoader] - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gwcXmlConfig' defined in ServletContext resource [/WEB-INF/geowebcache-core-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: No ArcGISCacheGridsetConfiguration could be found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
網上找到了解決方法
找到geowebcache-core-context文件,往里面添加
<bean id="gwcArcGIGridsetConfigutation" class="org.geowebcache.arcgis.layer.ArcGISCacheGridsetConfiguration"/>
5、加完之后可以在geowebcache的list中查看到自己添加的瓦片,但是卻不能預覽,比例尺也是1:NAN
網上解釋說高版本geowebcache可能無法預覽,查看他的預覽頁面發現是OL3的庫,因為我用的是OL4的庫,不影響OL或者leaflet加載
6、重啟一下服務,刷新一下
var format = 'image/png';
var tiled = new ol.layer.Tile({
//visible: false,
source: new ol.source.TileWMS({
url: 'http://localhost:8888/geowebcache/service/wms',
params: {
'FORMAT': format,
'VERSION': '1.0.0',
tiled: true,
"LAYERS": 'arcgis_cache',
"exceptions": 'application/vnd.ogc.se_inimage',
}
})
});
var view = new ol.View({
projection:"EPSG:4326",
zoom: 13,
center: [113.33, 34.01]
});
var map = new ol.Map({
target: 'map',
layers: [tiled],
view:view
});