📄 mainwebform.aspx.cs
字号:
// InitLayerConfigAndGridViewLayerByMapCongtrol();
InitGridViewLayerByLayerConfigTalbe();
// if (!IsPostBack)
// InitGridViewLayerInCheckByMapControl();
}
protected void CheckBoxLayerAll_CheckedChanged(object sender, EventArgs e)
{
for(int i=0;i<GridViewLayer.Rows.Count ;i++)
{
GridViewRow row = GridViewLayer.Rows[i];
this.CurMapLayerConfigTable.Rows[i][0] = CheckBoxLayerAll.Checked;
//CheckBox checkVisible = (CheckBox)row.FindControl("checkBoxLayer");
//checkVisible.Checked = CheckBoxLayerAll.Checked ;
}
}
protected void GridViewLayer_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
CheckBox checkVisible = (CheckBox)e.Row.FindControl("checkBoxLayer");
checkVisible.TabIndex = (short)e.Row.RowIndex;
checkVisible.Checked = Convert.ToBoolean(this.CurMapLayerConfigTable.Rows[e.Row.RowIndex][0]);
checkVisible.CheckedChanged += new EventHandler(checkVisible_CheckedChanged);
}
catch
{
}
}
void checkVisible_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkVisible = (CheckBox)sender;
DataTable dt = this.CurMapLayerConfigTable;
dt.Rows[checkVisible.TabIndex][0] = checkVisible.Checked;
MapControl1.Layers[checkVisible.TabIndex].Visible = checkVisible.Checked;
this.MapControl1.Update();
}
#endregion
#region 地图打印
/// <summary>
/// 当前地图的宽度
/// </summary>
private int MapControlWidth
{
set
{
Session["MapControlWidth"] = value;
}
get
{
if (Session["MapControlWidth"] == null)
return 0;
return (int)Session["MapControlWidth"];
}
}
/// <summary>
/// 当前地图的高度
/// </summary>
private int MapControlHeight
{
set
{
Session["MapControlHeight"] = value;
}
get
{
if (Session["MapControlHeight"] == null)
return 0;
return (int)Session["MapControlHeight"];
}
}
#endregion
#region 按照比例尺显示地图
/// <summary>
/// 按照相应的比例尺显示地图
/// </summary>
/// <param name="scale"></param>
private void ViewByScale(double scale)
{
CurMapScale = 1 / scale;
}
protected void IBtnScale_Click(object sender, ImageClickEventArgs e)
{
try
{
ViewByScale(Convert.ToDouble(DropDownListScale.Text.Trim ()));
}
catch
{
this.ShowDialog("输入的比例尺不正确,请重新输入!");
}
}
protected void DropDownListScale_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownListScale.Text != "")
{
TextBoxScale.Text = DropDownListScale.Text;
DropDownListScale.SelectedIndex = 0;
}
}
#endregion
#region 右键菜单
protected void LBtnLL_Click(object sender, EventArgs e)
{
DrawLL();
}
#endregion
#region 地图查询
public int MapQueryCount = 0;
/// <summary>
/// 初始化地图查询
/// </summary>
private void InitMapQuery()
{
if (PostBackCount == 2)
{
dropDownType.DataSource = this.MapQueryType;
this.DataBind();
}
DingWei();
}
private void DingWei()
{
try
{
if (Request["Result_X"] != null && Convert.ToString(Request["Result_X"]) != "" && Request["Result_Y"] != null && Convert.ToString(Request["Result_Y"]) != "")
{
double x = Convert.ToDouble(Request["Result_X"].Replace(",",""));
double y = Convert.ToDouble(Request["Result_Y"].Replace(",",""));
this.MapControl1.CenterPoint = new MapCoord(x, y);
this.CurMapScale = 0.0001;
this.MapControl1.CustomLayer.Marks.Add(this.MapControl1.CustomLayer.Marks.Count.ToString () , this.MapControl1.CenterPoint.X, this.MapControl1.CenterPoint.Y, "<img src='images/hotballold.gif'>");
this.MapControl1.CustomLayer.Visible = true;
this.MapControl1.Update();
this.Page.RegisterHiddenField("Result_X", "");
this.Page.RegisterHiddenField("Result_Y", "");
}
}
catch
{
}
}
#region 查询属性数据
/// <summary>
/// 地图查询结果
/// </summary>
private Recordset MapQueryResult
{
set
{
Session ["MapQueryResult"] = value;
GetPageCount();
MapQueryCurPageIndex = 0;
SetBtnVisible();
}
get
{
if (Session["MapQueryResult"] == null)
return null;
return (Recordset)Session["MapQueryResult"];
}
}
/// <summary>
/// 地图查询类型
/// </summary>
private string[] MapQueryType
{
get
{
if(Application["MapQueryType"]==null)
return new string[0];
return (string[])Application["MapQueryType"];
}
}
/// <summary>
/// 地图查询图层
/// </summary>
private string[] MapQueryLayer
{
get
{
if (Application["MapQueryLayer"] == null)
return new string[0];
return (string[])Application["MapQueryLayer"];
}
}
/// <summary>
/// 地图查询字段
/// </summary>
private string[] MapQueryField
{
get
{
if (Application["MapQueryField"] == null)
return new string[0];
return (string[])Application["MapQueryField"];
}
}
/// <summary>
/// 显示或查询字段名称
/// </summary>
private string MapQueryShowAndQueryField
{
set
{
Session["MapQueryShowAndQueryField"] = value;
}
get
{
if (Session["MapQueryShowAndQueryField"] == null)
return "";
return (string)Session["MapQueryShowAndQueryField"];
}
}
#endregion
/// <summary>
/// 根据查询类型得到相应的图层名称和查询字段
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private string[] GetLayerAndFieldByType(string type)
{
string[] queryType = this.MapQueryType;
string[] queryLayer = this.MapQueryLayer;
string[] queryField = this.MapQueryField;
int index = -1;
for (int i = 0; i < queryType.Length; i++)
{
if (type.Trim() == queryType[i].Trim())
{
index = i;
break;
}
}
if (index == -1 || index >= queryLayer.Length || index >= queryField.Length)
return new string[] { };
return new string[] { queryLayer[index], queryField[index] };
}
/// <summary>
/// 根据类型和名称进行查询
/// </summary>
/// <param name="type"></param>
/// <param name="queryText"></param>
/// <returns></returns>
private Recordset QueryInMap(string type,string queryText)
{
string[] query = this.GetLayerAndFieldByType(type);
if (query.Length == 0)
return null;
this.MapQueryShowAndQueryField = query[1];
QueryParam qParam = new QueryParam();
qParam.HasGeometry = false;
QueryLayer layer = new QueryLayer(query[0]);
layer.WhereClause = string.Format("{0} like '%{1}%'", query[1], queryText);
layer.SortClause = " order by " + query[1];
qParam.Layers = new QueryLayer[] { layer };
// return MapControl1.QueryBySQL(qParam);
ResultSet rs=MapControl1.QueryBySQL(qParam);
if (rs.Recordsets == null || rs.Recordsets.Length == 0)
return null;
return rs.Recordsets[0];
}
/// <summary>
/// 得到查询结果总页数
/// </summary>
/// <returns></returns>
private void GetPageCount()
{
if (this.MapQueryResult == null || this.MapQueryResult.Records.Length == 0)
{
this.MapQueryTotalPage = 0;
return;
}
int count = this.MapQueryResult.Records.Length / this.MapQueryPageSize;
if (this.MapQueryResult.Records.Length % this.MapQueryPageSize > 0)
count++;
this.MapQueryTotalPage = count;
}
private void SetBtnVisible()
{
this.IBtnPre.Visible = this.MapQueryCurPageIndex != 0;
IBtnNext.Visible = this.MapQueryCurPageIndex < this.MapQueryTotalPage - 1;
}
#region 分页控制
/// <summary>
/// 显示当前页
/// </summary>
private int MapQueryCurPageIndex
{
set
{
Session["MapQueryCurPageIndex"] = value;
}
get
{
if (Session["MapQueryCurPageIndex"] == null)
return -1;
return (int)Session["MapQueryCurPageIndex"];
}
}
/// <summary>
/// 总页数
/// </summary>
private int MapQueryTotalPage
{
set
{
Session["MapQueryTotalPage"] = value;
}
get
{
if (Session["MapQueryTotalPage"] == null)
return -1;
return (int)Session["MapQueryTotalPage"];
}
}
/// <summary>
/// 每页显示的记录数
/// </summary>
private int MapQueryPageSize
{
set
{
Session["MapQueryPageSize"] = value;
}
get
{
int pageSize = 10;
string size = ConfigurationManager.AppSettings["MapResultPageSize"];
try
{
pageSize = Convert.ToInt16(size);
}
catch
{
}
return pageSize;
//if (Session["MapQueryPageSize"] == null)
// return 10;
//return (int)Session["MapQueryPageSize"];
}
}
#endre
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -