[GIS] Dynamically changed url in the Vector layer protocol not taken into account after refresh

javascriptopenlayers-2

I have a map which I try to change dynamically its url when the user clicks a radio button.

Here is my code :

var refreshLayer = new OpenLayers.Strategy.Refresh({ force: true, active: true });
var fromProjection = new OpenLayers.Projection("EPSG:4326");
var toProjection = new OpenLayers.Projection("EPSG:3857");
var vectorProtocol = new OpenLayers.Protocol.HTTP({
        url: '/getmaindata',
        format: new OpenLayers.Format.GeoJSON({
            'internalProjection': fromProjection,
            'externalProjection': toProjection
        }),
        params: {
            "naf": "04"
        }
    });
var map = new OpenLayers.Map("map_element");
var vectorStrategies = [new OpenLayers.Strategy.Fixed(), refreshLayer];
var osmLayer = new OpenLayers.Layer.OSM();
var vectorLayer = new OpenLayers.Layer.Vector('vector_layer', {
   protocol: vectorProtocol,
   strategies: vectorStrategies
});

map.addLayers([osmLayer, vectorLayer]);

(...)

// $radio is my radiobutton
$radio.onclick = function() {
      vectorProtocol.url = "/getouterdata";
      refreshLayer.refresh({force: true});
});

When I debug with Firebug, I notice that the url is correctly changed in my layer's protocol object. However, what is called is the previous url (/getmaindata) instead of the new one (/getouterdata).
So I was asking myself if there was something I did wrong. When is the new url called ? Is it by calling the refresh() method of my Strategy.Refresh ? Or somewhere else ? Maybe the old url is cached ?

Best Answer

Problem solved : 'url' is located in the 'options' field of vectorProtocol

$radio.onclick = function() {
      vectorProtocol.options.url = "/getouterdata";
      refreshLayer.refresh({force: true});
});