[mapguide-commits] r6270 - trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Dec 1 09:16:38 EST 2011


Author: jng
Date: 2011-12-01 06:16:38 -0800 (Thu, 01 Dec 2011)
New Revision: 6270

Added:
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.cs
   trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.designer.cs
Log:
Oops. Left out the actual updated SDK sample

Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx	                        (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx	2011-12-01 14:16:38 UTC (rev 6270)
@@ -0,0 +1,21 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ModifyParcelsFilter.aspx.cs" Inherits="SamplesWeb.Tasks.ModifyParcelsFilter" %>
+<!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 id="Head1" runat="server">
+    <title>Untitled Page</title>
+</head>
+<body>
+    <form id="form1" runat="server">
+    <div>
+        <asp:Label ID="lblMessage" runat="server"></asp:Label>
+        <br />
+        <a id="resetLink" runat="server">Reset</a>
+        <a href="Home.aspx">Go back</a>
+        <br />
+        <div id="debug" runat="server">
+        </div>
+    </div>
+    </form>
+</body>
+</html>

Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.cs	                        (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.cs	2011-12-01 14:16:38 UTC (rev 6270)
@@ -0,0 +1,117 @@
+#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.Generic;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+using System.Configuration;
+using OSGeo.MapGuide.MaestroAPI;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using OSGeo.MapGuide.MaestroAPI.Mapping;
+using OSGeo.MapGuide.ObjectModels.LayerDefinition;
+
+namespace SamplesWeb.Tasks
+{
+    public partial class ModifyParcelsFilter : System.Web.UI.Page
+    {
+        protected void Page_Load(object sender, EventArgs e)
+        {
+            if (!IsPostBack)
+            {
+                string agent = ConfigurationManager.AppSettings["MapAgentUrl"];
+                string mapName = Request.Params["MAPNAME"];
+                string session = Request.Params["SESSION"];
+
+                IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
+                    "Maestro.Http",
+                    "Url", agent,
+                    "SessionId", session);
+
+                IMappingService mpSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
+                string rtMapId = "Session:" + conn.SessionID + "//" + mapName + ".Map";
+
+                RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);
+                int layerIndex = rtMap.Layers.IndexOf("Parcels");
+                RuntimeMapLayer layer = rtMap.Layers[layerIndex];
+
+                //Here is now the layer replacement technique works:
+                //
+                //We take the Layer Definition content referenced by the old layer
+                //Modify the filter in this content and save it to a new resource id
+                //We then create a replacement layer that points to this new resource id
+                //and set the public properties to be identical of the old layer.
+                //
+                //Finally we then remove the old layer and put the replacement layer in its
+                //place, before saving the runtime map.
+
+                ILayerDefinition ldf = (ILayerDefinition)conn.ResourceService.GetResource(layer.LayerDefinitionID);
+                IVectorLayerDefinition vl = (IVectorLayerDefinition)ldf.SubLayer;
+
+                //Sets the layer filter
+                vl.Filter = "RNAME LIKE 'SCHMITT%'";
+                if (Request.Params["RESET"] == "1")
+                {
+                    vl.Filter = "";
+                }
+                
+                //Save this modified layer under a different resource id
+                string ldfId = "Session:" + conn.SessionID + "//ParcelsFiltered.LayerDefinition";
+                conn.ResourceService.SaveResourceAs(ldf, ldfId);
+                //Note that SaveResourceAs does not modify the ResourceID of the resource we want to save
+                //so we need to update it here
+                ldf.ResourceID = ldfId;
+
+                //Create our replacement layer and apply the same properties from the old one
+                RuntimeMapLayer replace = new RuntimeMapLayer(rtMap, ldf);
+                replace.ExpandInLegend = layer.ExpandInLegend;
+                replace.Group = layer.Group;
+                replace.Name = layer.Name;
+                replace.Selectable = layer.Selectable;
+                replace.ShowInLegend = layer.ShowInLegend;
+                replace.Visible = layer.Visible;
+
+                //Remove the old layer and put the new layer at the same position (thus having the
+                //same draw order)
+                rtMap.Layers.RemoveAt(layerIndex);
+                rtMap.Layers.Insert(layerIndex, replace);
+                replace.ForceRefresh();
+
+                rtMap.Save();
+
+                if (Request.Params["RESET"] == "1")
+                {
+                    lblMessage.Text = "Layer filter has been reset";
+                    resetLink.Visible = false;
+                }
+                else
+                {
+                    lblMessage.Text = "Layer filter has been set (to RNAME LIKE 'SCHMITT%')";
+                    resetLink.Attributes["href"] = "ModifyParcelsFilter.aspx?MAPNAME=" + mapName + "&SESSION=" + session + "&RESET=1";
+                }
+
+                Page.ClientScript.RegisterStartupScript(
+                    this.GetType(),
+                    "load",
+                    "<script type=\"text/javascript\"> window.onload = function() { parent.parent.Refresh(); } </script>");
+            }
+        }
+    }
+}

Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.designer.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.designer.cs	                        (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ModifyParcelsFilter.aspx.designer.cs	2011-12-01 14:16:38 UTC (rev 6270)
@@ -0,0 +1,61 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:2.0.50727.5448
+//
+//     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 ModifyParcelsFilter {
+        
+        /// <summary>
+        /// Head1 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.HtmlHead Head1;
+        
+        /// <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>
+        /// resetLink 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.HtmlAnchor resetLink;
+        
+        /// <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;
+    }
+}



More information about the mapguide-commits mailing list