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