📄 demo.aspx.cs
字号:
}
}
/// <summary>
/// 把地图名显示在下拉框中,当前地图为默认选中项
/// </summary>
/// <param name="list">要显示地图名的下拉框</param>
private void FillMapList(DropDownList list)
{
FillMapList(list, false);
}
#endregion
#region 显示图层列表
/// <summary>
/// 把地图图层显示在下拉框中
/// </summary>
/// <param name="list">要显示图层名的下拉框</param>
private void FillLayerList(DropDownList list)
{
FillLayerList(list, null);
}
private void FillLayerList(DropDownList list, LayerType[] layerTypes)
{
Layer[] layers = this.MapControl1.Layers;
if (layers == null || layers.Length < 1)
{
return;
}
list.Items.Clear();
string layerName;
string layerCaption;
int listIndex = 0;
int c = 0;
if (layerTypes != null)
{
c = layerTypes.Length;
}
for (int i = 0; i < layers.Length; i++)
{
bool flag = false;
if (layerTypes == null)
{
flag = true;
}
else
{
for (int j = 0; j < c; j++)
{
if (layers[i].LayerType == layerTypes[j])
{
flag = true;
break;
}
}
}
if (flag)
{
layerName = layers[i].Name;
layerCaption = layers[i].Caption;
layerCaption = layerCaption.Split('@')[0];
list.Items.Add(layerCaption);
list.Items[listIndex].Value = layerName;
listIndex++;
}
}
}
#endregion
#region 地图查询前的事件
/// <summary>
/// 地图查询前的事件。修改查询参数。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MapControl1_Querying(object sender, SuperMap.IS.WebControls.EventArguments.QueryingEventArgs e)
{
// 设置期望返回的记录数,以避免一次返回太多结果。
e.Params.ExpectCount = 10;
// 高亮查询区域。
e.Params.Highlight.HighlightQueryArea = true;
e.Params.Highlight.QueryAreaStyle = new SuperMap.IS.Utility.Style();
e.Params.Highlight.QueryAreaStyle.PenColor = Convertor.SystemColorToIntegerColor(Color.Blue);
e.Params.Highlight.QueryAreaStyle.BrushColor = Convertor.SystemColorToIntegerColor(Color.Blue);
e.Params.Highlight.QueryAreaStyle.BrushBackTransparent = true;
e.Params.Highlight.QueryAreaStyle.BrushStyle = 2;
}
#endregion
#region 公交分析
/// <summary>
/// 公交方案查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnFindBus_Click(object sender, System.EventArgs e)
{
SetBusToolboxActive();
string strBusStart = this.txtBusStart.Text;
string strBusEnd = this.txtBusEnd.Text;
int transferTimes;
int.TryParse(this.lstChangeTimes.SelectedValue, out transferTimes);
bool bMost = this.checkBoxMostChange.Checked ? true : false;
BusSolutionItem solution = this.MapControl1.SpatialAnalystOperator.GetBusSolution(strBusStart, strBusEnd, transferTimes, bMost, 10);
if (solution != null && solution.RoutingItems != null && solution.RoutingItems.Length > 0)
{
// 得到最终方案,直接显示。
ShowBusSolutionResult(solution);
return;
}
else
{
// 没有得到最终方案,可能:起点站、终点站不唯一,需要二次查询;没有匹配的方案。
this.treeBusResult.Nodes.Clear();
this.treeBusResult.Visible = false;
if (solution != null && solution.StartStops != null && solution.EndStops != null)
{
// 起点站、终点站不唯一,需要二次查询。
BusStopItem[] busStartStops = solution.StartStops;
BusStopItem[] busEndStops = solution.EndStops;
this.lstBusStarts.Items.Clear();
for (int i = 0; i < busStartStops.Length; i++)
{
ListItem curItem = new ListItem();
curItem.Text = busStartStops[i].Name + "(ID=" + busStartStops[i].ID + ")";
curItem.Value = busStartStops[i].InterChangeID.ToString(NumberFormatInfo.InvariantInfo);
this.lstBusStarts.Items.Add(curItem);
}
this.lstBusEnds.Items.Clear();
for (int i = 0; i < busEndStops.Length; i++)
{
ListItem curItem = new ListItem();
curItem.Text = busEndStops[i].Name + "(ID=" + busEndStops[i].ID + ")"; ;
curItem.Value = busEndStops[i].InterChangeID.ToString(NumberFormatInfo.InvariantInfo);
this.lstBusEnds.Items.Add(curItem);
}
this.PanelBusSearch.Visible = false;
this.panelBusStops.Visible = true;
}
else
{
// 没有匹配的方案。
ShowBusSolutionResultNothing();
}
}
}
/// <summary>
/// 呈现公交方案结果
/// </summary>
/// <param name="solution"></param>
private void ShowBusSolutionResult(BusSolutionItem solution)
{
this.BusSolutionRef = solution;
this.TreeShowType = "Solution";
this.PanelBusResult.Visible = true;
// this.treeBusResult.Visible = true;
this.btnBusResultCancel.Visible = true;
// 隐藏查询面板。
this.PanelBusSearch.Visible = false;
// this.treeBusResult.Nodes.Clear();
this.lblBusResult.Text = string.Empty;
this.lblBusResult.Visible = true;
if (solution != null && solution.RoutingItems != null)
{
System.Text.StringBuilder sb = new StringBuilder();
int routingCount = solution.RoutingItems.Length;
BusRoutingItem curItem;
sb.Append("<br>共搜索到 " + routingCount + " 种换乘方案:");
for (int i = 0; i < routingCount; i++)
{
// Microsoft.Web.UI.WebControls.TreeNode solutionNode = new Microsoft.Web.UI.WebControls.TreeNode();
// solutionNode.Text = "方案" + Convert.ToString(i+1);
sb.Append("<br> " + GetHrefSolution(i) + ": ");
curItem = solution.RoutingItems[i];
string upStop;
string busline;
string downStop;
string upStopSmID;
string buslineSmID;
string downStopSmID;
MapCoord upStopLocation;
MapCoord downStopLocation;
for (int j = 0; j < curItem.UpStops.Length; j++)
{
upStop = curItem.UpStops[j].Name;
busline = curItem.BusLines[j].Name;
downStop = curItem.DownStops[j].Name;
upStopSmID = curItem.UpStops[j].ID.ToString();
buslineSmID = curItem.BusLines[j].SmID.ToString();
downStopSmID = curItem.DownStops[j].ID.ToString();
upStopLocation = curItem.UpStops[j].Location;
downStopLocation = curItem.DownStops[j].Location;
sb.Append("从 " + GetHrefStop(upStopSmID, upStop, i, upStopLocation) + " 站上车,乘坐 " + busline + " 汽车,在 " + GetHrefStop(downStopSmID, downStop, i, downStopLocation) + " 站下车; <br>");
/*
Microsoft.Web.UI.WebControls.TreeNode buslineNode = new Microsoft.Web.UI.WebControls.TreeNode();
buslineNode.Text = busline;
buslineNode.NodeData = buslineSmID;
Microsoft.Web.UI.WebControls.TreeNode upstopNode = new Microsoft.Web.UI.WebControls.TreeNode();
upstopNode.Text = upStop;
upstopNode.NodeData = upStopSmID;
Microsoft.Web.UI.WebControls.TreeNode downstopNode = new Microsoft.Web.UI.WebControls.TreeNode();
downstopNode.Text = downStop;
downstopNode.NodeData = downStopSmID;
buslineNode.Nodes.Add(upstopNode);
buslineNode.Nodes.Add(downstopNode);
solutionNode.Nodes.Add(buslineNode);
*/
}
// this.treeBusResult.Nodes.Add(solutionNode);
}
this.lblBusResult.Text += sb.ToString();
}
}
/// <summary>
/// 清除公交方案结果树
/// </summary>
private void ShowBusSolutionResultNothing()
{
this.treeBusResult.Nodes.Clear();
this.treeBusResult.Visible = false;
this.lblBusResult.Text = string.Empty;
// 显示查询面板。
this.PanelBusSearch.Visible = true;
// 弹出提示对话框。
this.ShowAlertDialog("ShowBusSolutionResultNothing", "没有查询结果!");
}
#endregion
#region 公交站点查询, 公交线路查询
/// <summary>
/// 公交站点查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnBusStopQuery_Click(object sender, System.EventArgs e)
{
SetBusToolboxActive();
this.TreeShowType = "BusStop";
this.treeBusResult.Nodes.Clear();
this.treeBusResult.Visible = false;
string fuzzyStopText = this.txtBusStopQuery.Text;
if (string.IsNullOrEmpty(fuzzyStopText))
{
ShowAlertDialog("BusStopQuery", "请输入站点名!");
return;
}
BusStopItem[] busStopItems = this.MapControl1.SpatialAnalystOperator.FindBusStop(fuzzyStopText);
if (busStopItems == null)
{
ShowAlertDialog("BusLineQuery", "没有找到匹配的站点!");
return;
}
this.PanelBusSearch.Visible = false;
this.PanelBusResult.Visible = true;
this.treeBusResult.Visible = true;
this.btnBusResultCancel.Visible = true;
// this.lblBusResult.Visible = true;
int busStopCount = busStopItems.Length;
// this.lblBusResult.Text = "<br>您搜索的是 \"" + fuzzyStopText + "\",共找到 " + busStopCount + " 个匹配的站点:";
// System.Text.StringBuilder sb = new StringBuilder();
string stopName;
int interChangeID;
int stopID;
string stopNodeText;
BusLineItem[] busLineItems;
for (int i = 0; i < busStopCount; i++)
{
stopName = busStopItems[i].Name;
interChangeID = busStopItems[i].InterChangeID;
stopID = busStopItems[i].ID;
stopNodeText = stopName + "(ID=" + stopID + ")";
Microsoft.Web.UI.WebControls.TreeNode stopNode = new Microsoft.Web.UI.WebControls.TreeNode();
stopNode.Text = stopNodeText;
stopNode.NodeData = stopID.ToString(NumberFormatInfo.InvariantInfo);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -