重绘openlayers矢量图层

时间:2012-08-06 17:30:37

标签: jquery openlayers

我想重绘一个OpenLayers向量。

我的html按钮:

<button id="refresh" type="button">Refresh</button>

和我的jquery函数重绘图层,刷新函数中的parksLayer记录为false:

function refresh() {
    parksLayer.redraw(true);
}

function bind(){
    $("#refresh").bind("click", refresh);
}

和我的地图,我想重新绘制ParksLayer:

        map = new OpenLayers.Map({
            div: "map",
            layers: [
                new OpenLayers.Layer.OSM(),
                parksLayer
            ]
        });

更新

感谢您的帮助,我的矢量图层定义如下:

function changeme(avalue){
        parksLayer = new OpenLayers.Layer.Vector("Parks", {
            projection: new OpenLayers.Projection("EPSG:4326"),
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.Script({
                url: "http://my.cartodb.com/api/v2/sql",
                params: {
        q: "SELECT * FROM activities where type_code is not null"+" "+avalue,
        format: "geojson"
    },
                format: new OpenLayers.Format.GeoJSON({
                    ignoreExtraDims: true
                }),
                callbackKey: "callback"
            }),
        });  
    }

我有一个动态更改avalue的表单会更改GeoJSON查询,因此,如果我可以重新绘制parksLayer,我将从图层中选择一个新选项。

3 个答案:

答案 0 :(得分:3)

如果我阅读Openlayers API,重绘功能不使用任何参数......您应该尝试调用redraw()而不将“true”作为参数...

Openlayers API: 重绘:function() 重绘图层。如果重绘图层,则返回true,否则返回false。

此致

艾蒂安

答案 1 :(得分:3)

我也有redraw()的问题并使用它。

VecLayer.redraw(true);
VecLayer.refresh({force: true});

答案 2 :(得分:1)

这是一个KML格式,但它很容易适应,你可以看到

   var refresh = new OpenLayers.Strategy.Refresh({force: true, active: true});

   var protocol = new OpenLayers.Protocol.HTTP({
         url: "http://my_data.source.com",
            format: new OpenLayers.Format.KML({
                  extractStyles: false,
                  extractAttributes: true
               })
            });

   mylayer = new OpenLayers.Layer.Vector("MyLayerName", {
            strategies: [new OpenLayers.Strategy.Fixed(), refresh],
            protocol: protocol
   });

然后重绘/重新下载您执行的操作:

refresh.refresh();
相关问题