📄 selecttooltask.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web.DataSources.Graphics;
using ESRI.ArcGIS.ADF.Web.Display.Graphics;
using ESRI.ArcGIS.ADF.Web.Display.Symbol;
using ESRI.ArcGIS.ADF.Web.Geometry;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
namespace SelectToolTask
{
/// <summary>
/// Allows user to select features on the Map control by drawing a graphic.
/// </summary>
[ToolboxData("<{0}:SelectToolTask runat=\"server\" Width=\"200px\" Transparency=\"35\" BackColor=\"White\" TitleBarColor=\"WhiteSmoke\" TitleBarSeparatorLine=\"False\" TitleBarHeight=\"20px\" BorderColor=\"LightSteelBlue\" BorderStyle=\"Outset\" BorderWidth=\"1px\" Font-Names=\"Verdana\" Font-Size=\"8pt\" ForeColor=\"Black\"> </{0}:SelectToolTask>"),
Designer(typeof(SelectToolTaskDesigner)),
WebConfigurator(typeof(SelectToolTaskWebConfigurator)),
System.Drawing.ToolboxBitmap(typeof(SelectToolTask))]
public class SelectToolTask : FloatingPanelTask
{
#region Private members
Map mapCtrl;
string mapResMgr;
private string idStringDelim = "___";
DropDownList ddlLayerList;
Toolbar selectToolbar;
#endregion
#region Public properties
/// <summary>
/// Selection toleratnce around points, in pixels.
/// </summary>
[Browsable(true),
Category("SelectToolTask"),
DefaultValue(3),
Description("Tolerance around point selection, in pixels. Must be greater than zero to select features in point and line layers."),
PersistenceMode(PersistenceMode.Attribute)]
public int PointSelectionTolerance
{
get
{
object o = StateManager.GetProperty("selectionTolerance");
return (o == null) ? 3 : (int)o;
}
set
{
StateManager.SetProperty("selectionTolerance", value);
}
}
/// <summary>
/// Whether to make previous selections in the TaskResults invisible
/// when the user makes a new selection.
/// </summary>
[Browsable(true),
Category("SelectToolTask"),
DefaultValue(true),
Description("Whether to make previous selections in the TaskResults invisible when the user makes a new selection."),
PersistenceMode(PersistenceMode.Attribute)]
public bool HidePreviousSelections
{
get
{
object o = StateManager.GetProperty("hidePreviousSelections");
return (o == null) ? true : (bool)o;
}
set
{
StateManager.SetProperty("hidePreviousSelections", value);
}
}
/// <summary>
/// Whether to render (highlight) all features upon selection.
/// If true, individual features may be highlighted by clicking
/// feature check-boxes in the Task Results, but the all-feature
/// rendering cannot be turned off without also turning off individual highlights.
/// </summary>
[Browsable(true),
Category("SelectToolTask"),
DefaultValue(true),
Description("Whether to render (highlight) all features upon selection. If true, individual features may be highlighted by clicking feature check-boxes in the Task Results, but the all-feature rendering cannot be turned off without also turning off individual highlights."),
PersistenceMode(PersistenceMode.Attribute)]
public bool RenderSelectedSet
{
get
{
object o = StateManager.GetProperty("renderAllSelectedFeatures");
return (o == null) ? true : (bool)o;
}
set
{
StateManager.SetProperty("renderAllSelectedFeatures", value);
}
}
/// <summary>
/// Color to render all features in the selected set.
/// Used only when RenderAllSelectedFeatures is true.
/// </summary>
[Browsable(true),
Category("SelectToolTask"),
DefaultValue(typeof(System.Drawing.Color), "Yellow"),
Description("Color to render all features in the selected set. Used only when RenderAllSelectedFeatures is true."),
PersistenceMode(PersistenceMode.Attribute)]
public System.Drawing.Color SelectedSetColor
{
get
{
object o = StateManager.GetProperty("selectedSetColor");
return (o == null) ? System.Drawing.Color.Yellow : (System.Drawing.Color)o;
}
set
{
StateManager.SetProperty("selectedSetColor", value);
}
}
/// <summary>
/// Title for the item in Task Results. Layer name and number of features is added.
/// </summary>
[Browsable(true),
Category("SelectToolTask"),
DefaultValue("Selection"),
Description("Title for the item in Task Results. Layer name and number of features is added."),
PersistenceMode(PersistenceMode.Attribute)]
public string ResultsTitle
{
get
{
object o = StateManager.GetProperty("resultsTitle");
return (o == null) ? "Selection" : o as string;
}
set
{
StateManager.SetProperty("resultsTitle", value);
}
}
/// <summary>
/// Layers that the user may choose from for selection.
/// Separate names with double colon (::). If null or
/// empty (the default), any vector layer may be chosen. If only
/// one layer, no layer drop-down choice list is displayed to the user.
/// </summary>
[Browsable(true),
Category("SelectToolTask"),
DefaultValue(""),
Description("Layers that the user may choose from for selection. Separate names with double colon (::). If null or empty (the default), any vector layer may be chosen. If only one layer, no layer drop-down choice list is displayed to the user."),
Editor(typeof(SelectionLayersEditor), typeof(UITypeEditor)),
PersistenceMode(PersistenceMode.Attribute)]
public string SelectionLayerNames
{
get
{
object o = StateManager.GetProperty("selectionLayerNames");
return (o == null) ? String.Empty : (string)o;
}
set
{
string names = (value == null) ? String.Empty : value;
StateManager.SetProperty("selectionLayerNames", names);
}
}
/// <summary>
/// ID of Map control to select from
/// </summary>
[Browsable(true),
Category("SelectToolTask"),
DefaultValue("Map1"),
Description("ID of Map control to use for selection. If blank, first map control found is used."),
Editor(typeof(MapControlEditor), typeof(UITypeEditor)),
PersistenceMode(PersistenceMode.Attribute)]
public string Map
{
get
{
object o = StateManager.GetProperty("map");
return (o == null) ? "Map1" : o as string;
}
set
{
StateManager.SetProperty("map", value);
}
}
/// <summary>
/// Layer to select from.
/// Set dynamically when user picks layer from dropdownlist, or from
/// SelectionLayerIds if only one layer specified.
/// </summary>
[Browsable(false)]
public string SelectLayerId
{
get
{
object o = StateManager.GetProperty("selectLayerId");
return (o == null) ? String.Empty : (string)o;
}
set
{
StateManager.SetProperty("selectLayerId", value);
}
}
/// <summary>
/// Map resource that contains layer with SelectLayerId.
/// </summary>
[Browsable(false)]
public string SelectMapResource
{
get
{
object o = StateManager.GetProperty("selectMapResource");
return (o == null) ? String.Empty : (string)o;
}
set
{
StateManager.SetProperty("selectMapResource", value);
}
}
/// <summary>
/// Geometry for selection created by user with SelectTool
/// </summary>
protected internal ESRI.ArcGIS.ADF.Web.Geometry.Geometry SelectionGeometry
{
get
{
Type geomType = StateManager.GetProperty("geometryType") as Type;
string geomString = StateManager.GetProperty("selectionGeometry") as string;
if (geomType == null || String.IsNullOrEmpty(geomString)) return null;
ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom =
DeserializeGeometry(geomString, geomType);
return geom;
}
set
{
string geomSer = SerializeGeometry(value);
StateManager.SetProperty("geometryType", value.GetType());
StateManager.SetProperty("selectionGeometry", geomSer);
}
}
/// <summary>
/// Used internally to store the current map control height and width
/// </summary>
protected internal int MapWidth
{
get
{
object o = StateManager.GetProperty("mapWidth");
return (o == null) ? 0 : (int)o;
}
set
{
StateManager.SetProperty("mapWidth", value);
}
}
protected internal int MapHeight
{
get
{
object o = StateManager.GetProperty("mapHeight");
return (o == null) ? 0 : (int)o;
}
set
{
StateManager.SetProperty("mapHeight", value);
}
}
#endregion
#region Web control overrides - CreateChildControls, OnPreRender, Rendering
#region CreateChildControls method
protected override void CreateChildControls()
{
// Note that we do most rendering-related chores in
// OnPreRender() and RenderContents(). This is more efficient
// because CreateChildControls runs every callback, whereas
// rendering methods run only on full postback. We only do
// what's needed here to add controls so the callback code
// can work with the controls.
Controls.Clear();
// Add drop-down list of layers available for selection
ddlLayerList = new DropDownList();
ddlLayerList.ID = ClientID + "_ddlLayerList";
Controls.Add(ddlLayerList);
// create toolbar to hold selection button
// (Note that need to readd toolbar each request in order to find
// newly clicked tools)
selectToolbar = new Toolbar();
selectToolbar.ID = ClientID + "_selToolbar";
Controls.Add(selectToolbar);
base.CreateChildControls();
}
#endregion
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -