开发者

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 开发者_JAVA百科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,


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


See Object Literals and Using Object Initializers at MDC.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜