[mapguide-commits] r5857 - in trunk/Tools/Maestro:
OSGeo.MapGuide.MaestroAPI/Mapping SDK/SamplesWeb/SamplesWeb
SDK/SamplesWeb/SamplesWeb/Tasks
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed May 25 08:04:40 EDT 2011
Author: jng
Date: 2011-05-25 05:04:40 -0700 (Wed, 25 May 2011)
New Revision: 5857
Added:
trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx
trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx.cs
trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx.designer.cs
trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx
trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx.cs
trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx.designer.cs
Modified:
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/MapSelection.cs
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
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/Tasks/ListSelection.aspx.cs
Log:
#1676: Expand the list selection sample by showing a link beside each id value to show the full set of attributes for that feature. Also add a sample to set the selection for a feature. Also fix some assorted bugs found in the selection API as these samples were written.
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/MapSelection.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/MapSelection.cs 2011-05-25 06:08:33 UTC (rev 5856)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/MapSelection.cs 2011-05-25 12:04:40 UTC (rev 5857)
@@ -3,6 +3,7 @@
using System.Text;
using OSGeo.MapGuide.MaestroAPI.Serialization;
using System.Xml;
+using OSGeo.MapGuide.MaestroAPI.Feature;
namespace OSGeo.MapGuide.MaestroAPI.Mapping
{
@@ -121,6 +122,52 @@
}
/// <summary>
+ /// Adds records from the specified reader into this selection
+ /// </summary>
+ /// <param name="reader">The reader</param>
+ /// <param name="limit">The maximum number of records to add. Specify -1 for all</param>
+ /// <returns>Number of records added</returns>
+ public int AddFeatures(IReader reader, int limit)
+ {
+ int added = 0;
+ if (limit < 0)
+ {
+ while (reader.ReadNext())
+ {
+ AddFeature(reader);
+ added++;
+ }
+ }
+ else
+ {
+ while (reader.ReadNext() && added < limit)
+ {
+ AddFeature(reader);
+ added++;
+ }
+ }
+ reader.Close();
+ return added;
+ }
+
+ /// <summary>
+ /// Adds the specified record to the selection
+ /// </summary>
+ /// <param name="record"></param>
+ public void AddFeature(IRecord record)
+ {
+ var idProps = m_layer.IdentityProperties;
+ object[] values = new object[idProps.Length];
+ for (int i = 0; i < idProps.Length; i++)
+ {
+ var prop = idProps[i];
+ //Don't null check because identity property values cannot be null
+ values[i] = record[prop.Name];
+ }
+ Add(values);
+ }
+
+ /// <summary>
/// Encodes the given combined keyset into an ID string for use in the Xml
/// </summary>
/// <param name="values">The combined key</param>
@@ -171,45 +218,7 @@
/// <returns>The composite value key</returns>
public object[] ParseIDString(string id)
{
- int index = 0;
- byte[] data = Convert.FromBase64String(id);
- object[] tmp = new object[m_layer.IdentityProperties.Length];
- for (int i = 0; i < m_layer.IdentityProperties.Length; i++)
- {
- Type type = m_layer.IdentityProperties[i].Type;
-
- if (type == typeof(short))
- {
- tmp[i] = BitConverter.ToInt16(data, index);
- index += MgBinarySerializer.UInt16Len;
- }
- else if (type == typeof(int))
- {
- tmp[i] = BitConverter.ToInt32(data, index);
- index += MgBinarySerializer.UInt32Len;
- }
- else if (type == typeof(long))
- {
- tmp[i] = BitConverter.ToInt64(data, index);
- index += MgBinarySerializer.UInt64Len;
- }
- else if (type == typeof(string))
- {
- int pos = index;
- while (pos < data.Length && data[pos] != 0)
- pos++;
-
- if (pos >= data.Length)
- throw new Exception("Bad null encoded string");
-
- tmp[i] = System.Text.Encoding.UTF8.GetString(data, index, pos - index);
- index = pos + 1;
- }
- else
- throw new Exception(string.Format("The type {0} is not supported for primary keys", type.ToString()));
- }
-
- return tmp;
+ return m_layer.ParseSelectionValues(id);
}
/// <summary>
@@ -537,7 +546,7 @@
if (_layers[i].Layer.ObjectId == layer.ObjectId)
return i;
- return 1;
+ return -1;
}
/// <summary>
@@ -589,7 +598,7 @@
}
/// <summary>
- /// Gets or sets the selection layer at a given index
+ /// Gets the selection layer at a given index
/// </summary>
/// <param name="index">The index to get or set the item for</param>
/// <returns>The item at the given index</returns>
@@ -599,12 +608,6 @@
{
return _layers[IndexOf(index)];
}
- set
- {
- if (value == null)
- throw new ArgumentNullException();
- _layers[IndexOf(index)] = value;
- }
}
#endregion
@@ -630,7 +633,10 @@
public void Add(RuntimeMapLayer layer)
{
if (!Contains(layer))
- Add(new LayerSelection(layer));
+ {
+ var sel = new LayerSelection(layer);
+ Add(sel);
+ }
}
/// <summary>
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs 2011-05-25 06:08:33 UTC (rev 5856)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs 2011-05-25 12:04:40 UTC (rev 5857)
@@ -524,6 +524,49 @@
}
}
+ public object[] ParseSelectionValues(string encodedId)
+ {
+ int index = 0;
+ byte[] data = Convert.FromBase64String(encodedId);
+ object[] tmp = new object[this.IdentityProperties.Length];
+ for (int i = 0; i < this.IdentityProperties.Length; i++)
+ {
+ Type type = this.IdentityProperties[i].Type;
+
+ if (type == typeof(short))
+ {
+ tmp[i] = BitConverter.ToInt16(data, index);
+ index += MgBinarySerializer.UInt16Len;
+ }
+ else if (type == typeof(int))
+ {
+ tmp[i] = BitConverter.ToInt32(data, index);
+ index += MgBinarySerializer.UInt32Len;
+ }
+ else if (type == typeof(long))
+ {
+ tmp[i] = BitConverter.ToInt64(data, index);
+ index += MgBinarySerializer.UInt64Len;
+ }
+ else if (type == typeof(string))
+ {
+ int pos = index;
+ while (pos < data.Length && data[pos] != 0)
+ pos++;
+
+ if (pos >= data.Length)
+ throw new Exception("Bad null encoded string");
+
+ tmp[i] = System.Text.Encoding.UTF8.GetString(data, index, pos - index);
+ index = pos + 1;
+ }
+ else
+ throw new Exception(string.Format("The type {0} is not supported for primary keys", type.ToString()));
+ }
+
+ return tmp;
+ }
+
/// <summary>
/// Initializes this instance with the specified binary stream
/// </summary>
Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Default.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Default.aspx.cs 2011-05-25 06:08:33 UTC (rev 5856)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Default.aspx.cs 2011-05-25 12:04:40 UTC (rev 5857)
@@ -51,11 +51,29 @@
//Here's an example of pre-processing the WebLayout before loading it
//in the AJAX viewer.
+ //This technique can also be used to do things like:
+ //
+ // 1. Overriding the initial view
+
+
//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
//resource versions have been registered on startup (see Global.asax.cs)
IWebLayout wl = ObjectFactory.CreateWebLayout(conn, mdfId);
+
+ //What is IWebLayout2? It is an extension of IWebLayout that supports the ping server property.
+ //This is the interface equivalent of WebLayout 1.1.0 schema. Most schema revisions in MapGuide
+ //are additive and incremental, and our Object Model interfaces follow the same pattern. All new
+ //interfaces inherit from their ancestor interface
+ //
+ //Anyway, what we want to do is if we created a 1.1.0 WebLayout, is to switch on the ping server
+ //property, thus preventing session expiry
+ IWebLayout2 wl2 = wl as IWebLayout2;
+ if (wl2 != null)
+ wl2.EnablePingServer = true;
+
+ wl.Title = "Maestro API Web Samples";
wl.TaskPane.InitialTask = "../SamplesWeb/Tasks/Home.aspx";
string resId = "Session:" + conn.SessionID + "//Sheboygan.WebLayout";
Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/SamplesWeb.csproj
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/SamplesWeb.csproj 2011-05-25 06:08:33 UTC (rev 5856)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/SamplesWeb.csproj 2011-05-25 12:04:40 UTC (rev 5857)
@@ -85,7 +85,9 @@
<Content Include="Global.asax" />
<Content Include="readme.txt" />
<Content Include="Tasks\AddTracksLayer.aspx" />
+ <Content Include="Tasks\FeatureInfo.aspx" />
<Content Include="Tasks\ListSelection.aspx" />
+ <Content Include="Tasks\SetSelectedFeatures.aspx" />
<Content Include="Tasks\ToggleGroupVisibility.aspx" />
<Content Include="Tasks\ToggleLayerVisibility.aspx" />
<Content Include="Tasks\ToggleParcelsLayer.aspx" />
@@ -111,6 +113,13 @@
<Compile Include="Tasks\AddTracksLayer.aspx.designer.cs">
<DependentUpon>AddTracksLayer.aspx</DependentUpon>
</Compile>
+ <Compile Include="Tasks\FeatureInfo.aspx.cs">
+ <DependentUpon>FeatureInfo.aspx</DependentUpon>
+ <SubType>ASPXCodeBehind</SubType>
+ </Compile>
+ <Compile Include="Tasks\FeatureInfo.aspx.designer.cs">
+ <DependentUpon>FeatureInfo.aspx</DependentUpon>
+ </Compile>
<Compile Include="Tasks\ListSelection.aspx.cs">
<DependentUpon>ListSelection.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
@@ -118,6 +127,13 @@
<Compile Include="Tasks\ListSelection.aspx.designer.cs">
<DependentUpon>ListSelection.aspx</DependentUpon>
</Compile>
+ <Compile Include="Tasks\SetSelectedFeatures.aspx.cs">
+ <DependentUpon>SetSelectedFeatures.aspx</DependentUpon>
+ <SubType>ASPXCodeBehind</SubType>
+ </Compile>
+ <Compile Include="Tasks\SetSelectedFeatures.aspx.designer.cs">
+ <DependentUpon>SetSelectedFeatures.aspx</DependentUpon>
+ </Compile>
<Compile Include="Tasks\ToggleGroupVisibility.aspx.cs">
<DependentUpon>ToggleGroupVisibility.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx 2011-05-25 12:04:40 UTC (rev 5857)
@@ -0,0 +1,23 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FeatureInfo.aspx.cs" Inherits="SamplesWeb.Tasks.FeatureInfo" %>
+
+<!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>
+ <h3>Feature Info</h3>
+ <hr />
+ <asp:Label ID="lblMessage" runat="server"></asp:Label>
+ <br />
+ <a href="Home.aspx">Go back</a>
+ <br />
+ <div id="content" runat="server">
+ </div>
+ </div>
+ </form>
+</body>
+</html>
Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx.cs (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx.cs 2011-05-25 12:04:40 UTC (rev 5857)
@@ -0,0 +1,118 @@
+#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;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using OSGeo.MapGuide.MaestroAPI.Mapping;
+using OSGeo.MapGuide.MaestroAPI.Feature;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SamplesWeb.Tasks
+{
+ public partial class FeatureInfo : System.Web.UI.Page
+ {
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ string agent = ConfigurationManager.AppSettings["MapAgentUrl"];
+ string mapName = Request.Params["MAPNAME"];
+ string layerId = Request.Params["LAYERID"];
+ string id = HttpUtility.UrlDecode(Request.Params["ID"]);
+
+ 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 + "//" + mapName + ".Map";
+
+ RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);
+ RuntimeMapLayer layer = rtMap.GetLayerByObjectId(layerId);
+
+ //The values returned are in the same order as the array from the IdentityProperties
+ object[] values = layer.ParseSelectionValues(id);
+ PropertyInfo[] idProps = layer.IdentityProperties;
+
+ //Having decoded the identity property values and knowing what names they are from the
+ //RuntimeMapLayer, construct the selection filter based on these values.
+ //
+ //This sample assumes the Sheboygan dataset and so all identity property values are
+ //known to be only numeric or strings. If this is not the case for you, use the Type
+ //property in PropertyInfo to determine how to construct the filter
+ string[] conditions = new string[idProps.Length];
+ for (int i = 0; i < idProps.Length; i++)
+ {
+ conditions[i] = idProps[i].Name + " = " + values[i].ToString();
+ }
+ //OR all the conditions together to form our final filter
+ string selFilter = string.Join(" OR ", conditions);
+
+ //Execute the query
+ IFeatureReader reader = conn.FeatureService.QueryFeatureSource(
+ layer.FeatureSourceID,
+ layer.QualifiedClassName,
+ selFilter);
+
+ //Use a StringBuilder because we are doing a lot of concatentation here
+ StringBuilder sb = new StringBuilder();
+
+ //Collect the field names
+ string[] fieldNames = new string[reader.FieldCount];
+ for (int i = 0; i < reader.FieldCount; i++)
+ {
+ fieldNames[i] = reader.GetName(i);
+ }
+
+ int count = 0;
+
+ //Write out the attribute table
+ while (reader.ReadNext())
+ {
+ sb.Append("<table border='1'>");
+ for (int i = 0; i < fieldNames.Length; i++)
+ {
+ //Just like the MgFeatureReader, you must test for null before
+ //attempting extraction of values, but unlike MgFeatureReader this
+ //offers an indexer property that returns System.Object which allows
+ //a nice and easy way to string coerce all property values.
+ sb.Append("<tr>");
+ sb.Append("<td><strong>" + fieldNames[i] + "</strong></td>");
+ sb.Append("<td>" + (reader.IsNull(i) ? "(null)" : reader[i]) + "</td>");
+ sb.Append("</tr>");
+ }
+ sb.Append("</table>");
+ count++;
+ }
+ content.InnerHtml = sb.ToString();
+ lblMessage.Text = "Showing attributes of " + count + " features";
+ reader.Close();
+ }
+ }
+}
Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx.designer.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx.designer.cs (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/FeatureInfo.aspx.designer.cs 2011-05-25 12:04:40 UTC (rev 5857)
@@ -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 FeatureInfo {
+
+ /// <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>
+ /// content 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 content;
+ }
+}
Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/Home.aspx
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/Home.aspx 2011-05-25 06:08:33 UTC (rev 5856)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/Home.aspx 2011-05-25 12:04:40 UTC (rev 5857)
@@ -35,16 +35,20 @@
</script>
</head>
<body>
- <form
- <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>
+ <h3>Samples</h3>
+ <hr />
+ <p>At any time, click the <strong>home button</strong> in the task bar or the <strong>Go back</strong> link to return to this list of samples.</p>
+ <p>Map/Layer Manipulation:</p>
<ul>
<li><a href="#" onclick="Go('../SamplesWeb/Tasks/ToggleParcelsLayer.aspx')">Add/Remove Parcels Layer</a></li>
<li><a href="#" onclick="Go('../SamplesWeb/Tasks/AddTracksLayer.aspx')">Add Tracks Layer</a></li>
- <li><a href="#" onclick="Go('../SamplesWeb/Tasks/ListSelection.aspx')">List Selected Features</a></li>
<li><a href="#" onclick="Go('../SamplesWeb/Tasks/ToggleGroupVisibility.aspx','GROUPNAME','Base Map')">Toggle "Base Map" Group</a></li>
<li><a href="#" onclick="Go('../SamplesWeb/Tasks/ToggleLayerVisibility.aspx','LAYERNAME','Parcels')">Toggle "Parcels" Layer</a></li>
</ul>
+ <p>Feature Selection:</p>
+ <ul>
+ <li><a href="#" onclick="Go('../SamplesWeb/Tasks/ListSelection.aspx')">List Selected Features</a></li>
+ <li><a href="#" onclick="Go('../SamplesWeb/Tasks/SetSelectedFeatures.aspx')">Set Selected Features</a></li>
+ </ul>
</body>
</html>
Modified: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ListSelection.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ListSelection.aspx.cs 2011-05-25 06:08:33 UTC (rev 5856)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/ListSelection.aspx.cs 2011-05-25 12:04:40 UTC (rev 5857)
@@ -63,7 +63,7 @@
for (int i = 0; i < selection.Count; i++)
{
MapSelection.LayerSelection layerSel = selection[i];
- sb.Append("<p>Layer: " + layerSel.Layer.Name + "(" + layerSel.Count + ")");
+ sb.Append("<p>Layer: " + layerSel.Layer.Name + " (" + layerSel.Count + " selected item)");
sb.Append("<table>");
for (int j = 0; j < layerSel.Count; j++)
@@ -76,6 +76,11 @@
sb.Append(values[k].ToString());
sb.Append("</td>");
}
+ sb.AppendFormat("<td><a href='FeatureInfo.aspx?MAPNAME={0}&SESSION={1}&LAYERID={2}&ID={3}'>More Info</a></td>",
+ rtMap.Name,
+ conn.SessionID,
+ layerSel.Layer.ObjectId,
+ HttpUtility.UrlEncode(layerSel.EncodeIDString(values)));
sb.Append("</tr>");
}
sb.Append("</table>");
@@ -87,7 +92,7 @@
}
else
{
- lblMessage.Text = "Nothing selected";
+ lblMessage.Text = "Nothing selected. Select some features first then run this sample again.";
}
}
}
Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx 2011-05-25 12:04:40 UTC (rev 5857)
@@ -0,0 +1,30 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SetSelectedFeatures.aspx.cs" Inherits="SamplesWeb.Tasks.SetSelectedFeatures" %>
+
+<!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>
+ <h3>Set Selected Features</h3>
+ <hr />
+ <form id="form1" runat="server">
+ <div>
+ <input id="MAPNAME" runat="server" type="hidden" />
+ <input id="SESSION" runat="server" type="hidden" />
+ <p>Select a map layer and specify a filter (eg. Layer: Parcels, Filter: RNAME LIKE 'SCHMITT%')</p>
+ <p>Features in this layer that match the filter will be selected</p>
+ <p>Layer:</p>
+ <asp:DropDownList ID="ddlLayers" runat="server" />
+ <p>Filter:</p>
+ <asp:TextBox ID="txtFilter" runat="server" Rows="4" TextMode="MultiLine" />
+ <div></div>
+ <asp:Button ID="btnSelect" runat="server" Text="Select"
+ onclick="btnSelect_Click" />
+ <hr />
+ <asp:Label ID="lblMessage" runat="server" />
+ </div>
+ </form>
+</body>
+</html>
Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx.cs (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx.cs 2011-05-25 12:04:40 UTC (rev 5857)
@@ -0,0 +1,116 @@
+#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;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using OSGeo.MapGuide.MaestroAPI.Mapping;
+using OSGeo.MapGuide.MaestroAPI.Feature;
+
+namespace SamplesWeb.Tasks
+{
+ public partial class SetSelectedFeatures : System.Web.UI.Page
+ {
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ if (!IsPostBack)
+ {
+ string agent = ConfigurationManager.AppSettings["MapAgentUrl"];
+ MAPNAME.Value = Request.Params["MAPNAME"];
+ SESSION.Value = Request.Params["SESSION"];
+
+ IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
+ "Maestro.Http",
+ "Url", agent,
+ "SessionId", SESSION.Value);
+
+ IMappingService mpSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
+ string rtMapId = "Session:" + conn.SessionID + "//" + MAPNAME.Value + ".Map";
+
+ RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);
+ foreach (RuntimeMapLayer rtLayer in rtMap.Layers)
+ {
+ ddlLayers.Items.Add(new ListItem(rtLayer.Name, rtLayer.ObjectId));
+ }
+ }
+ }
+
+ protected void btnSelect_Click(object sender, EventArgs e)
+ {
+ string agent = ConfigurationManager.AppSettings["MapAgentUrl"];
+ MAPNAME.Value = Request.Params["MAPNAME"];
+ SESSION.Value = Request.Params["SESSION"];
+
+ IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
+ "Maestro.Http",
+ "Url", agent,
+ "SessionId", SESSION.Value);
+
+ IMappingService mpSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
+ string rtMapId = "Session:" + conn.SessionID + "//" + MAPNAME.Value + ".Map";
+
+ RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);
+
+ //Get the selected layer
+ RuntimeMapLayer rtLayer = rtMap.GetLayerByObjectId(ddlLayers.SelectedValue);
+
+ //Query using the user filter
+ IFeatureReader reader = conn.FeatureService.QueryFeatureSource(
+ rtLayer.FeatureSourceID,
+ rtLayer.QualifiedClassName,
+ txtFilter.Text);
+
+ //Get the selection set
+ MapSelection sel = new MapSelection(rtMap);
+ MapSelection.LayerSelection layerSel = null;
+ if (!sel.Contains(rtLayer))
+ {
+ sel.Add(rtLayer);
+ }
+ layerSel = sel[rtLayer];
+
+ //Clear any existing selections
+ layerSel.Clear();
+
+ //Populate selection set with query result
+ int added = layerSel.AddFeatures(reader, -1);
+
+ //Generate selection string
+ string selXml = sel.ToXml();
+
+ //Generate a client-side set selection and execute a "Zoom to Selection" afterwards
+ Page.ClientScript.RegisterStartupScript(
+ this.GetType(),
+ "load",
+ "<script type=\"text/javascript\"> window.onload = function() { parent.parent.GetMapFrame().SetSelectionXML('" + selXml + "'); parent.parent.ExecuteMapAction(10); } </script>");
+
+
+ lblMessage.Text = added + " features in " + rtLayer.Name + " selected";
+ }
+ }
+}
Added: trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx.designer.cs
===================================================================
--- trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx.designer.cs (rev 0)
+++ trunk/Tools/Maestro/SDK/SamplesWeb/SamplesWeb/Tasks/SetSelectedFeatures.aspx.designer.cs 2011-05-25 12:04:40 UTC (rev 5857)
@@ -0,0 +1,79 @@
+//------------------------------------------------------------------------------
+// <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 SetSelectedFeatures {
+
+ /// <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>
+ /// MAPNAME 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.HtmlInputHidden MAPNAME;
+
+ /// <summary>
+ /// SESSION 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.HtmlInputHidden SESSION;
+
+ /// <summary>
+ /// ddlLayers 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.DropDownList ddlLayers;
+
+ /// <summary>
+ /// txtFilter 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.TextBox txtFilter;
+
+ /// <summary>
+ /// btnSelect 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.Button btnSelect;
+
+ /// <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;
+ }
+}
More information about the mapguide-commits
mailing list