ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript – openlayers:重绘矢量图层而不再重新下载数据

2019-09-02 09:36:05  阅读:165  来源: 互联网

标签:javascript openlayers gis


我需要的是一种修改矢量图层表示而无需再次下载数据的方法.
我已经定义了一个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,gis
来源: https://codeday.me/bug/20190902/1790279.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有