This is the definitive answer to your question:<br><a href="http://ASP.NET">ASP.NET</a> Qick Example, incomplete: doesn't handle memory - <b>you must dispose all</b>...<br><br><span style="font-family: courier new,monospace;"><%@ Page Language="C#" %><br>
<%@ Import Namespace="OSGeo.MapGuide" %><br><br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"><br>
<br><script runat="server"><br>private string _strSessionId = "";<br> private string _mapName = "";<br> string _csvShowLayers = "";<br> string _csvHideLayers = "";<br>
<br> protected string GetMapName()<br> {<br> return _mapName;<br> }<br> protected string GetMapSession()<br> {<br> return _strSessionId;<br> }<br> protected string GetShowlayers()<br> {<br>
return _csvShowLayers;<br> }<br> protected string GetHidelayers()<br> {<br> return _csvHideLayers;<br> }<br><br> protected void Page_Load(object sender, EventArgs e)<br> {<br><br> MgUserInformation userInfo = null;<br>
MgSiteConnection siteConnection = null;<br> MgSite site = null;<br> MgResourceIdentifier resourceId = null;<br> MgMappingService mappingService = null;<br><br> MgMap map = null;<br> MgResourceService resourceService = null;<br>
MgSelection selection = null;<br><br> MgLayerCollection lColl = null;<br> MgLayerBase layerBase = null;<br> MgResourceIdentifier sessionIdResourceIdentifier = null;<br><br> //TODO: fullfill catch / fullfill finally<br>
//IMPORTANT: dispose all in finally!!!<br> try<br> {<br> userInfo = new MgUserInformation("Anonymous", "");<br> siteConnection = new MgSiteConnection();<br>
siteConnection.Open(userInfo);<br>
<br> site = siteConnection.GetSite();<br> _strSessionId = site.CreateSession();<br><br> //---------------------------------------------------<br> //Save new mapguide session<br>
userInfo.SetMgSessionId(_strSessionId);<br> //---------------------------------------------------<br><br> resourceId = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");<br>
_mapName = resourceId.GetName();<br><br> //------------------------------------------------<br> //Layers objectId<br> mappingService = (MgMappingService)siteConnection.CreateService(MgServiceType.MappingService);<br>
map = new MgMap();<br> resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService;<br> map.Create(resourceService, resourceId, _mapName);<br><br> lColl = map.GetLayers();<br>
int iMax = lColl.Count;<br><br> //Let's show only Districts:<br> int iHid = 0, iShow = 0; ;<br> for (int i = 0; i < iMax; ++i)<br> {<br> if (null != layerBase) layerBase.Dispose();<br>
layerBase = lColl[i];<br> string layername = layerBase.GetName();<br> if (layername == "Districts")<br> {<br> if (iShow > 0) _csvShowLayers += ",";<br>
_csvShowLayers += layerBase.GetObjectId();<br> ++iShow;<br> }<br> else if (layername == "Hydrography")<br> {<br> if (iShow > 0) _csvShowLayers += ",";<br>
_csvShowLayers += layerBase.GetObjectId();<br> ++iShow;<br> }<br> else<br> {<br> //TODO: use StringBuilder<br> if (iHid > 0) _csvHideLayers += ",";<br>
_csvHideLayers += layerBase.GetObjectId();<br> ++iHid;<br> }<br> }<br> //------------------------------------------------<br><br> //------------------------------------------------<br>
//Necessary to show maps:<br> selection = new MgSelection(map);<br> selection.Save(resourceService, _mapName);<br><br> sessionIdResourceIdentifier = new MgResourceIdentifier(<br>
String.Concat("Session:", _strSessionId, "//", _mapName, ".", MgResourceType.Map));<br> map.Save(resourceService, sessionIdResourceIdentifier);<br> //------------------------------------------------<br>
}<br> catch<br> {<br> throw;//TODO: Handle exceptions<br> }<br> finally<br> {<br> //TODO: dispose<br> }<br> }</span><span style="font-family: courier new,monospace;"><br>
</script><br><br><html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>"><br><head runat="server"><br> <title></title><br> <script type="text/javascript" src="<a href="http://www.openlayers.org/api/OpenLayers.js">http://www.openlayers.org/api/OpenLayers.js</a>"></script><br>
<style type="text/css"><br> #map_mg<br> {<br> width: 500px;<br> height:500px;<br> float: left;<br> border:solid 1px #000;<br> }<br> </style><br> <br></head><br>
<body onload="init()"><br> <form id="form1" runat="server"><br> <div><br> <h2>Qick example: TODO: Dispose all map guide objects, use StringBuilder, etc...</h2><br>
<h3>Showing only Districts/Hydrography</h3><br> </div><br> <div id="map_mg"><br> </div><br> </form><br> <br> <script type="text/javascript"><br>
var addrs = "<a href="http://localhost/">http://localhost/</a>";<br> var mg_url = addrs + "mapguide/mapagent/mapagent.fcgi?USERNAME=Anonymous&";<br> var metersPerUnit = 111319.4908; //value returned from mapguide<br>
var inPerUnit = OpenLayers.INCHES_PER_UNIT.m * metersPerUnit;<br> OpenLayers.INCHES_PER_UNIT["dd"] = inPerUnit;<br> OpenLayers.INCHES_PER_UNIT["degrees"] = inPerUnit;<br> OpenLayers.DOTS_PER_INCH = 96;<br>
var _map = null;<br> <br> function init() {<br> var extent = new OpenLayers.Bounds(-87.865114442365922, 43.665065564837931, -87.595394059497067, 43.823852564430069);<br> var mapOptions = {<br>
maxExtent: extent,<br> maxResolution: 'auto'<br> };<br> _map = new OpenLayers.Map('map_mg', mapOptions);<br><br> var options = {<br> isBaseLayer: true,<br>
buffer: 1,<br> useOverlay: false,<br> useAsyncOverlay: false,<br> singleTile: true<br> };<br> var params = {};<br> params.mapName = '<%= GetMapName() %>';<br>
params.session = '<%= GetMapSession() %>';<br> params.hideLayers = '<%= GetHidelayers() %>';<br> params.showLayers = '<%= GetShowlayers() %>';<br>
<br> mg_layer = new OpenLayers.Layer.MapGuide("MapGuide Sheboygan map", mg_url, params, options);<br> _map.addLayer(mg_layer);<br><br> _map.addControl(new OpenLayers.Control.MousePosition());<br>
_map.zoomToMaxExtent();<br><br> }<br> </script><br></body><br></html><br><br><span style="font-family: arial,helvetica,sans-serif;">Pietro Ianniello</span><br></span><br>