User:SignpostMarv Martin/sandbox/mapapi

From Second Life Wiki
Jump to navigation Jump to search

Adding a group of lines to the map

This example is used with the slrr.js file, and although the function names suggest otherwise, this code is not limited to indicating rail lines

<javascript>mapapi['callbacks']['addGridCallback']('com.secondlife.agni', function(gridConfig){ // grid configs are addressed by namespaces (org.osgrid for OSGrid, com.blizzard.wow for World of Warcraft etc.) var options = function(weight){ return {'strokeWeight':weight,'strokeColor':'#ffffff','clickable':false} // generally you'll not want the line to be clickable, to let people teleport to a point along a line. }, addRailNetwork = function(name, alt, things){ gridConfig['addMultiObjOverlay'](new mapapi['MultiObjOverlay']({ // multi-object overlays are shortcut objects in mapapi.js, intended for batch-handling of multiple overlay objects. 'name' : name, 'alt'  : alt, 'things' : things })); }, ZoomWidthPolyline = mapapi['factory']['ZoomWidthPolyline']; // this factory method from mapapi.js is assigned to a var to assist in readability & minification. addRailNetwork('Rail::Hobo', 'Hobo Railway', [ // the sl-viewer-1 UI plugin will create a menu item named "Rail" with a sub-item named "Hobo" and a description of "Hobo Railway" ZoomWidthPolyline([ [1005.144714, 1014.679810], [1005.481262, 1014.678711], [1005.522461, 1014.678955], [1005.571716, 1014.691895], [1005.594543, 1014.702393], [1005.617188, 1014.715820] ], options(3) ), ZoomWidthPolyline([ [1005.444824, 1013.211609], [1005.445679, 1014.442261], [1005.447571, 1014.465454], [1005.451843, 1014.488403], [1005.457092, 1014.509399], [1005.465393, 1014.531311], [1005.474792, 1014.552124], [1005.486267, 1014.572388], [1005.498352, 1014.589661], [1005.517883, 1014.612671], [1005.682861, 1014.778259], [1005.708008, 1014.802673], [1005.720276, 1014.815491], [1005.758667, 1014.860474] ], options(3) ) ]); }); </javascript>

Adding landmarks

This example is from welcome-areas.js and is intended for use with toggling the display of a group of related landmarks via a UI plugin. <javascript>(function(){

   var cb1 = function(plugin){
       if(plugin['functions'] && plugin['functions']['addMenuToLogWidget']){
           var markerImage = new window['google']['maps']['MarkerImage'](
               'http://static.marvulous.co.uk/img/mapapi/marker-sm.png', // URL to your landmark image.
               new window['google']['maps']['Size'](53, 48), // width and height of your landmark icon
               new window['google']['maps']['Point'](0, 0),  // unless you're using sprite sheets, leave this as-is.
               new window['google']['maps']['Point'](26, 48) // the x & y pixels in the icon to use as the anchor. In this case, it is the bottom middle of the icon.
           );
           plugin['functions']['addMenuToLogWidget']('Places', 'Welcome Areas',[ // this will add a menu named "Welcome Areas" to the "Places" log widget. In the sl-viewer-1 UI plugin, this is the Places tab in the sidebar.
               {
                   'name'        : 'Ahern', // Although it's not likely to happen for mainland regions, private islands may be moved around the grid, making their global co-ordinates change;
                   'x'           : 28, // Since mapapi.js will fetch the global position of the named region, then add the landmark at the specified co-ordinates.
                   'y'           : 28,
                   'z'           : 40,
                   'text'        : 'Ahern Welcome Area',
                   'description' : 'The first welcome area in Second Life.', // html in descriptions are not supported. line endings however, will be converted to 
tags in order to preserve structure. 'icon'  : markerImage // since all of these landmarks will use the same icon, a variable is referenced instead of instantiating google.maps.MarkerImage here. }, { 'name'  : 'Plum', 'x'  : 73, 'y'  : 250, 'z'  : 47, 'text'  : 'Plum Welcome Area', 'description' : 'Currently restful, but a fond living memory of what the classic Welcome Area looked like back in the day.', 'image'  : { // this landmark should have an image displayed on the map UI when clicked. 'src'  : 'http://secondlife.com/app/image/fbe02542-1aac-cf02-9356-6cd52b7301b1/1' // the src attribute of the image. URLs may be whitelisted by the UI plugin at some point. }, 'icon'  : markerImage }, { 'name'  : 'Violet', 'x'  : 164, 'y'  : 102, 'z'  : 26, 'text'  : 'Violet Welcome Area and Infohub', 'description' : 'A beautiful Japanese garden, a place to start your Second Life, find info, and meet other residents.', 'image'  : { 'src' : 'http://secondlife.com/app/image/25d90335-eadf-20dd-1268-ae45948dbeef/1' }, 'icon'  : markerImage }, { 'name'  : 'Waterhead', 'x'  : 36, 'y'  : 76, 'z'  : 25, 'text'  : 'Waterhead Welcome Area', 'description' : 'Tranquil beauty in the heart of arboreal lushness. Wander around the woods or relax by the water\'s edge.', 'image'  : { 'src' : 'http://secondlife.com/app/image/c72a3c22-48fe-2f7a-66ae-52a79f257c3f/1' }, 'icon'  : markerImage } ]); } return true; }, cb2 = function(){ mapapi['callbacks']['addCallback']('plugin loaded', cb1); // if you're wondering what the nonsense is with cb1 and cb2, it's a workaround for load ordering issues. } mapapi['callbacks']['addGridCallback']('com.secondlife.agni', cb2);

})();</javascript>