📄 selecttooltaskwebconfigurator.cs
字号:
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Design;
using ESRI.ArcGIS.ADF.Web.DataSources.Graphics;
namespace SelectToolTask
{
/// <summary>
/// Provides a configurator for Manager for the task
/// </summary>
class SelectToolTaskWebConfigurator:
ESRI.ArcGIS.ADF.Web.UI.WebControls.CompositeControl,
IWebConfigurator, IBuddyControlSupport
{
#region Private fields for controls
TextBox dialogTitle;
RadioButton rbnAllowAllLayers;
RadioButton rbnSpecifyAvailableLayers;
ListBox lstAvailableLayers;
TextBox txtSelectionTolerance;
LiteralControl litInvalidResources;
CheckBox ckbRenderSelectionSet;
ColorPicker cpSelectionSetColor;
ColorPicker cpHighlightColor;
CheckBox ckbHidePreviousSelections;
private string idStringDelim = "___";
#endregion
#region Web control
protected override void CreateChildControls()
{
#region Setup and dialog title
Controls.Clear();
Table ctlTable = new Table();
Controls.Add(ctlTable);
TableCell tCell;
// Title row
tCell = CreateCellRow(ctlTable, 0);
tCell.Text = "<strong>Select Tool Task</strong><br/>";
tCell = CreateCellRow(ctlTable, 30);
tCell.Text = "Allows users to select features by clicking on the map<br/>";
tCell = CreateCellRow(ctlTable, 0);
tCell.Controls.Add(new LiteralControl("Title for dialog in browser: "));
dialogTitle = new TextBox();
dialogTitle.ID = "dialogTitle";
tCell.Controls.Add(dialogTitle);
#endregion
#region Selection layers available to user
tCell = CreateCellRow(ctlTable, 0);
rbnAllowAllLayers = new RadioButton();
rbnAllowAllLayers.ID = "rbnAllowAllLayers";
rbnAllowAllLayers.GroupName = "AllowLayers";
rbnAllowAllLayers.Text = "Allow user to select from any queryable layer";
rbnAllowAllLayers.Checked = true;
tCell.Controls.Add(rbnAllowAllLayers);
tCell = CreateCellRow(ctlTable, 0);
rbnSpecifyAvailableLayers = new RadioButton();
rbnSpecifyAvailableLayers.ID = "rbnSpecifyAvailableLayers";
rbnSpecifyAvailableLayers.GroupName = rbnAllowAllLayers.GroupName;
rbnSpecifyAvailableLayers.Text = "Specify selectable layers";
rbnSpecifyAvailableLayers.Checked = false;
tCell.Controls.Add(rbnSpecifyAvailableLayers);
tCell = CreateCellRow(ctlTable, 150); // TODO: reduce width
lstAvailableLayers = new ListBox();
lstAvailableLayers.ID = "lstAvailableLayers";
lstAvailableLayers.ToolTip = "Choose layers that the user may select from. Use Ctrl/Shift to select multiple layers.";
tCell.Controls.Add(lstAvailableLayers);
litInvalidResources = new LiteralControl();
litInvalidResources.ID = "lblInvalidResources";
litInvalidResources.Text = "<br/><span style=\"color:red\">";
string[] invalidResources = null;
// Get a list of queryable layers in all map resources/services
try
{
ListItem[] queryLayers = this.GetQueryableLayers(out invalidResources);
if (queryLayers.Length > 0)
lstAvailableLayers.Items.AddRange(queryLayers);
else
{
lstAvailableLayers.Items.Add(new ListItem("(No queryable layers found)", "null"));
lstAvailableLayers.Enabled = false;
rbnSpecifyAvailableLayers.Enabled = false;
}
// if any map services aren't responding, let user know which ones
if (invalidResources.Length > 0) {
litInvalidResources.Text += String.Concat(
"<br/>Service failed to initialize/respond: ",
String.Join("; ", invalidResources), "</span>");
tCell.Controls.Add(litInvalidResources);
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Exception: " + e.Message);
lstAvailableLayers.Items.Add(new ListItem("(Error retrieving layers)", "null"));
lstAvailableLayers.Enabled = false;
rbnSpecifyAvailableLayers.Enabled = false;
litInvalidResources.Text += String.Concat(
"<br/>Server error details:", e.Message, "</span>");
tCell.Controls.Add(litInvalidResources);
}
lstAvailableLayers.SelectionMode = ListSelectionMode.Multiple;
lstAvailableLayers.Width = new Unit(200, UnitType.Pixel);
lstAvailableLayers.Rows = 8;
#endregion
#region Other options
tCell = CreateCellRow(ctlTable, 0);
tCell.Controls.Add(new LiteralControl("Selection tolerance (pixels) "));
txtSelectionTolerance = new TextBox();
txtSelectionTolerance.ID = "txtSelectionTolerance";
txtSelectionTolerance.ToolTip = "Number of pixels around user-drawn graphics to select." +
" Must be greater than zero to select from point or line layers with point tool.";
txtSelectionTolerance.Text = gSelTask.PointSelectionTolerance.ToString();
txtSelectionTolerance.Width = new Unit(20, UnitType.Pixel);
tCell.Controls.Add(txtSelectionTolerance);
tCell = CreateCellRow(ctlTable, 0);
ckbRenderSelectionSet = new CheckBox();
ckbRenderSelectionSet.ID = "ckbRenderSelectionSet";
ckbRenderSelectionSet.Text = "Highlight all features found ";
ckbRenderSelectionSet.Checked = true;
ckbRenderSelectionSet.ToolTip = "If true, all features found are rendered (highlighted) upon selection. Users may also highlight individual features, but turning off all-feature rendering also hides highlights on individual features.";
tCell.Controls.Add(ckbRenderSelectionSet);
cpSelectionSetColor = new ColorPicker();
cpSelectionSetColor.ID = "selectionSetColorPicker";
cpSelectionSetColor.Font.Name = "Verdana";
cpSelectionSetColor.Font.Size = new FontUnit(new Unit(8, UnitType.Point));
cpSelectionSetColor.BackColor = System.Drawing.Color.White;
cpSelectionSetColor.DropDownBorderColor = System.Drawing.Color.Silver;
cpSelectionSetColor.DropDownBorderStyle = BorderStyle.Solid;
cpSelectionSetColor.DropDownBorderWidth = new Unit(1, UnitType.Pixel);
cpSelectionSetColor.ChosenColor = System.Drawing.Color.Yellow;
cpSelectionSetColor.ShowColorNames = false;
cpSelectionSetColor.DisplayText = "Color for all features ";
//cpSelectionSetColor.ToolTip = "Click to choose color to use for selecting features";
tCell.Controls.Add(cpSelectionSetColor);
tCell = CreateCellRow(ctlTable, 0);
cpHighlightColor = new ColorPicker();
cpHighlightColor.ID = "cpHighlightColor";
cpHighlightColor.Font.Name = "Verdana";
cpHighlightColor.Font.Size = new FontUnit(new Unit(8, UnitType.Point));
cpHighlightColor.BackColor = System.Drawing.Color.White;
cpHighlightColor.DropDownBorderColor = System.Drawing.Color.Silver;
cpHighlightColor.DropDownBorderStyle = BorderStyle.Solid;
cpHighlightColor.DropDownBorderWidth = new Unit(1, UnitType.Pixel);
cpHighlightColor.ChosenColor = System.Drawing.Color.Aqua;
cpHighlightColor.ShowColorNames = false;
cpHighlightColor.DisplayText = "Color for individual feature highlight ";
tCell.Controls.Add(cpHighlightColor);
tCell = CreateCellRow(ctlTable, 0);
ckbHidePreviousSelections = new CheckBox();
ckbHidePreviousSelections.ID = "ckbHidePreviousSelections";
ckbHidePreviousSelections.Text = "Hide previous selections on select ";
ckbHidePreviousSelections.Checked = true;
ckbHidePreviousSelections.ToolTip = "Whether to hide prior selections with this task when a new selection is made.";
tCell.Controls.Add(ckbHidePreviousSelections);
#endregion
#region OK/cancel row
tCell = CreateCellRow(ctlTable, 0);
Button okButton = new Button();
okButton.ID = "okButton";
okButton.Text = "OK";
okButton.Width = new Unit(75, UnitType.Pixel);
okButton.Click += new EventHandler(okButton_Click);
tCell.Controls.Add(okButton);
Button cancelButton = new Button();
cancelButton.ID = "cancelButton";
cancelButton.Text = "Cancel";
cancelButton.Width = new Unit(75, UnitType.Pixel);
cancelButton.Click += new EventHandler(cancelButton_Click);
tCell.Controls.Add(cancelButton);
#endregion
}
private TableCell CreateCellRow(Table table, int indentPixels)
{
TableRow tRow = new TableRow();
table.Rows.Add(tRow);
TableCell tCell = new TableCell();
tCell.Wrap = false;
tCell.Style[HtmlTextWriterStyle.FontWeight] = "normal";
if (indentPixels < 1)
{
tCell.ColumnSpan = 2;
}
else
{
TableCell spCell = new TableCell();
spCell.Text = " ";
spCell.Width = new Unit(indentPixels, UnitType.Pixel);
tRow.Cells.Add(spCell);
}
tRow.Cells.Add(tCell);
return tCell;
}
private void cancelButton_Click(object sender, EventArgs e)
{
OnWebConfigurationCancel(new EventArgs());
}
private void okButton_Click(object sender, EventArgs e)
{
if (gSelTask == null)
return;
// get user-selected values from the web dialog and store them in the task
gSelTask.Title = dialogTitle.Text;
gSelTask.PointSelectionTolerance = int.Parse(txtSelectionTolerance.Text);
gSelTask.HidePreviousSelections = ckbHidePreviousSelections.Checked;
if (rbnAllowAllLayers.Checked)
{
gSelTask.SelectionLayerNames = null;
}
else
{
// compile a list of selectable layers
StringBuilder sbLayers = new StringBuilder();
foreach (ListItem lyrItem in lstAvailableLayers.Items)
if (lyrItem.Selected)
{
if (sbLayers.Length > 0)
sbLayers.Append("::");
sbLayers.Append(lyrItem.Text);
}
gSelTask.SelectionLayerNames = sbLayers.ToString();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -