javascript – openlayers:重绘矢量图层而不再重新下载数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – openlayers:重绘矢量图层而不再重新下载数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2868字,纯文字阅读大概需要5分钟。
内容图文
![javascript – openlayers:重绘矢量图层而不再重新下载数据](/upload/InfoBanner/zyjiaocheng/721/1b6596f4059b40d5a71194544fb9440f.jpg)
我需要的是一种修改矢量图层表示而无需再次下载数据的方法.
我已经定义了一个GLM矢量图层和一个名为build_style的函数,用于根据某些特征为其几何图形着色.我有一个HTML表单调用函数UpdateGlmLayer,它以这种方式定义:
function UpdateGlmLayer(info_str) {
var v = info_str.split("|");
var filter_column = v[0];
var values = [parseFloat(v[1]), parseFloat(v[2]), parseFloat(v[3])];
glm.styleMap = build_style(filter_column, values);
glm.redraw();
};
GLM层以这种方式定义:
gml_protocol = new OpenLayers.Protocol.HTTP({
url: "http://localhost:8080/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName="+info["layer_featurePrefix"]+":"+info["layer_featureType"],
format: new OpenLayers.Format.GML()
})
glm = new OpenLayers.Layer.Vector(info["layer_name"], {
strategies: [new OpenLayers.Strategy.BBOX({ratio: 3, resFactor: 1})],
protocol: gml_protocol,
styleMap: build_style(info["filter_property"], info["filter_values"]),
srsName: info["layer_srsName"],
projection: new OpenLayers.Projection("EPSG:4326"),
visibility: true
});
当触发UpdateGlmLayer时,颜色似乎立即发生变化,但之后系统停止的时间与初始页面加载下载数据的时间大致相同.在此期间什么都做不了.有什么不对?
解决方法:
问题在于您设置resFactor.我创建了两个演示映射,一个加载了一些GeoServer GML向量,并在不使用resFactor 1设置的情况下重新设置它们,另一个使用resFactor 1设置,第二个肯定是发送多个请求.如果将resfactor设置为大于1的任何值,则不会发生这种情况.
没有resFactor设置点击restyle 3次给出这个结果:
只有1个数据请求.
但是,resFactor设置3点击restyle 3次会得到以下结果:
4个数据请求.
我相信这是你所看到的行为.这看起来像是一个错误,因为文档说你所做的是有效的.看看BBOX策略js文件中的代码,问题似乎出现在代码中:
var ratio = this.resolution / this.layer.map.getResolution();
invalid = (ratio >= this.resFactor || ratio <= (1 / this.resFactor));
这是在.redraw()函数上运行,以计算是否需要重新加载数据.因为当您重绘地图时,比率将始终设置为1(分辨率未更改,因此this.resolution === this.layer.map.getResolution())则无效将始终等于true,因此图层重新加载.
resFactor
{Float} Optional factor used to determine when previously requested
features are invalid. If set, the resFactor will be compared to the
resolution of the previous request to the current map resolution. If
resFactor > (old / new) and 1/resFactor < (old / new). If you set a
resFactor of 1, data will be requested every time the resolution
changes. If you set a resFactor of 3, data will be requested if the
old resolution is 3 times the new, or if the new is 3 times the old.
If the old bounds do not contain the new bounds new data will always
be requested (with or without considering resFactor).
我正在以下列方式进行重新设计:
var style1, style2;
style1 = new OpenLayers.Style({
strokeColor: "yellow",
strokeWidth: 10 });
style2 = new OpenLayers.Style({
strokeColor: "blue",
strokeWidth: 5 });
function restyle1()
{
layer.styleMap = style1;
layer.redraw();
}
function restyle2()
{
layer.styleMap = style2;
layer.redraw();
}
内容总结
以上是互联网集市为您收集整理的javascript – openlayers:重绘矢量图层而不再重新下载数据全部内容,希望文章能够帮你解决javascript – openlayers:重绘矢量图层而不再重新下载数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。