Within the openlayers documentation I’ve noticed that “options” is many times used to show that the constructor takes parameters. But where can I get the details for this parameter {object}? How does one know what parameters the constructors accepts?

For example: below I have put the constructor documentation for OpenLayers.Filter.Spatial.

How do I know what properties I can put within {Object}?

enter image description here

1 Answer 1


The best thing about open source is that you can see exactly what is going on by browsing the source code. When constructing a spatial filter, a new object is initialised with the following initialize function:

72      initialize: function(options) {
73          OpenLayers.Filter.prototype.initialize.apply(this, [options]);
74      },

This can be seen in the online source control. The apply function copies all the properties from your configuration object (the options parameter) to the properties of a new spatial filter object (the keyword this in the above code).

So in answer to your question, you can create a config object with any of the properties listed in the spatial filter (type, property, value etc.) and they will be set on your new object.

One of the best ways to see how to use OpenLayers classes (along with the examples) is to find their associated unit tests. For example the tests for OpenLayers.Filter.Spatial are at http://trac.osgeo.org/openlayers/browser/trunk/openlayers/tests/Filter/Spatial.html

These tests show many different examples of the construction of the spatial filter class (and how to use it once constructed) e.g.

28          var filer, feature, res, geom, bounds;
30          bounds = new OpenLayers.Bounds(0, 0, 10, 10);
31          filter = new OpenLayers.Filter.Spatial({
32              type: OpenLayers.Filter.Spatial.BBOX,
33              value: bounds
34          });

You can use these techniques to find out about how any OpenLayers class is constructed, and exactly what happens when you create a new object.

  • Thanks, +1 for the suggestion of looking for the tests. (value added to your answer)
    – CaptDragon
    Mar 9, 2011 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.