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

From Second Life Wiki
Jump to navigation Jump to search
(Updated for version 2 of API)
 
(83 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== SLMap ==
{{Supported API}}
This class represents the map.
{{: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.
__TOC__
<br clear="all"/>
== Global functions ==


=== Constructor ===
{| border="1" cellspacing="0" cellpadding="3" rules="all" class="apitable"
 
{{API Constructor|
SLMap (
HTMLElement container,
SLMapOptions options )
}}
 
Creates the map. The SLMapOptions argument is optional.
 
=== Methods ===
 
{| border="2" cellspacing="0" cellpadding="3" rules="all" style="margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse; background-color:#F9F9F9; font-size:90%; empty-cells:show; "
|- bgcolor="#A7C1F2"
|- bgcolor="#A7C1F2"
! Method
!valign="top"| Function
! Return Value
!valign="top"| Return Value
! Description
!valign="top"| Description
 


|-
|-
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0; white-space: pre;"|addMapWindow (
|valign="top" class="signature"|
MapWindow mapWindow,
SLMap(
XYPoint coord)  
[https://developer.mozilla.org/en/DOM/element HTMLElement] element)
|valign="top"| None
|[[#Map|Map]]
|valign="top"| Adds a MapWindow to the map at specified coordinate.  
|Creates a new map inside the specified DOM element.
 
|-
|-
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin: 0; white-space: pre;"|addMarker (
|valign="top" class="signature"|
Marker marker,  
gotoSLURL(
MapWindow mapWindow )
x Number,
|valign="top"| None
y Number,
|valign="top"| Adds a marker. If the optional mapWindow argument is null, then clicking on the marker will not open a window.
[[#Map|Map]] lmap)
|None
|Pans the map to display the specified inworld location.
|}


|-
== Objects ==
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0; white-space:pre;"|clickMarker (
Marker marker)
|valign="top"| None
|valign="top"|
Simulates a clicking a marker. Will recenter the pan if its not currently in the viewport of the map.


|-
=== Map ===
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|disableDragging ()
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].
|valign="top"| None
|valign="top"|
Disables all dragging on the map. Note: panning controls will still work.  


|-
{{API Constructor|  
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|enableDragging ()
[http://leafletjs.com/reference-1.0.2.html#map Map] SLMap([https://developer.mozilla.org/en/DOM/element HTMLElement] container)
|valign="top"| None
}}
|valign="top"|
Re-enables dragging on the map if it was disabled.  
 
|-
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin: 0; white-space: pre;"|enterAndZoomAtSLCoord(
XYPoint coordinate,
int zoom)
|valign="top"| None
|valign="top"| Centers and zooms the map to the specified location.
 
|-
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|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].


|-
Creates a Leaflet map configured to display a map of Second Life.
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|getMapCenter ()
|valign="top"|XYPoint
|valign="top"|
Returns the current map center. See [http://secondlife.com/developers/mapapi/index.html#about_coords about coordinates].


|-
The map is generated with a click event handler that calls '''gotoSLURL()''' to display a popup with a “Visit this location” link.
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|getViewportBounds ()  
|valign="top"|Bounds
|valign="top"|
Gets the viewport bounds. See [http://secondlife.com/developers/mapapi/index.html#about_coords about coordinates].  


|-
==== Useful Methods ====
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|panDown ()
|valign="top"| None
|valign="top"|
Pans the map to the down by half its width.


|-
For other methods, see [http://leafletjs.com/reference-1.0.2.html#map-method the Leaflet Map methods reference].
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|panLeft ()
|valign="top"| None
|valign="top"|
Pans the map to the left by 1/2 its width.


|-
{| border="1" cellspacing="0" cellpadding="3" rules="all" class="apitable"
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0; white-space: pre;"|panOrRecenterToSLCoord (
|- bgcolor="#A7C1F2"
XYPoint coord,
!valign="top"| Method
Boolean recenter )
!valign="top"| Return Value
|valign="top"| None
!valign="top"| Description
|valign="top"|
Pans 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" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|panRight ()
|valign="top" class="signature"|
|valign="top"| None
[http://leafletjs.com/reference-1.0.2.html#map-setview setView](
|valign="top"|
[http://leafletjs.com/reference-1.0.2.html#latlng LatLng] center,
Pans the map to the right by 1/2 its width.  
Number zoom)
|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. 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.
|}


|-
== Utility URLs ==
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|panUp ()
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.
|valign="top"| None
|valign="top"|
Pans the map to the up by 1/2 its width.  
 
|-
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|removeAllMarkers ()
|valign="top"| None
|valign="top"|
Removes all markers.


|-
=== Region name from global coordinates ===
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0; white-space: pre;"|removeMarker (
https<nowiki></nowiki>://cap.secondlife.com/cap/0/'''b713fe80-283b-4585-af4d-a3b7d9a32492'''?'''var'''=''varName''&'''grid_x'''=''xcoord''&'''grid_y'''=''ycoord''
Marker marker) 
* '''var''' is arbitrary, for output formatting.
|valign="top"| None
* '''grid_x''' is the region's global x coordinate as an integer.
|valign="top"| Removes a marker.
* '''grid_y''' is the region's global y coordinate as an integer.


|-
'''Example'''
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0; white-space: pre;"|setCurrentZoomLevel (
https://cap.secondlife.com/cap/0/b713fe80-283b-4585-af4d-a3b7d9a32492?var=region&grid_x=1000&grid_y=1000
int zoom)
:Returns: <pre>var region='Da Boom';</pre>
|valign="top"| None
|valign="top"| Sets the zoom level to specified zoom.


|-
=== Global coordinates from region name ===
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|zoomIn ()
https<nowiki></nowiki>://cap.secondlife.com/cap/0/'''d661249b-2b5a-4436-966a-3d3b8d7a574f'''?'''var'''=''varName''&'''sim_name'''=''RegionName''
|valign="top"| None
* '''var''' is arbitrary, for output formatting.
|valign="top"|
* '''sim_name''' is a region on the Second Life map.
Zooms in on the map if the map is not already all the way zoomed in.


|-
'''Example'''
|valign="top" style="font: 10pt courier; padding: 10px 10px 0 10px; margin:0;"|zoomOut ()
https://cap.secondlife.com/cap/0/d661249b-2b5a-4436-966a-3d3b8d7a574f?var=coords&sim_name=Da%20Boom
|valign="top"| None
:Returns: <pre>var coords = {'x' : 1000, 'y' : 1000 };</pre>
|valign="top"|
Zooms out on the map if the map is not already all the way zoomed out.
|}

Latest revision as of 18:23, 13 December 2016

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 };