[mapguide-commits] r5849 - in trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb: . Tasks

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue May 24 13:42:07 EDT 2011


Author: jng
Date: 2011-05-24 10:42:07 -0700 (Tue, 24 May 2011)
New Revision: 5849

Added:
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.cs
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.designer.cs
Modified:
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Default.aspx.cs
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/SamplesWeb.csproj
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/Home.aspx
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Web.config
Log:
#1676: Update the web sample with an example to add a layer to the runtime map


Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Default.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Default.aspx.cs	2011-05-24 16:27:00 UTC (rev 5848)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Default.aspx.cs	2011-05-24 17:42:07 UTC (rev 5849)
@@ -48,6 +48,9 @@
             var mdfId = "Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition";
             if (conn.ResourceService.ResourceExists(mdfId))
             {
+                //Here's an example of pre-processing the WebLayout before loading it
+                //in the AJAX viewer.
+
                 //Create a WebLayout. By default the version created will be 
                 //the latest supported one on the mapguide server we've connected to. For example
                 //connecting to MGOS 2.2 will create a version 1.1.0 WebLayout. All the known

Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/SamplesWeb.csproj
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/SamplesWeb.csproj	2011-05-24 16:27:00 UTC (rev 5848)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/SamplesWeb.csproj	2011-05-24 17:42:07 UTC (rev 5849)
@@ -84,6 +84,7 @@
     <Content Include="Default.aspx" />
     <Content Include="Global.asax" />
     <Content Include="readme.txt" />
+    <Content Include="Tasks\AddTracksLayer.aspx" />
     <Content Include="Tasks\ToggleParcelsLayer.aspx" />
     <Content Include="Tasks\Home.aspx" />
     <Content Include="Web.config" />
@@ -100,6 +101,13 @@
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Tasks\AddTracksLayer.aspx.cs">
+      <DependentUpon>AddTracksLayer.aspx</DependentUpon>
+      <SubType>ASPXCodeBehind</SubType>
+    </Compile>
+    <Compile Include="Tasks\AddTracksLayer.aspx.designer.cs">
+      <DependentUpon>AddTracksLayer.aspx</DependentUpon>
+    </Compile>
     <Compile Include="Tasks\ToggleParcelsLayer.aspx.cs">
       <DependentUpon>ToggleParcelsLayer.aspx</DependentUpon>
       <SubType>ASPXCodeBehind</SubType>
@@ -132,12 +140,11 @@
     <VisualStudio>
       <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
         <WebProjectProperties>
-          <UseIIS>False</UseIIS>
+          <UseIIS>True</UseIIS>
           <AutoAssignPort>True</AutoAssignPort>
           <DevelopmentServerPort>49241</DevelopmentServerPort>
           <DevelopmentServerVPath>/</DevelopmentServerVPath>
-          <IISUrl>
-          </IISUrl>
+          <IISUrl>http://localhost/mapguide/SamplesWeb/</IISUrl>
           <NTLMAuthentication>False</NTLMAuthentication>
           <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
         </WebProjectProperties>

Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx	                        (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx	2011-05-24 17:42:07 UTC (rev 5849)
@@ -0,0 +1,21 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddTracksLayer.aspx.cs" Inherits="SamplesWeb.Tasks.AddTracksLayer" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" >
+<head runat="server">
+    <title>Untitled Page</title>
+</head>
+<body>
+    <form id="form1" runat="server">
+    <div>
+        <asp:Label ID="lblMessage" runat="server"></asp:Label>
+        <br />
+        <a href="javascript:history.go(-1)">Go back</a>
+        <br />
+        <div id="debug" runat="server">
+        </div>
+    </div>
+    </form>
+</body>
+</html>

Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.cs	                        (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.cs	2011-05-24 17:42:07 UTC (rev 5849)
@@ -0,0 +1,170 @@
+#region Disclaimer / License
+// Copyright (C) 2011, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections;
+using System.Configuration;
+using System.Data;
+using System.Web;
+using System.Web.Security;
+using System.Web.UI;
+using System.Web.UI.HtmlControls;
+using System.Web.UI.WebControls;
+using System.Web.UI.WebControls.WebParts;
+using OSGeo.MapGuide.MaestroAPI.Mapping;
+using System.Text;
+using OSGeo.MapGuide.MaestroAPI;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using OSGeo.MapGuide.ObjectModels.LayerDefinition;
+using OSGeo.MapGuide.ObjectModels;
+using System.Drawing;
+
+namespace SamplesWeb.Tasks
+{
+    public partial class AddTracksLayer : System.Web.UI.Page
+    {
+        protected void Page_Load(object sender, EventArgs e)
+        {
+            string agent = ConfigurationManager.AppSettings["MapAgentUrl"];
+
+            IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
+                "Maestro.Http",
+                "Url", agent,
+                "SessionId", Request.Params["SESSION"]);
+
+            IMappingService mpSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
+            string rtMapId = "Session:" + conn.SessionID + "//" + Request.Params["MAPNAME"] + ".Map";
+
+            RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);
+
+            RuntimeMapLayer tracks = rtMap.GetLayerByName("Tracks");
+            if (tracks != null)
+            {
+                lblMessage.Text = "Tracks layer already added";
+            }
+            else
+            {
+                RuntimeMapGroup group = rtMap.GetGroupByName("Transportation");
+                if (group == null)
+                {
+                    group = rtMap.AddGroup("Transportation");
+                    throw new Exception("Layer group not found");
+                }
+
+                //For some reason, the Sheboygan sample data does not have a Rail
+                //Layer Definition, so what better time to show how to create a
+                //layer dynamically :)
+
+                //Our Feature Source
+                string fsId = "Library://Samples/Sheboygan/Data/Rail.FeatureSource";
+
+                //The place we'll store the layer definition
+                string layerId = "Session:" + conn.SessionID + "//Rail.LayerDefinition";
+
+                CreateTracksLayer(conn, fsId, layerId);
+
+                RuntimeMapLayer layer = rtMap.CreateLayer(layerId, group);
+
+                layer.LegendLabel = "Tracks";
+                layer.ShowInLegend = true;
+                layer.ExpandInLegend = true;
+                layer.Selectable = true;
+                layer.Visible = true;
+
+                //Set it to be drawn above districts.
+                //In terms of draw order, it goes [0...n] -> [TopMost ... Bottom]
+                //So for a layer to be drawn above something else, its draw order must be
+                //less than that particular layer.
+
+                int index = rtMap.IndexOfLayer("Districts");
+                rtMap.InsertLayer(index, layer);
+
+                rtMap.Save();
+
+                Page.ClientScript.RegisterStartupScript(
+                    this.GetType(),
+                    "load",
+                    "<script type=\"text/javascript\"> window.onload = function() { parent.parent.Refresh(); } </script>");
+
+                lblMessage.Text = "Parcels layer added again";
+            }
+
+            rtMap = mpSvc.OpenMap(rtMapId);
+            DumpMap(rtMap);
+        }
+
+        private static void CreateTracksLayer(IServerConnection conn, string resId, string layerId)
+        {
+            //We use the ObjectFactory class to create our layer
+            ILayerDefinition ldf = ObjectFactory.CreateDefaultLayer(conn, LayerType.Vector);
+            IVectorLayerDefinition vldf = (IVectorLayerDefinition)ldf.SubLayer;
+
+            //Set feature source
+            vldf.ResourceId = resId;
+
+            //Set the feature class
+            vldf.FeatureName = "SHP_Schema:Rail";
+
+            //Set the designated geometry
+            vldf.Geometry = "SHPGEOM";
+
+            //Get the first vector scale range. This will have been created for us and is 0 to infinity
+            IVectorScaleRange vsr = vldf.GetScaleRangeAt(0);
+
+            //Get the line style
+            ILineVectorStyle lstyle = vsr.LineStyle;
+
+            //Get the first rule (a created one will only have one)
+            ILineRule rule = lstyle.GetRuleAt(0);
+
+            //There's only one stroke here, but iteration is the only
+            //way to go through
+            foreach (var stroke in rule.Strokes)
+            {
+                //Set color to red
+                stroke.Color = "ffff0000";
+            }
+
+            //Now save it
+            conn.ResourceService.SaveResourceAs(ldf, layerId);
+        }
+
+        //This method dumps the runtime state of the map. I personally
+        //used this method to debug this sample as I was developing it.
+        //
+        //It's been kept here for reference.
+        private void DumpMap(RuntimeMap rtMap)
+        {
+            StringBuilder sb = new StringBuilder();
+            sb.Append("<p>Debugging</p>");
+            sb.Append("Name: " + rtMap.Name + "<br/>");
+            sb.Append("Layers: <br/>");
+            sb.Append("<ul>");
+            foreach (var layer in rtMap.Layers)
+            {
+                sb.Append("<li>Name: " + layer.Name + " (Selectable: " + layer.Selectable + ", Visible: " + layer.Visible + ")<br/>");
+                sb.Append("Group: " + layer.Group + "<br/>");
+                sb.Append("Draw Order: " + layer.DisplayOrder + "</li>");
+            }
+            sb.Append("</ul>");
+
+            debug.InnerHtml = sb.ToString();
+        }
+    }
+}

Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.designer.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.designer.cs	                        (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/AddTracksLayer.aspx.designer.cs	2011-05-24 17:42:07 UTC (rev 5849)
@@ -0,0 +1,43 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:2.0.50727.4952
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace SamplesWeb.Tasks {
+    
+    
+    public partial class AddTracksLayer {
+        
+        /// <summary>
+        /// form1 control.
+        /// </summary>
+        /// <remarks>
+        /// Auto-generated field.
+        /// To modify move field declaration from designer file to code-behind file.
+        /// </remarks>
+        protected global::System.Web.UI.HtmlControls.HtmlForm form1;
+        
+        /// <summary>
+        /// lblMessage control.
+        /// </summary>
+        /// <remarks>
+        /// Auto-generated field.
+        /// To modify move field declaration from designer file to code-behind file.
+        /// </remarks>
+        protected global::System.Web.UI.WebControls.Label lblMessage;
+        
+        /// <summary>
+        /// debug control.
+        /// </summary>
+        /// <remarks>
+        /// Auto-generated field.
+        /// To modify move field declaration from designer file to code-behind file.
+        /// </remarks>
+        protected global::System.Web.UI.HtmlControls.HtmlGenericControl debug;
+    }
+}

Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/Home.aspx
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/Home.aspx	2011-05-24 16:27:00 UTC (rev 5848)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/Home.aspx	2011-05-24 17:42:07 UTC (rev 5849)
@@ -5,13 +5,27 @@
 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
     <title>Home</title>
+    <script type="text/javascript">
+    
+        function Go(url)
+        {
+            var map = parent.parent.GetMapFrame();
+            
+            url += "?SESSION=" + map.GetSessionId();
+            url += "&MAPNAME=" + map.GetMapName();
+            
+            window.location = url;
+        }
+    
+    </script>
 </head>
 <body>
     <p>At any time, click the <strong>home button</strong> in the task bar to return to this list of samples.</p>
     
     <p>Samples</p>
     <ul>
-        <li><a href="ToggleParcelsLayer.aspx?SESSION=<%=Request.Params["SESSION"] %>&MAPNAME=<%=Request.Params["MAPNAME"] %>">Toggle Parcels Layer</a></li>
+        <li><a href="#" onclick="Go('ToggleParcelsLayer.aspx')">Toggle Parcels Layer</a></li>
+        <li><a href="#" onclick="Go('AddTracksLayer.aspx')">Add Tracks Layer</a></li>
     </ul>
 </body>
 </html>

Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Web.config
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Web.config	2011-05-24 16:27:00 UTC (rev 5848)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Web.config	2011-05-24 17:42:07 UTC (rev 5849)
@@ -1,29 +1,25 @@
-<?xml version="1.0"?>
-
+<?xml version="1.0"?>
 <configuration>
-
-    <appSettings>
-        <add key="MapAgentUrl" value="http://localhost/mapguide/mapagent/mapagent.fcgi"/>
-    </appSettings>
-    <connectionStrings/>
-  
-    <system.web>
-        <!-- 
+	<appSettings>
+		<add key="MapAgentUrl" value="http://localhost/mapguide/mapagent/mapagent.fcgi"/>
+	</appSettings>
+	<connectionStrings/>
+	<system.web>
+		<!-- 
             Set compilation debug="true" to insert debugging 
             symbols into the compiled page. Because this 
             affects performance, set this value to true only 
             during development.
         -->
-        <compilation debug="false">
-
-        </compilation>
-        <!--
+		<compilation debug="true">
+		</compilation>
+		<!--
             The <authentication> section enables configuration 
             of the security authentication mode used by 
             ASP.NET to identify an incoming user. 
         -->
-        <authentication mode="Windows" />
-        <!--
+		<authentication mode="Windows"/>
+		<!--
             The <customErrors> section enables configuration 
             of what to do if/when an unhandled error occurs 
             during the execution of a request. Specifically, 
@@ -35,7 +31,5 @@
             <error statusCode="404" redirect="FileNotFound.htm" />
         </customErrors>
         -->
-
-    </system.web>
-
+	</system.web>
 </configuration>



More information about the mapguide-commits mailing list