我是靠谱客的博主 还单身菠萝,最近开发中收集的这篇文章主要介绍openlayer常见问题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1.跨域访问WFS问题

找到的OpenLayers跨域访问WFS服务出现No 'Access-Control-Allow-Origin' header is present...错误的一种解决办法

在eclipse中部署了一个使用OpenLayers的Java web项目CrossDomainTest,容器为Tomcat 7.0.56.(http://localhost:8080/CrossDomainTest/index.html)

利用Geoserver 2.5.2使用内置容器jetty 6.18发布WFS服务.(http://localhost:8888/geoserver/wfs).

从localhost:8080访问localhost:8888的WFS无法得到预期效果,通过chrome浏览器开发者工具发现错误:No 'Access-Control-Allow-Origin' header is present on the requested resource. 查阅发现是所谓的Javascript安全性导致的“跨域问题”,找了很多的解决方法,比如设置cgi代理,CORS(跨域资源共享)等我都尝试了但不知为何没有成功,限于时间关系没有仔细追究,最后找到[Geoserver-users] CORS for jetty 6.1.8 (Geoserver 2.x), solved这篇文章,按其设置解决了问题:


解决方案步骤为:
1.从这里下载ZIP文件,解压后放到<Geoserver>webappsgeoserverWEB-INFclasses文件夹中。
2.向<Geoserver>webappsgeoserverWEB-INF文件夹中的web.xml文件中增加如下配置文件允许所有域的跨域资源共享

<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.mortbay.servlets.CrossOriginFilter</filter-class>
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>allowedMethods</param-name>
<param-value>GET,POST</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>x-requested-with,content-type</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

详见:http://blog.csdn.net/shulitang/article/details/41520353

http://sourceforge.net/p/geoserver/mailman/message/32391594/

2.以某个要素(feature)的范围extent放大

openlayers2 中的方法为 map.zoomToExtent(extent);
ol3 中不在使用以上方法,改用
var extent = source.getExtent();
map.getView().fitExtent(extent, map.getSize());

3.vector source returning empty in source.getFeatures()

When you pass an url param, ol.source.Vector is asynchronously (AJAX) loaded so you have to wait until it's fully loaded with:
vectorSource.on('change', function(evt){
if(source.getState() === 'ready'){
console.info(vectorSource.getFeatures());
}
});
详见: http://stackoverflow.com/questions/32561718/vector-source-returning-empty-in-source-getfeatures
http://www.tuicool.com/articles/n6BBNfj

4.基于OpenLayers 的WFS模糊查询优化

http://blog.csdn.net/zhang88lei/article/details/6614973

最后

以上就是还单身菠萝为你收集整理的openlayer常见问题的全部内容,希望文章能够帮你解决openlayer常见问题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(76)

评论列表共有 0 条评论

立即
投稿
返回
顶部