views:

83

answers:

3

Hi,

I'm trying to work with openstreetmap through openlayers, and I have encountered a biit of Javascript syntax that I don't understand (I'm no expert with Javascript - just beginning to learn how it handles objects at the moment...)

Here it is anyway...

map = new OpenLayers.Map ("map", {
 controls:[
  new OpenLayers.Control.Navigation(),
  new OpenLayers.Control.PanZoomBar(),
  new OpenLayers.Control.LayerSwitcher(),
  new OpenLayers.Control.Attribution()],
 maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
    maxResolution: 156543.0399,
 numZoomLevels: 19,
 units: 'm',
 projection: new OpenLayers.Projection("EPSG:900913"),
 displayProjection: new OpenLayers.Projection("EPSG:4326")
} );

Is this simply saying the first parameter in the map constructor is what you would expect it to be, an the { ... } is enclosing a collection of named parameters?

That's what it looks like to me, but I'd appreciate the nod from someone a little more familiar with it...

Cheers,

+1  A: 

The { foo: bar, bax: qux } syntax is an object literal. It creates an object and sets those fields.

Mark Byers
Thanks... I get it now... Sort of an anonymous type idea then...
Martin Milan
+2  A: 

The first parameter is the HTML element that will contain the map, and the second parameter is an object that contains extended options. The properties "controls", "maxExtent" and so on are properties of that object and OpenLayers will later be able to access them by name with options.maxExtent, for instance (see documentation here).

AndiDog
Cheers for that - I get it now... (and thanks for the link)
Martin Milan
+2  A: 

See Object Literals and Using Object Initializers at MDC.

Christoph
Thanks for that...
Martin Milan