User:Kerik Rau

From Second Life Wiki
Revision as of 19:50, 31 December 2007 by Kerik Rau (Talk | contribs)

Jump to: navigation, search

SLURL Raster Image Generator

//SLURL Tile URL Generator - By Kerik Rau

//Based on the javascript from SLURL.com, mearly an adaptation in LSL
//It should only take a minute or 2 to export this into PHP or other languages

//SLURL uses WMS, I still want to look at incorperating it into something like Mapguide
//I will need to look at the implementation to see if this would be easy or a pain

vector genTileVec(vector RegPos)
{
    //tiles are in a grid based on the regions, so 256m = 1 tile
    RegPos /= 256.0;
    
    //offset provided in the javascript, really 1278 + 1 (probably 0 -> 1 index difference?)
    RegPos.y = 1279.0 - RegPos.y;

    return RegPos;
}

string genMapURL()
{   
    vector TilePos = genTileVec(llGetRegionCorner());
    
    //should look like http://secondlife.com/apps/mapapi/grid/map_image/x-y-zoom-0
    string mapURL = "http://secondlife.com/apps/mapapi/grid/map_image/";
    mapURL += (string) llFloor(TilePos.x);
    mapURL += "-";
    mapURL += (string) llFloor(TilePos.y);
    
    //the 3rd value is something to do with zoom, but only 1 seems to work with this
    //the 4th value is undefined, omitting it works but I leave it in to match SLURL
    mapURL += "-1-0";
    return mapURL;
}


default
{
    state_entry()
    {
        llSetText("SLURL Raster Image URL Generator\nOpens the image of the current sim\n(in a browser)", <1,1,1>, 1);
    }
    
    touch_start(integer numdet)
    {
        integer i;
        for(i = 0; i < numdet; ++i)
            llLoadURL(llDetectedKey(i), "load this page to see the sim image", genMapURL());
        
    }
}