Extends dispatch.
Sets or gets the constraints on the map center. If the argument x is specified, it sets the new center range, and returns this. If no arguments are specified, it returns the current center range.
The constraints are defined as a two-element location array: the locations of the south-west and north-east corners of the visible region. If the center range is null, then no constraints are enforced on the center. The default center range is:
[{lat: -85.05112877980659, lon: -Infinity}, {lat: +85.05112877980659, lon: +Infinity}]The default behavior thus ensures that one row of tiles is visible at zoom level zero, with infinite wrapping of longitudes. The latitude range of [-85.0…, +85.0…] is based on the Spherical Mercator projection. Latitudes of -90 or less, and +90 or greater, are treated as unbounded.
The constraint enforces that some part of the map (as defined by the center range) is visible within the viewport. This visible region may be infinitely small, as when the map is pushed entirely off-screen. However, because the map is immediately off-screen, it is easy to pull back into view. This behavior also ensures that any visible location on the map can be zoomed in or out without changing its point on-screen.
Sets or gets the map zoom level; a nonnegative number. If the argument x is specified, it sets the new map zoom level, and returns this. If no arguments are specified, it returns the current zoom level.
The loaded tiles’ zoom level (assuming the layer is not transformed) will be the rounded map zoom level. Thus, at zoom level 0.49, tiles at zoom level 0 will be loaded and magnified; at zoom level 0.51, tiles at zoom level 1 will be loaded and minified.
Sets or gets the constraints on the map zoom level; a two-element array of nonnegative numbers representing the minimum and maximum (both inclusive) zoom levels. If the argument x is specified, it sets the new zoom range, and returns this. If no arguments are specified, it returns the current zoom range.
If the zoom range is null, then no constraints are enforced on the zoom level. The default zoom range is [1, 18], but may change in subsequent releases.
Zooms the map by the specified zoom level delta z, and returns this. The new zoom level after this method returns is the old zoom level plus z.
Two optional arguments may be specified. The second argument x0 specifies a position in the map’s coordinate space. The location at the given position will be preserved after the zoom. For example, to zoom in on the location under the cursor, specify map.mouse(e), where e is a mouse event. The third argument l specifies the location at x0 explicitly; thus, this method may also be used to zoom and set the location at the given point simultaneously, which is faster than setting the zoom and map sequentially.
Sets or gets the extent of the map. If the argument x is specified, it sets the new extent, and returns this. If no arguments are specified, it returns the current extent.
The extent is defined as a two-element location array, similar to the center range: the locations of the south-west and north-east corners of the visible region. The current extent is computed as:
[map.pointLocation({x: 0, y: size.y}), map.pointLocation({x: size.x, y: 0})]where size is the current map size.
If the aspect ratio of the specified extent does not match the aspect ratio of the current map size, then the extent is expanded to match the current aspect ratio; the extent is fully-visible after this method returns. Note that the zoom level may not be an integer after setting the extent.
Sets or gets the tile size, in pixels. If the argument x is specified, it sets the tile size and returns this. If no arguments are specified, it returns the current tile size. The tile size is represented as an object with x and y positive number attributes. The default tile size is {x: 256, y: 256}.
Note: currently the tile size must be set before any tiles are loaded, and may not be changed after tiles are loaded. Tiles may be reloaded using layer.reload, but changing tile size is not yet supported.
Sets or gets the map container element. If the argument x is specified, it sets the map container, and returns this. If no arguments are specified, it returns the current container. The map container must be either an SVG svg element or an SVG g element. The class attribute of the container element will be set to “map”.
Note: currently the container must be set before any objects are added to the map, and may not be changed after objects are added. This restriction may be removed in a future release.
Sets or gets the map size. If the argument x is specified, it sets the map size, and returns this. If no arguments are specified, it returns the current container. The map size is represented as an object with x and y positive number attributes.
The default map size is null, which causes the map to infer its size from the bounds of the container. If the container is an SVG g element, the owner svg element is used to compute the inferred size. In addition, if the map size is set to null, the map listens to the window for resize events, updating the map size automatically. When the map size is null, calling this method with no arguments will return the inferred size of the map, rather than null.
Maps use the dispatch mechanism to notify interested parties of events. Maps currently support two types of events: “move” and “resize”. The move event is dispatched whenever the map center or zoom level changes. The resize event is dispatched whenever the map size changes. Listeners that depend on the visible region should typically listen for both move and resize events, while static overlays (such as the compass control) only need to listen for resize events. These events currently have no additional metadata describing the event, though that additional descriptive information may be added in a future release.
Returns the position of the mouse, as determined from the given mouse event e, in the map’s coordinate space. The returned position is an object with x and y number attributes. Typically, this method returns the pageX and pageY attributes of the event e, minus the top-left position of the map container; however, this method takes into consideration any custom transforms that have been applied to the map container through SVG.
This method is based on the W3C specification for getScreenCTM.