Difference between revisions of "Linden Lab Official:Map API Reference"

From Second Life Wiki
Jump to: navigation, search
(MarkerOptions)
(Updated for version 2 of API)
 
(46 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Help/Box|Update notice|<b>We've made improvements and changes to the webmap, effective January 15, 2009.<br>Some information here may be out of date as we update this wiki with the changes.  Thanks for your patience.</b>}}
+
{{Supported API}}
 
+
{{:API Portal/navigation|map}}
 
+
'''NOTE:''' See the [[Linden Lab Official:Map API Introduction#Release notes|Release Notes]] for information on new features and known issues.
{{:API Portal/navigation}}
+
 
__TOC__
 
__TOC__
 
+
<br clear="all"/>
 
== Global functions ==
 
== Global functions ==
  
Line 13: Line 12:
 
!valign="top"| Description
 
!valign="top"| Description
  
 +
|-
 +
|valign="top" class="signature"|
 +
SLMap(
 +
[https://developer.mozilla.org/en/DOM/element HTMLElement] element)
 +
|[[#Map|Map]]
 +
|Creates a new map inside the specified DOM element.
 
|-
 
|-
 
|valign="top" class="signature"|
 
|valign="top" class="signature"|
Line 18: Line 23:
 
x Number,
 
x Number,
 
y Number,
 
y Number,
[[#SLMap|SLMap]] slMap)  
+
[[#Map|Map]] lmap)
 
|None
 
|None
|Launches the Second Life Viewer with the avatar's location directly to the specified inworld location.
+
|Pans the map to display the specified inworld location.
 
+
|-
+
|valign="top" class="signature"|
+
slAddDynamicScript(
+
String scriptURL,
+
function onLoadHandler)
+
|None
+
|TBD
+
 
+
 
|}
 
|}
  
 
== Objects ==
 
== Objects ==
  
=== Bounds ===
+
=== Map ===
Represents the bounds for a 2D coordinate space. Typically, you don't construct one explicitly, but rather call the getViewportBounds() method on a [[#SLMap|SLMap]] instance.
+
This class is the Leaflet class that represents the map. For more information, see [http://leafletjs.com/reference-1.0.2.html#map the Leaflet Map reference].
 
+
  
 
{{API Constructor|  
 
{{API Constructor|  
Bounds (
+
[http://leafletjs.com/reference-1.0.2.html#map Map] SLMap([https://developer.mozilla.org/en/DOM/element HTMLElement] container)
xMin Number,
+
xMax Number,
+
yMin Number,
+
yMax Number)
+
 
}}
 
}}
  
'''Properties'''
+
Creates a Leaflet map configured to display a map of Second Life.
  
{| border="2" cellspacing="0" cellpadding="3" rules="all" class="apitable"
+
The map is generated with a click event handler that calls '''gotoSLURL()''' to display a popup with a “Visit this location” link.
|- bgcolor="#A7C1F2"
+
!valign="top"| Property
+
!valign="top"| Default
+
!valign="top"| Description
+
  
|-
+
==== Useful Methods ====
|xMin
+
|Zero
+
|Minimum x coordinate of the bounding window.  Must be a postive integer.
+
  
|-
+
For other methods, see [http://leafletjs.com/reference-1.0.2.html#map-method the Leaflet Map methods reference].
|xMax
+
|Zero
+
|Maximum x coordinate of the bounding window.  Must be a postive integer.
+
 
+
|-
+
|yMin
+
|Zero
+
|Minimum y coordinate of the bounding window.  Must be a postive integer.
+
 
+
|-
+
|yMax
+
|Zero
+
|Maximum y coordinate of the bounding window.  Must be a postive integer.
+
|}
+
 
+
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.
+
 
+
{{API Constructor|
+
Icon (
+
[[#Img|Img]] mainImage,  
+
[[#Img|Img]] shadowImage )
+
}}
+
 
+
Creates a new icon to be used on the map. The optional second parameter specifies a shadow image.
+
The shadowImage argument is optional and defaults to null.
+
 
+
'''Example'''
+
 
+
// create the icons
+
var forsale_sign = new Img("Forsale.png",80,83, true); // note how the fourth parameter is set true!
+
var forsale_shadow = new Img("Forsale-shadow.png",98,83, true);
+
var forsale_icon = new Icon(forsale_sign, forsale_shadow);
+
var all_images = [forsale_icon, forsale_icon, forsale_icon, forsale_icon, forsale_icon, forsale_icon];
+
+
// create the marker
+
var marker = new Marker(all_images, new XYPoint(995,1004));
+
mapInstance.addMarker(marker);
+
 
+
=== Img ===
+
Represents an image to be used as an icon.  
+
 
+
{{API Constructor|
+
Img (
+
String imageSource,
+
Number width,
+
Number height,
+
Boolean hasAlphaChannel )
+
}}
+
 
+
The followint table describes the Img object's properites:
+
 
+
{| border="2" cellspacing="0" cellpadding="3" rules="all" class="apitable"
+
|- bgcolor="#A7C1F2"
+
!valign="top"| Property
+
!valign="top"| Default
+
!valign="top"| Description
+
 
+
|-
+
| imageSource
+
| None
+
| URL of image file.  Can be a relative or absolute URL.
+
 
+
|-
+
| width
+
| None
+
| Width of image in pixels (a positive integer).
+
 
+
|-
+
| height
+
| None
+
| Height of image in pixels (a positive integer).
+
 
+
|-
+
| hasAlphaChannel
+
| false
+
| Boolean that indicates whether the image is a 24-bit PNG image with alpha channel transparency.  Optional parameter.
+
 
+
|}
+
 
+
'''Example'''
+
 
+
// create the icons
+
var forsale_sign = new Img("Forsale.png",80,83, true); // note how the fourth parameter is set true!
+
var forsale_shadow = new Img("Forsale-shadow.png",98,83, true);
+
var forsale_icon = new Icon(forsale_sign, forsale_shadow);
+
var all_images = [forsale_icon, forsale_icon, forsale_icon, forsale_icon, forsale_icon, forsale_icon];
+
+
// create the marker
+
var marker = new Marker(all_images, new XYPoint(995,1004));
+
mapInstance.addMarker(marker);
+
 
+
'''Methods'''
+
  
 
{| border="1" cellspacing="0" cellpadding="3" rules="all" class="apitable"
 
{| border="1" cellspacing="0" cellpadding="3" rules="all" class="apitable"
Line 171: Line 53:
 
|-
 
|-
 
|valign="top" class="signature"|
 
|valign="top" class="signature"|
isAlpha()
+
[http://leafletjs.com/reference-1.0.2.html#map-setview setView](  
|Boolean
+
[http://leafletjs.com/reference-1.0.2.html#latlng LatLng] center,
|Returns true if the image has an alpha channel, false otherwise.
+
|}
+
 
+
=== MapWindow ===
+
This class represents a window placed over the map.
+
 
+
{{API 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.
+
 
+
{| border="2" cellspacing="0" cellpadding="3" rules="all" class="apitable"
+
|- bgcolor="#A7C1F2"
+
!valign="top"| Property
+
!valign="top"| Default
+
!valign="top"| 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.
+
|}
+
 
+
<span style="background: yellow">''Are all the window options implemented?  From the source, it looks like only width is implemented. And I couldn't find an example.''</span>
+
 
+
=== Marker ===
+
Represents a marker to be added on the map.  
+
 
+
{{API Constructor|
+
Marker (
+
Array icons,
+
[[#XYPoint|XYPoint]] coordinate,
+
[[#MarkerOptions|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|MarkerOptions]] argument is optional.
+
 
+
=== MarkerOptions ===
+
 
+
Object used to specify optional properties when creating a [[#Marker|Marker]] object.
+
 
+
'''Properties'''
+
 
+
{| border="2" cellspacing="0" cellpadding="3" rules="all" class="apitable"
+
|- bgcolor="#A7C1F2"
+
!valign="top"| Property
+
!valign="top"| Default
+
!valign="top"| 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.  Optional.
+
 
+
|-
+
|onMouseOverHandler
+
|null
+
|Event handler function called when mouse pointer moves over marker, that is, when onmouseover event occurs.    Optional.
+
 
+
|-
+
|onMouseOutHandler
+
|null
+
|Event handler function called when mouse pointer leaves marker, that is, when onmouseout event occurs.    Optional.
+
 
+
|-
+
|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:
+
* "top"
+
* "bottom"
+
* "middle"
+
 
+
|-
+
|horizontalAlign
+
|"center"
+
|Specifies how the marker is horizontally aligned.  Valid values are:
+
* "left"
+
* "right"
+
* "center"
+
 
+
|-
+
|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 optional clickHandler, onMouseOverHandler, and onMouseOutHandler properties specify event handler functions called when the respective events occur.
+
 
+
Example
+
 
+
var doMarkerAction = function(marker) {
+
alert("an event occured at (" + marker.slCoord.x + "," + marker.slCoord.y + ")");};
+
+
var marker = new Marker(all_images,
+
                        new XYPoint(997,1002),
+
                        {clickHandler: doMarkerAction, 
+
                          onMouseOutHandler: doMarkerAction,
+
                          onMouseOverHandler: doMarkerAction});
+
 
+
=== SLMap ===
+
This class represents the map.
+
 
+
{{API Constructor|
+
SLMap (
+
[https://developer.mozilla.org/en/DOM/element HTMLElement] container,
+
[[#SLMapOptions|SLMapOptions]] options )
+
}}
+
 
+
Creates the map. The options argument defaults to null.
+
 
+
==== Methods ====
+
 
+
{| border="1" cellspacing="0" cellpadding="3" rules="all" class="apitable"
+
|- bgcolor="#A7C1F2"
+
!valign="top"| Method
+
!valign="top"| Return Value
+
!valign="top"| Description
+
 
+
|-
+
|valign="top" class="signature"|
+
addMapWindow(
+
[[#MapWindow|MapWindow]] mapWindow,
+
[[#XYPoint|XYPoint]] coord )
+
|valign="top"| None
+
|valign="top"| Add a MapWindow to the map at specified coordinate.  
+
 
+
|-
+
|valign="top" class="signature"|
+
addMarker(
+
[[#Marker|Marker]] marker,
+
[[#MapWindow|MapWindow]] mapWindow )
+
|valign="top"| None
+
|valign="top"| Add a marker. If the optional mapWindow argument is null, then clicking on the marker will not open a window.
+
 
+
|-
+
|valign="top" class="signature"|
+
clickMarker(
+
[[#Marker|Marker]] marker)
+
|valign="top"| None
+
|valign="top"| Simulates clicking a marker. Recenters the pan if its not currently in the viewport of the map.
+
 
+
|-
+
|valign="top" class="signature"|
+
disableDragging()
+
|valign="top"| None
+
|valign="top"| Disables all dragging on the map. Note: panning controls will still work.
+
 
+
|-
+
|valign="top" class="signature"|
+
enableDragging()
+
|valign="top"| None
+
|valign="top"| Re-enables dragging on the map if it was disabled.
+
 
+
|-
+
|valign="top" class="signature"|
+
enterAndZoomAtSLCoord(
+
[[#XYPoint|XYPoint]] coordinate,  
+
 
Number zoom)
 
Number zoom)
|valign="top"| None
+
|valign="top"| [http://leafletjs.com/reference-1.0.2.html#map Map]
|valign="top"| Centers and zooms the map to the specified location.  Argument zoom must be an integer value.
+
|valign="top"| Centers and zooms the map to the specified location.  Argument zoom must be an integer value. Note that [http://leafletjs.com/examples/crs-simple/crs-simple.html#this-is-not-the-latlng-youre-looking-for a LatLng is a (Y, X) coordinate], so coordinates passed as ''center'' should be in (Y, X) order.
 
+
|-
+
|valign="top" class="signature"|
+
getCurrentZoomLevel()
+
|valign="top"| None
+
|valign="top"| Gets the current zoom level (1-6). See [http://secondlife.com/developers/mapapi/index.html#about_zoom about zoom levels].
+
 
+
|-
+
|valign="top" class="signature"|
+
getMapCenter()
+
|valign="top"|[[#XYPoint|XYPoint]]
+
|valign="top"| Returns the current map center. See [http://secondlife.com/developers/mapapi/index.html#about_coords about coordinates].
+
 
+
|-
+
|valign="top" class="signature"|
+
getViewportBounds()
+
|valign="top"|[[#Bounds|Bounds]]
+
|valign="top"| Gets the viewport bounds. See [http://secondlife.com/developers/mapapi/index.html#about_coords about coordinates].
+
 
+
|-
+
|valign="top" class="signature"|
+
panDown()
+
|valign="top"| None
+
|valign="top"| Pan the map down by half its width.
+
 
+
|-
+
|valign="top" class="signature"|
+
panLeft()
+
|valign="top"| None
+
|valign="top"| Pan the map left by half its width.
+
 
+
|-
+
|valign="top" class="signature"|
+
panOrRecenterToSLCoord(
+
[[#XYPoint|XYPoint]] coord,
+
Boolean recenter )
+
|valign="top"| None
+
|valign="top"| 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.
+
 
+
|-
+
|valign="top" class="signature"|
+
panRight()
+
|valign="top"| None
+
|valign="top"| Pan the map right by half its width.
+
 
+
|-
+
|valign="top" class="signature"|
+
panUp()
+
|valign="top"| None
+
|valign="top"| Pan the map up by half its width.
+
 
+
|-
+
|valign="top" class="signature"|
+
removeAllMarkers() 
+
|valign="top"| None
+
|valign="top"| Remove all markers.
+
 
+
|-
+
|valign="top" class="signature"|
+
removeMarker(
+
[[#Marker|Marker]] marker) 
+
|valign="top"| None
+
|valign="top"| Remove a marker.
+
 
+
|-
+
|valign="top" class="signature"|
+
setCurrentZoomLevel(
+
Number zoom)  
+
|valign="top"| None
+
|valign="top"| Set the zoom level to specified value.  Argument zoom must be an integer.
+
 
+
|-
+
|valign="top" class="signature"|
+
zoomIn()
+
|valign="top"| None
+
|valign="top"| Zoom in on the map if the map is not already all the way zoomed in.
+
 
+
|-
+
|valign="top" class="signature"|
+
zoomOut()
+
|valign="top"| None
+
|valign="top"| Zoom out on the map if the map is not already all the way zoomed out.  
+
 
|}
 
|}
  
=== SLMapOptions ===
+
== Utility URLs ==
This class represents optional arguments to the SLMap constructor. It has no constructor, but is instantiated as an object literal.
+
These map helper functions are available from the caps server. The JSON-like results return text that Javascript could eval(), but scripts coming from outside should parse them the "hard" way for safety.
  
'''Properties'''
+
=== Region name from global coordinates ===
 +
https<nowiki></nowiki>://cap.secondlife.com/cap/0/'''b713fe80-283b-4585-af4d-a3b7d9a32492'''?'''var'''=''varName''&'''grid_x'''=''xcoord''&'''grid_y'''=''ycoord''
 +
* '''var''' is arbitrary, for output formatting.
 +
* '''grid_x''' is the region's global x coordinate as an integer.
 +
* '''grid_y''' is the region's global y coordinate as an integer.
  
{| border="2" cellspacing="0" cellpadding="3" rules="all" class="apitable"
+
'''Example'''
|- bgcolor="#A7C1F2"
+
https://cap.secondlife.com/cap/0/b713fe80-283b-4585-af4d-a3b7d9a32492?var=region&grid_x=1000&grid_y=1000
!valign="top"| Property
+
:Returns: <pre>var region='Da Boom';</pre>
!valign="top"| Default
+
!valign="top"| Description
+
  
|-
+
=== Global coordinates from region name ===
|hasZoomControls
+
https<nowiki></nowiki>://cap.secondlife.com/cap/0/'''d661249b-2b5a-4436-966a-3d3b8d7a574f'''?'''var'''=''varName''&'''sim_name'''=''RegionName''
|true
+
* '''var''' is arbitrary, for output formatting.
|Whether the map has zoom controls.
+
* '''sim_name''' is a region on the Second Life map.
  
|-
+
'''Example'''
|hasPanningControls
+
https://cap.secondlife.com/cap/0/d661249b-2b5a-4436-966a-3d3b8d7a574f?var=coords&sim_name=Da%20Boom
|true
+
:Returns: <pre>var coords = {'x' : 1000, 'y' : 1000 };</pre>
|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 [http://secondlife.com/developers/mapapi/index.html#adv_double_click 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 [http://secondlife.com/developers/mapapi/index.html#adv_onstatechanged guide] for more.
+
 
+
=== SLPoint ===
+
 
+
Not currently implemented.
+
 
+
<!--
+
Represents a point in Second Life.
+
 
+
 
+
{{API Constructor|
+
SLPoint (String Region_name,
+
Int local_x,
+
Int local_y )
+
 
+
Creates an SLPoint object.
+
 
+
'''Properties'''
+
 
+
{| border="2" cellspacing="0" cellpadding="3" rules="all" class="apitable"
+
|- bgcolor="#A7C1F2"
+
!valign="top"| Property
+
!valign="top"| Default
+
!valign="top"| Description
+
|-
+
|x
+
|X coordinate
+
 
+
|-
+
|y
+
|Y coordinate
+
|}
+
 
+
Note - The region name is case insensitive; for example, so to specificy "Da Boom" region, use either:
+
 
+
* SLPoint("da boom")
+
* SLPoint("dA bOOm")
+
-->
+
=== XYPoint ===
+
Represents a point in 2D coordinate space.
+
 
+
{{API Constructor|
+
XYPoint (
+
Number x,  
+
Number y )
+
}}
+
 
+
Creates an XYPoint object.
+
 
+
'''Properties'''
+
 
+
{| border="2" cellspacing="0" cellpadding="3" rules="all" class="apitable"
+
|- bgcolor="#A7C1F2"
+
!valign="top"| Property
+
!valign="top"| Default
+
!valign="top"| Description
+
 
+
|-
+
|x
+
|None
+
|X coordinate
+
 
+
|-
+
|y
+
|None
+
|Y coordinate
+
|}
+

Latest revision as of 18:23, 13 December 2016

Ll color vert 100.gif
Official Linden Lab® Information: You may access and link to this page, but you may not copy, distribute, modify, adapt, or translate any content on this page. This content is subject to the Terms of Service and is not available under the Creative Commons or any other license.

Have a suggestion to improve this page? Contact us.
NOTE: This is an official Second Life API provided and documented by Linden Lab. Its use is subject to the API Terms of Use.

NOTE: See the Release Notes for information on new features and known issues.


Global functions

Function Return Value Description

SLMap( HTMLElement element)

Map Creates a new map inside the specified DOM element.

gotoSLURL( x Number, y Number, Map lmap)

None Pans the map to display the specified inworld location.

Objects

Map

This class is the Leaflet class that represents the map. For more information, see the Leaflet Map reference.

Constructor

Map SLMap(HTMLElement container)

Creates a Leaflet map configured to display a map of Second Life.

The map is generated with a click event handler that calls gotoSLURL() to display a popup with a “Visit this location” link.

Useful Methods

For other methods, see the Leaflet Map methods reference.

Method Return Value Description

setView( LatLng center, Number zoom)

Map Centers and zooms the map to the specified location. Argument zoom must be an integer value. Note that a LatLng is a (Y, X) coordinate, so coordinates passed as center should be in (Y, X) order.

Utility URLs

These map helper functions are available from the caps server. The JSON-like results return text that Javascript could eval(), but scripts coming from outside should parse them the "hard" way for safety.

Region name from global coordinates

https://cap.secondlife.com/cap/0/b713fe80-283b-4585-af4d-a3b7d9a32492?var=varName&grid_x=xcoord&grid_y=ycoord

  • var is arbitrary, for output formatting.
  • grid_x is the region's global x coordinate as an integer.
  • grid_y is the region's global y coordinate as an integer.

Example

https://cap.secondlife.com/cap/0/b713fe80-283b-4585-af4d-a3b7d9a32492?var=region&grid_x=1000&grid_y=1000
Returns:
var region='Da Boom';

Global coordinates from region name

https://cap.secondlife.com/cap/0/d661249b-2b5a-4436-966a-3d3b8d7a574f?var=varName&sim_name=RegionName

  • var is arbitrary, for output formatting.
  • sim_name is a region on the Second Life map.

Example

https://cap.secondlife.com/cap/0/d661249b-2b5a-4436-966a-3d3b8d7a574f?var=coords&sim_name=Da%20Boom
Returns:
var coords = {'x' : 1000, 'y' : 1000 };