Linden Lab Official talk:Map API

From Second Life Wiki
Revision as of 17:52, 20 June 2009 by Sasun Steinbeck (talk | contribs) (SLPoint hack)
Jump to navigation Jump to search

Previously, SIM images were available in-world if you knew their UUID, is this going to be the case with the new images, or is there any other way to get a SIM image onto a prim (without using the web page on a prim stuff)?

-- Talwyn Mills.



Will SLPoint be implemented again since the changes made to the API?

The removal of this crucial function has broken most of the user interface at bloghud.com, used by many to blog their Second lives to meatspace. Also many other sites which used this have also broken now. —The preceding unsigned comment was added on 20:18, 3 October 2007 by Koz Farina

Alternate version of the webmap API

Just a headsup that I've been working on an alternate API for the Second Life webmap: User:SignpostMarv Martin/Webmap API - SignpostMarv Martin 12:06, 28 December 2007 (PST)

disableVoiceInfo and In-World map tiles.

I know on the old Map API you could display an icon showing if that region supported voice chat or not. Not all regions choose to do so, and apparently the map API was able to determine how the estate owner had set that option. I believe that is what the disableVoiceInfo indicated,whether this information was shown or not.

I would like to echo Talwyn Mills' concern about the future of in-world map tile textures. Having the ability to display maps in-world is a feature that shouldn't be forgotten in this endeavor. Darien Caldwell 23:47, 27 January 2009 (UTC)

SLPoint hack

by Sasun Steinbeck

Not having an SLPoint function is a serious roadblock if you want to map a bunch of SLURLs. For my needs I simply wanted to plot markers based on a database of art gallery SLURLs. I implemented my own SLPoint and it works great. Here's what I did:

Since I'm programming in asp.net, it was easiest for me to load a hidden gridview control with my data, which can easily be accessed by javascript as a normal table element after the grid is bound, but you can change the code below to get data from other sources as needed. In my case, the SLURL is not really a slurl but just a string in the format region/x/y/z and is the first column of my table. You can modify the code below to account for different format location parameters.

First create your own "mymaps.js" file, which is also where I implemented my loadmap() function and set up my marker flags <lsl>var gallery_flag = new Img("your_graphic.gif", 16, 16, false); var gallery_icon = new Icon(gallery_flag); var all_images = [gallery_icon, gallery_icon, gallery_icon, gallery_icon, gallery_icon, gallery_icon]; var mapInstance; var markerCount; //holds a count of markers loaded for debugging/informational purposes

function loadmap(){ if (mapInstance == null) { mapInstance = new SLMap(document.getElementById('map-element')); } mapInstance.centerAndZoomAtSLCoord(new XYPoint(1000, 1000), 6); var grid = document.getElementById('GridView1'); //get my gridview table markerCount = 0; for (i = 1; i < grid.rows.length; i++) { params = grid.rows[i].cells; //pass in whole row of data. SLURL MUST be first parameter, others are optional. SLPoint(params, SLPointCallback); //calls my custom SLPoint defined below } }

function SLPoint(params, callback) { var s = params[0].innerHTML.split("/"); //first element of params must be this format: region/x/y/z var regionName = s[0]; var localX = s[1]; var localY = s[2]; var varName = "slRegionPos_result"; var scriptURL = "https://cap.secondlife.com/cap/0/d661249b-2b5a-4436-966a-3d3b8d7a574f?var=" + varName + "&sim_name=" + encodeURIComponent(regionName); var onLoadHandler = function () { if (slRegionPos_result.error) { //alert("The region name '" + regionName + "' was not recognised."); } else { callback(params, regionName, slRegionPos_result.x + (localX/slTileSize), slRegionPos_result.y + (localY/slTileSize)); } }; slAddDynamicScript(scriptURL, onLoadHandler); }</lsl>

There's some interesting javascript magic going on above. Basically what is going on is that I'm calling that cap.secondlife.com function to convert a region name to coordinates, with the necessary parameters for it, one of which is a callback function, which is added to the parameters via the slAddDynamicScript function. The onLoadHandler function is defined then added with slAddDynamicScript to the scriptURL variable. Note in the onLoadHandler function I'm calling callback() with one of the parameters I passed in to SLPoint. This is a cool way to just pass along other relevant data (for example I pass in the name of the art gallery I'm mapping, as well as the type of gallery and other stuff) to your callback function that you can use when creating your marker. Following the params variable is the region name that I extracted from params (since I've already extracted it) and the results of the cap.secondlife.com call, the x and y coordinates.

Now you must download a local copy of slmapapi.js and comment OUT the dummy SLPoint function implemented there. In your main html file where you will display your map, change your code to load your LOCAL hacked copy of slmapapi.js, not from the slurl.com website. After that, specify your mymaps.js file. Like this: <script src="slmapapi.js" type="text/javascript"></script> <script src="MyMaps.js" type="text/javascript"></script>

Now you need to implement the callback specified in mymaps.js in your main html file. Be sure to define you own teleport_now_graphic.gif.

<lsl>function SLPointCallback(params, region, x, y) { XYreturn = new XYPoint(x, y); var marker = new Marker(all_images, XYreturn, { centerOnClick: true }); //make sure the SLURLs are endcoded correctly!

var mapWindow = new MapWindow("

<a href='secondlife://" + params[0].innerHTML "'><img src='images/teleport_now_graphic.gif' align='right'></a>
Region: " + region + "

", { closeOnMove: true });

mapInstance.addMarker(marker, mapWindow); ++markerCount; }</lsl>

following this is the body of your html file containing the map elements as per the usual way. Make sure to include the onload event for your body to run the loadmap() function in your mymaps.js file. I hope this helps!!

Click here to see the resulting map of art galleries in SL!