Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 12 down vote accepted

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;
29  
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.

share|improve this answer
    
Thanks, +1 for the suggestion of looking for the tests. (value added to your answer) –  CaptDragon Mar 9 '11 at 17:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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