重绘openlayers矢量图层

问题描述:

我想重绘一个OpenLayers矢量。重绘openlayers矢量图层

我的HTML按钮:

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

和我的jQuery函数重绘层,该parksLayer在刷新功能被记录为假:

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

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

,我的地图,我想重绘在ParksLayer:

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

UPDATE

感谢您的帮助,我的矢量图层的定义是这样的:

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我会留下一种形式来自图层的新选择。

如果我读的OpenLayers API,重绘函数不使用任何参数......你应该尝试调用重绘()没有把“真”作为参数...

的OpenLayers API: 重绘:函数() 重绘该图层。如果图层重绘,则返回true,否则返回false。

问候

艾蒂安

+0

反正你确定您的刷新功能中的parksLayer变量是否真的是一个图层?我假设你在初始化变量之前使用它,因为你显示我们的代码不能工作... – 2012-08-06 17:59:29

+0

我已经尝试了两种方式,有和没有真实,但没有骰子 – Bwyss 2012-08-06 19:29:29

+0

你可以发布多一点你的代码看看你如何创建你的ParkLayer变量? – 2012-08-06 19:48:27

我有重绘问题()也是一样,使用它。

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

这里有一个为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();