GeoWebCache发布切片数据
2018-01-31 本文已影响167人
王顼
自己写了个小工具,用于下载网络地图的切片数据,一直都是将下载好的切片发布到ArcGIS Server上去,今年决定拥抱开源,尝试使用GeoWebCache发布切片。
机器环境
Oracle JDK8
Tomcat 8.5
GeoWebCache 1.12.1
ArcMap 10.2
1.GeoWebCache基本配置
- 设置GeoWebCache的WEB-INF/geowebcache-core-context.xml文件,对GWC进行基本配置,相关说明很多,不再赘述。
- 设置GeoWebCache的WEB-INF/web.xml文件,添加GEOWEBCACHE_CACHE_DIR存放路径
<context-param>
<param-name>GEOWEBCACHE_CACHE_DIR</param-name>
<param-value>E:\\myTile</param-value>
</context-param>
2.切片发布
- 切片下载好后,为了保证下载切片的完整性,先发布到ArcGIS Server上去验证了下。验证完成后,将ArcGIS Server的缓存服务目录下的,该地图服务的Conf.xml和conf.cdi文件连同切片数据复制到自己设置的GeoWebCache切片目录
- 删除conf.cdi中的SpatialReference节点
- 删除Conf.xml中的lastWKID节点
- 修改Conf.xml中的WKID,以适应GeoWebCache中的要求,本例中将102100改为了900913
- 设置GEOWEBCACHE_CACHE_DIR中的geowebcache.xml文件,在layers节点最后添加
<arcgisLayer>
<name>map</name>
<tilingScheme>E:\\map\\Conf.xml</tilingScheme>
<tileCachePath>E:\\map\\_alllayers\\</tileCachePath>
</arcgisLayer>
- 运行GeoWebCache,点击Reload Configuration
3.切片预览
- 网上许多同学在使用高于1.8版本的GeoWebCache发布切片时,都会在这一步遇到问题,经过一天的排查,初步确定是GeoWebCache所引用的openLayers3的问题。在使用OpenLayer4重新加载GeoWebCache发布的切片后,WMTS服务访问正常,下面是经过修改的Openlayer4访问WMTS服务的官方示例代码
<!DOCTYPE html>
<html>
<head>
<title>WMTS</title>
<link rel="stylesheet" href="https://openlayers.org/en/v4.6.4/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/v4.6.4/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script>
var projection = ol.proj.get('EPSG:3857');
var projectionExtent = projection.getExtent();
var size = ol.extent.getWidth(projectionExtent) / 256;
var resolutions = new Array(14);
var matrixIds = new Array(14);
for (var z = 0; z < 14; ++z) {
// generate resolutions and matrixIds arrays for this WMTS
resolutions[z] = size / Math.pow(2, z);
matrixIds[z] = 'EPSG:900913_map:'+z;
}
var map = new ol.Map({
layers: [
new ol.layer.Tile({
opacity: 0.7,
source: new ol.source.WMTS({
attributions: 'GeoWebCache Tiles ©',
url: 'http://localhost:9080/geowebcache/service/wmts',
layer: 'map',
matrixSet: 'EPSG:900913_map',
format: 'image/png',
projection: projection,
tileGrid: new ol.tilegrid.WMTS({
origin: ol.extent.getTopLeft(projectionExtent),
resolutions: resolutions,
matrixIds: matrixIds
}),
style: 'default',
wrapX: true
})
})
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: {
collapsible: false
}
}),
view: new ol.View({
center: [8375524, 4573882],
zoom: 5
})
});
</script>
</body>
</html>