在使用ol5调用arcgis wms服务使用canvas导处图片的时候会出现跨域问题。
wms图层加载方式
new ol.layer.Image({
source: new ol.source.ImageWMS({
crossOrigin: 'anonymous',
ratio: 1,
url: 'http://localhost:6080/arcgis/services/gis/xiaoban/MapServer/WMSServer',
params: {
'FORMAT': 'image/png',
'VERSION': '1.1.0',
'LAYERS': '0',
}
})
})
1.开始的时候如果取消crossOrigin的话,可以正常加载图层,但是导出的时候会提示跨域问题;
2.如果放开的话,则地图不会正常显示。
经过自己研究,现将自己解决的过程阐述如下:
1.cors-filter-2.5.jar,java-property-utils-1.10.jar这两个是跨域的文件,需要放置的位置为:
...\ArcGIS\Server\framework\runtime\tomcat\webapps\arcgis#services\WEB-INF\lib
...\ArcGIS\Server\framework\runtime\tomcat\lib
2.添加跨域标识:
...\ArcGIS\Server\framework\runtime\tomcat\webapps\arcgis#services\WEB-INF\web.xml
...\ArcGIS\Server\framework\runtime\tomcat\conf\web.xml
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, DELETE</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<param-value>Set-Cookie</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
配置上述之后,先在浏览器中查看是否可以正常访问,如果有异常,尝试重启
...\ArcGIS\Server\framework\runtime\tomcat\bin目录下的
startup.bat或version.bat
arcgis server服务
网友评论