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
});