Search code examples
openlayersstoregeoext

GeoExt reload FeatureStore changing url


I'm trying to reload a GeoExt.data.FeatureStore changing url. This is my code:

 var vecLayer = new OpenLayers.Layer.Vector("vector", {
            protocol: new OpenLayers.Protocol.HTTP({
                url: '/url',
                format: new OpenLayers.Format.GeoJSON()
            }),
            strategies: [new OpenLayers.Strategy.Fixed()]
        });

 var store = Ext.create('GeoExt.data.FeatureStore', {
        layer: vecLayer,
        fields: [
            {name: 'name', type: 'string'},
            {name: 'elevation', type: 'float'}
        ],
        autoLoad: true
    });

 mycombo.addListener('change', function() {
            vecLayer.protocol.url = "/url2";
            vecLayer.refresh();
        });

I can see the request is made in Firebug console, but the url is "/url" not "/url2" as I expect. Also tried with

store.proxy.url = "url2";

since FeatureStore inherit from Ext.data.Store but no luck.


Solution

  • I've got it! I have to replace the protocol:

     mycombo.addListener('change', function() {
            var proto = new OpenLayers.Protocol.HTTP({
                url: new_url,
                format: new OpenLayers.Format.GeoJSON()
            });
            vecLayer.protocol = proto;
            vecLayer.refresh();
     });