Linden Lab Official:Map API Reference
We've made improvements and changes to the webmap, effective January 15, 2009.
Some information here may be out of date as we update this wiki with the changes. Thanks for your patience.
Global functions
Function | Return Value | Description |
---|---|---|
gotoSLURL( x, y, SLMap slMap) |
None | Launches the Second Life Viewer with the avatar's location directly to the specified inworld location. |
slAddDynamicScript( String scriptURL, function onLoadHandler) |
None | TBD |
Objects
Bounds
Represents the bounds for a 2D coordinate space. Typically, you don't construct one explicitly, but rather call the SLMap getViewportBounds() method.
Constructor
Bounds ( xMin, xMax, yMin, yMax)
Properties
Property | Default | Description |
---|---|---|
xMin | Zero | Minimum x coordinate of the bounding window. |
xMax | Zero | Maximum x coordinate of the bounding window. |
yMin | Zero | Minimum y coordinate of the bounding window. |
yMax | Zero | Maximum y coordinate of the bounding window. |
NOTE: The default values are applied if any of the properties is not specified in the constructor call.
Example
... var mapInstance = new SLMap(document.getElementById('map-container')); var bounds = mapInstance.getViewportBounds(); // This is a Bounds object ...
Icon
Represents an icon to used as a marker.
Constructor
Creates a new icon to be used on the map. The optional second parameter specifies a shadow image. See the guide for more. shadowImage defaults to null.
Img
Represents an image to be used as an icon.
Constructor
Img ( String imageSource, Number width, Number height, Boolean hasAlphaChannel )
Property | Default | Description |
---|---|---|
imageSource | None | URL of image file. Can be a relative or absolute URL. |
width | None | Width of image in pixels (an integer). |
height | None | Height of image in pixels (an integer). |
hasAlphaChannel | false | Whether the image is a 24-bit PNG image with alpha channel transparency. Optional parameter. |
See the guide for more.
Methods
Method | Return Value | Description |
---|---|---|
isAlpha() |
Boolean | Returns true if the image has an alpha channel, false otherwise. |
MapWindow
This class represents a window placed over the map.
Constructor
MapWindow ( String windowText, options )
Creates a new map window. The given text will be what is contained in the window. Note, HTML can be used but quotes must be escaped correctly otherwise javascript errors will occur.
The options argument is an object literal that specifies the window options, as described in the following table.
Property | Default | Description |
---|---|---|
alwaysOnTop | false | Whether window is always displayed on top of other windows. |
noEffect | false | Whether window appears with fade-in and fade-out effect. |
closeOnMove | false | Whether window is closed when user drags the map. |
bringToTop | false | Whether window is brought to the top when user clicks other windows. |
width | 252 | Width of the window in pixels. |
height | 236 | Height of the window in pixels. |
padding | 10 | Padding of the window in pixels. |
Are the window options implemented? It didn't seem so from the source, and I couldn't find an example.
Marker
Represents a marker to be added on the map.
Constructor
Marker ( Array icons, XYPoint coordinate, MarkerOptions markerOptions )
Creates a new marker to be placed on the map at given coordinate. The first parameter is an array of icons of length 6. Each icon in the array corresponds to a zoom level, icons[0] being the icon used at the close zoom (level 0).
The MarkerOptions argument is optional.
MarkerOptions
Object used to specify optional properties when creating a Marker object.
Properties
Property | Default | Description |
---|---|---|
centerOnClick | false | If true, centers the map on the marker when user clicks on it. |
clickHandler | null | Event handler function called when user clicks on marker, that is, when onClick event. |
onMouseOverHandler | null | Event handler function called when mouse pointer moves over marker, that is, when onmouseover event occurs. |
onMouseOutHandler | null | Event handler function called when mouse pointer leaves marker, that is, when onmouseout event occurs. |
autopanOnClick | true | If true, the map will automatically pan the map if part of the associated MapWindow would have been clipped by an edge of the map when it was opened. |
autopanPadding | 45 | How close the window needs to be (in pixels) to an edge of the map to trigger autopanning. |
verticalAlign | "middle" | Specifies how the marker is vertically aligned. Valid values are:
|
horizontalAlign | "center" | Specifies how the marker is horizontally aligned. Valid values are:
|
zLayer | 0 | Specifies the layer the marker will render on. For example, if a marker having zLayer = 1 and another marker having zLayer = 0 overlap, the marker with zLayer = 1 will be on top. |
The clickHandler, onMouseOverHandler, and onMouseOutHandler options specify optional functions that get called when their respective events occur. See the guide for more.
SLMap
This class represents the map.
Constructor
SLMap ( HTMLElement container, SLMapOptions options )
Creates the map. The options argument defaults to null.
Methods
Method | Return Value | Description |
---|---|---|
None | Add a MapWindow to the map at specified coordinate. | |
None | Add a marker. If the optional mapWindow argument is null, then clicking on the marker will not open a window. | |
clickMarker( Marker marker) |
None | Simulates clicking a marker. Recenters the pan if its not currently in the viewport of the map. |
disableDragging() |
None | Disables all dragging on the map. Note: panning controls will still work. |
enableDragging() |
None | Re-enables dragging on the map if it was disabled. |
enterAndZoomAtSLCoord( XYPoint coordinate, Number zoom) |
None | Centers and zooms the map to the specified location. Argument zoom must be an integer value. |
getCurrentZoomLevel() |
None | Gets the current zoom level (1-6). See about zoom levels. |
getMapCenter() |
XYPoint | Returns the current map center. See about coordinates. |
getViewportBounds() |
Bounds | Gets the viewport bounds. See about coordinates. |
panDown() |
None | Pan the map down by half its width. |
panLeft() |
None | Pan the map left by half its width. |
panOrRecenterToSLCoord( XYPoint coord, Boolean recenter ) |
None | Pan the map to the given coordinate if it is currently in the viewport (in the user's view). Otherwise, recenters the map to the given coordinate. The optional recenter argument specifies whether to center the given coordinate even it if is currently in the viewport. Its default value is false. |
panRight() |
None | Pan the map right by half its width. |
panUp() |
None | Pan the map up by half its width. |
removeAllMarkers() |
None | Remove all markers. |
removeMarker( Marker marker) |
None | Remove a marker. |
setCurrentZoomLevel( Number zoom) |
None | Set the zoom level to specified value. Argument zoom must be an integer. |
zoomIn() |
None | Zoom in on the map if the map is not already all the way zoomed in. |
zoomOut() |
None | Zoom out on the map if the map is not already all the way zoomed out. |
SLMapOptions
This class represents optional arguments to the SLMap constructor. It has no constructor, but is instantiated as an object literal.
Properties
Property | Default | Description |
---|---|---|
hasZoomControls | true | Whether the map has zoom controls. |
hasPanningControls | true | Whether the map has pan controls. |
doubleClickHandler | null | Specifies a double click function. |
singleClickHandler | null | Specifies a single click function |
onStateChangedHandler | null | Specifies an onstatechanged handler function |
zoomMin | 6 | Specifies an minimum level a map can be zoomed to. Currently the maximum for this value is 7. |
zoomMax | 1 | Specifies an maximum level a map can be zoomed to. Currently the minimum for this value is 1. |
The doubleClickHandler and singleClickHandler option can be assigned to call a function whenever a place on the map is double-clicked or single-clicked respectively. See the guide for more.
The onStateChangedHandler option can be assigned to call a function whenever the "state" of the map changes (i.e. whenever the map bounds change). Likewise, see the guide for more.
SLPoint
Not currently implemented.
XYPoint
Represents a point in 2D coordinate space.
Constructor
XYPoint ( Number x, Number y )
Creates an XYPoint object.
Properties
Property | Default | Description |
---|---|---|
x | None | X coordinate |
y | None | Y coordinate |