采用 geowebcache 缓存地图
1 .把 geowebcache 服务放到 tomcat 应用中,假设和 wms 服务放在同一个 tomcat 中,在 geowebcache/WEB-INF 下面找到 geowebcache-servlet.xml
在这个文件中有一段:
<bean id="gwcWMSConfig" class="org.geowebcache.config.GetCapabilitiesConfiguration"> <constructor-arg ref="gwcGridSetBroker"/> <!-- The URL to the WMS GetCapabilities document --> <constructor-arg value="http://localhost:8000/wmsserver111/servlet/wms"/> //替换成wms实际的url地址 。。。 </bean>
2.在 geowebcache/WEB-INF/classes 中找到 geowebcache.xml 文件,打开文件,在 <layers> 标签中添加一个 <wmsLayer> ,如:
<wmsLayer> <name>gz</name> <metaInformation> <title>gz</title> <description>gz</description> </metaInformation> <mimeFormats><string>image/jpeg</string><string>image/gif</string><string>image/png</string></mimeFormats> <!-- Grid Subset Example --> <gridSubsets> <gridSubset> <gridSetName>EPSG:4326</gridSetName> <extent> <coords> <double>112.806</double> <double>22.567</double> <double>114.287</double> <double>24.067</double> </coords> </extent> </gridSubset> </gridSubsets> <wmsUrl> <string>http://localhost:8000/wmsserver111/servlet/wms</string> </wmsUrl> <wmsLayers>layers/gz/xzqj,layers/gz/ld,layers/gz/sx,layers/gz/jmd,layers/gz/gsgl,layers/gz/gd,layers/gz/sd,layers/gz/ptgl,layers/gz/ybjd,layers/gz/cgd,layers/gz/zgd,layers/gz/zfjg</wmsLayers> //此处是mapxtreme480\resources\layers下面的命名资源 <transparent>true</transparent> <bgColor></bgColor> <expireCacheList> <expirationRule minZoom="10" expiration="600" /> </expireCacheList> <expireClientsList> <expirationRule minZoom="0" expiration="7200" /> </expireClientsList> </wmsLayer>
3 .编写 js 代码,其他代码不变修改如下:代码见:http://ninggy.iteye.com/blog/617150
var tiled = new OpenLayers.Layer.WMS("背景图", "http://localhost:8000/geowebcache/service/wms?LAYERS=gz", { layers : 'gz', format : format }, { buffer : 0, displayOutsideMaxExtent : true, tileSize : new OpenLayers.Size(256, 256) });