Skip to main content
added 78 characters in body
Source Link
atlefren
  • 4.3k
  • 21
  • 36

I think your scoping has gone haywire.

(if i understand your code corrctly) You have two functions: createWmsLayer and CQLfilter.

in the line var ikke_listet = new createWmsLayer...

you assign the returned value of the call to createWmsLayer to the variable ikke_listet. The problem is that createWmsLayer does not return anything.

So, you should rewrite it to :

var createWmsLayer = function(name, url, params, options) {
    var layer = new OpenLayers.Layer.WMS(name, url, params, options);
    map.addLayer(layer);         
    return layer;
};

as variables created inside functions are not available outside (scoping).

On another note: while you do reach map inside the createWmsLayer fucntion, this is only because you have defined the map variable before the you define the function, so you should pass that as an input parameter as well.

But, basically; remember to return any variables created inside a function in order to use them outside of the function

EDIT: and skip the "new" keyword when calling your createWmsLayer function

I think your scoping has gone haywire.

(if i understand your code corrctly) You have two functions: createWmsLayer and CQLfilter.

in the line var ikke_listet = new createWmsLayer...

you assign the returned value of the call to createWmsLayer to the variable ikke_listet. The problem is that createWmsLayer does not return anything.

So, you should rewrite it to :

var createWmsLayer = function(name, url, params, options) {
    var layer = new OpenLayers.Layer.WMS(name, url, params, options);
    map.addLayer(layer);         
    return layer;
};

as variables created inside functions are not available outside (scoping).

On another note: while you do reach map inside the createWmsLayer fucntion, this is only because you have defined the map variable before the you define the function, so you should pass that as an input parameter as well.

But, basically; remember to return any variables created inside a function in order to use them outside of the function

I think your scoping has gone haywire.

(if i understand your code corrctly) You have two functions: createWmsLayer and CQLfilter.

in the line var ikke_listet = new createWmsLayer...

you assign the returned value of the call to createWmsLayer to the variable ikke_listet. The problem is that createWmsLayer does not return anything.

So, you should rewrite it to :

var createWmsLayer = function(name, url, params, options) {
    var layer = new OpenLayers.Layer.WMS(name, url, params, options);
    map.addLayer(layer);         
    return layer;
};

as variables created inside functions are not available outside (scoping).

On another note: while you do reach map inside the createWmsLayer fucntion, this is only because you have defined the map variable before the you define the function, so you should pass that as an input parameter as well.

But, basically; remember to return any variables created inside a function in order to use them outside of the function

EDIT: and skip the "new" keyword when calling your createWmsLayer function

Source Link
atlefren
  • 4.3k
  • 21
  • 36

I think your scoping has gone haywire.

(if i understand your code corrctly) You have two functions: createWmsLayer and CQLfilter.

in the line var ikke_listet = new createWmsLayer...

you assign the returned value of the call to createWmsLayer to the variable ikke_listet. The problem is that createWmsLayer does not return anything.

So, you should rewrite it to :

var createWmsLayer = function(name, url, params, options) {
    var layer = new OpenLayers.Layer.WMS(name, url, params, options);
    map.addLayer(layer);         
    return layer;
};

as variables created inside functions are not available outside (scoping).

On another note: while you do reach map inside the createWmsLayer fucntion, this is only because you have defined the map variable before the you define the function, so you should pass that as an input parameter as well.

But, basically; remember to return any variables created inside a function in order to use them outside of the function