1

OpenLayersベクターを再描画したい。

私のhtmlボタン:

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

レイヤーを再描画するjquery関数では、refresh関数の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"
            }),
        });  
    }

GeoJSONクエリを変更する動的に変更されるフォームがあるavalueので、parksLayerを再描画できれば、レイヤーからの新しい選択が残ります。

4

3 に答える 3

3

Openlayers APIを読んだ場合、再描画関数はパラメーターを使用しません...パラメーターとして「true」を指定せずにredraw()を呼び出そうとする必要があります...

Openlayers API:redraw:function()レイヤーを再描画します。レイヤーが再描画された場合はtrueを返し、そうでない場合はfalseを返します。

よろしく

エティエンヌ

于 2012-08-06T17:43:14.110 に答える
3

redraw()にも問題があり、これを使用します。

VecLayer.redraw(true);
VecLayer.refresh({force: true});
于 2012-08-10T08:25:55.267 に答える
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();
于 2012-10-29T14:17:19.493 に答える