Search code examples
javascriptparametersopenlayers

Javascript syntax (2 minute question)


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,


Solution

  • 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).