|
|
Posted on 2008-07-03 22:37 长沙小能 阅读(333) 评论(28) 编辑 收藏 所属分类: ARCGIS SERVER
本文版权归小能所有,转载麻烦标明出处,谢谢! 同时写作过程中也参阅了大量其他网络文档,如果您觉得侵犯版权,请和我联系:chinazhousheng@gmail.com
饮食场所地图标注服务功能,即当客户端人员进行属性查询或者空间查询后,如果想进一步获取更加详细的信息,则点击电子地图中其位置图标,则页面将显示企业的具体信息,如特色菜、详细介绍等。还可以通过移动、放大、缩小查看该饮食场所的周边信息。系统的后续工作还将进一步扩展此项相关功能,如到达该地点的公交线路等。图1为系统界面图。需要源码的请留自己的邮箱!
<图1>
图中彩色块体为目标点击物,左键点击后,系统界面的右边将出现其详细信息。如图2
<图2>
实现原理为:
(1)在工具栏中加入一个工具按钮。
(2)服务器代码方面,首先查找要查询的图层,并将当前点转化成MapPoint
(3)关键在于使用以上条件,并采用方法IQueryFunctionality.Identify获取到数据集
(4)适当处理,将信息显示在页面上。
整个例子采用Ajax效果,达到无刷新效果,虽然没有Google的酷,但我相信,大家处理一下,采用层的显示是完全可以达到它的效果的.
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using ESRI.ArcGIS;
using ESRI.ArcGIS.ADF.Web;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web.Display.Graphics;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
using System.Data;
using System;
using System.Web.UI.WebControls;
using System.Web.UI;


using ESRI.ArcGIS.ADF.Web.UI.WebControls;


using ESRI.ArcGIS.ADF.Web;
using ESRI.ArcGIS.ADF;

using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;
using ESRI.ArcGIS.ADF.Web.DataSources.Graphics;
using ESRI.ArcGIS.ADF.ArcGISServer;


using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Geodatabase;

using ESRI.ArcGIS.ADF.Connection;

 /**//// <summary>
/// MapIdentify 的摘要说明
/// </summary>
public class MapIdentify :IMapServerToolAction
  {
public MapIdentify()
 {
//
// TODO: 在此处添加构造函数逻辑
//
}

 IMapServerToolAction 成员#region IMapServerToolAction 成员

public DataRow minus_row;

public void ServerAction(ToolEventArgs args)
 {
Map mapctrl = null;
mapctrl = (Map)args.Control;

IEnumerable func_enum = null;
func_enum =mapctrl.GetFunctionalities();

System.Data.DataTable datatable = null;
PointN txt_Point = new PointN();


//
string name_eat = "null";

foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality gisfunctionality in func_enum)
 {

//对特定的数据库图层进行查询
if (gisfunctionality.Resource.Name == "CsMap")
 {
ESRI.ArcGIS.ADF.Web.DataSources.IMapResource gResource;
gResource = (ESRI.ArcGIS.ADF.Web.DataSources.IMapResource)gisfunctionality.Resource;



bool supported = false;
ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = null;
gisresource = gisfunctionality.Resource;
supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));

//如果支持
if (supported)
 {
ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;
qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);

string[] lids;
string[] lnames;

qfunc.GetQueryableLayers(null, out lids, out lnames);


//获取屏幕点
ESRI.ArcGIS.ADF.Web.Geometry.Point pnt = new ESRI.ArcGIS.ADF.Web.Geometry.Point() ;
ESRI.ArcGIS.ADF.Web.UI.WebControls.PointEventArgs ptargs = null;
ptargs = (PointEventArgs)args;

pnt= ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(ptargs.ScreenPoint.X,ptargs.ScreenPoint.Y, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);


System.Data.DataTable[] qdatatables = qfunc.Identify(null, pnt, 1, ESRI.ArcGIS.ADF.Web.IdentifyOption.AllLayers, lids);

//将指点的图层的表格数据赋给表
datatable = qdatatables[3];//为饮食所在图层
double pnt_xy = pnt.X + pnt.Y;
double minus_xy = 0;
double add_xy;
int first_row=0; //判断是否是第一行,为0为第一行;为1表示为其他行;


 获取点的坐标#region 获取点的坐标
DataRowCollection drs = datatable.Rows;

int shpind = -1;
for (int i = 0; i < datatable.Columns.Count; i++)
 {
if (datatable.Columns[i].DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))
 {
shpind = i;
break;
}
}

try
 {
foreach (DataRow dr in drs)
 {
//ESRI.ArcGIS.ADF.Web.Geometry.Multipoint geom = (ESRI.ArcGIS.ADF.Web.Geometry.Multipoint)dr[shpind];
//ESRI.ArcGIS.ADF.Web.Geometry.PointCollection pointcol = geom.Points;
//txt_Point.X = pointcol[0].X;
//txt_Point.Y = pointcol[0].Y;
ESRI.ArcGIS.ADF.Web.Geometry.Point geom = (ESRI.ArcGIS.ADF.Web.Geometry.Point)dr[shpind];
//add_xy=pointcol[0].X+pointcol[0].Y;
add_xy = geom.X + geom.Y;

if(first_row==0)
 {
minus_xy = System.Math.Abs(add_xy-pnt_xy);
minus_row = dr;
first_row = 1;
name_eat = minus_row["餐饮店名称"].ToString();
}
else if(System.Math.Abs(pnt_xy-add_xy)<minus_xy)
 {
minus_xy = System.Math.Abs(pnt_xy - add_xy);
minus_row = dr;
name_eat = minus_row["餐饮店名称"].ToString();

}


}
}
catch (Exception q)
 {
}

#endregion


if (gResource == null)
return;

//
// GridView gdview = (GridView)mapctrl.Page.FindControl("GridView1");
//TextBox txt_name = (TextBox)mapctrl.Page.FindControl("FloatingPanel9$Txt_Name");
//设置图片
System.Web.UI.WebControls.Image Image1 = (System.Web.UI.WebControls.Image)mapctrl.Page.FindControl("Image1");
//Image1.ImageUrl = "~/Img/images_sk.jpg";//huogongdian
Image1.ImageUrl = "~/Img/huogongdian.jpg";
Image1.Visible = true;

//设置label

Label eat_name = (Label)mapctrl.Page.FindControl("eat_name");
eat_name.Text = "<br/><br/> 餐饮名称:" + name_eat + "<br/>";
eat_name.Visible = true;
//
Label eat_cai = (Label)mapctrl.Page.FindControl("eat_cai");
eat_cai.Text = "<br/> 特色菜系:" + minus_row["特色菜"].ToString() + "<br/>";
//
Label eat_demo = (Label)mapctrl.Page.FindControl("eat_demo");
eat_demo.Text = "<br/> 详细介绍:" + minus_row["详细介绍"].ToString() + "<br/>";
//

Label eat_tel = (Label)mapctrl.Page.FindControl("eat_tel");
eat_tel.Text = "<br/> 订餐热线:" + minus_row["订餐热线"].ToString() + "<br/>";

Label eat_recom = (Label)mapctrl.Page.FindControl("eat_recom");
eat_recom.Text = "<br/> 推荐指数:" + minus_row["推荐数"].ToString() + "<br/>";

object[] oa = new object[1];
string showtable = "'visible'";
//设置数据源
// gdview.DataSource = datatable;
//gdview.DataBind();
// txt_name.Text = datatable.Rows[0]["NAME"].ToString();
// txt_name.Visible = true;
string returnstring = null;

using (System.IO.StringWriter sw = new System.IO.StringWriter())
 {
HtmlTextWriter htw = new HtmlTextWriter(sw);
// txt_name.RenderControl(htw);
// gdview.RenderControl(htw);
Image1.RenderControl(htw);
eat_name.RenderControl(htw);
eat_cai.RenderControl(htw);
eat_tel.RenderControl(htw);
eat_demo.RenderControl(htw);

htw.Flush();
returnstring = sw.ToString();
}

CallbackResult cr = new CallbackResult("div", "identify", "innercontent", returnstring);
mapctrl.CallbackResults.Add(cr);
CallbackResult cr1 = new CallbackResult("div", "img_div", "innercontent", returnstring);
mapctrl.CallbackResults.Add(cr1);
CallbackResult cr2 = new CallbackResult("div", "img_lab", "innercontent", returnstring);
mapctrl.CallbackResults.Add(cr2);

if (datatable.Rows.Count > 0)
 {
showtable = "'visible'";
}
else
 {
showtable = "'hidden'";
}

// 设置griddiv是否显示
string sa = "var griddiv = document.getElementById('identify');";
sa += "griddiv.style.visibility = " + showtable + ";";
oa[0] = sa;

CallbackResult cr4 = new CallbackResult(null, null, "javascript", oa);
mapctrl.CallbackResults.Add(cr1);

if (mapctrl.ImageBlendingMode == ImageBlendingMode.WebTier)
 {
mapctrl.Refresh();
}
else if (mapctrl.ImageBlendingMode == ImageBlendingMode.Browser)
 {
mapctrl.RefreshResource(gResource.Name);
}
}
}
}



}
#endregion
}

Feedback
您好!我是一名GIS应届生,有辛做arcgis server的开发,但什么都不知道,希望你能够给一些入门的建议,直接发我油箱里,非常感谢了.本人实在是什么都不知道!
@feifei123 恭喜你,我想有项目做就是一个最大的学习动力!入门的资料我一直向别人推荐 flyingis.cnblogs.com的博客里面的内容,非常人非常好,另外ESRI的中文社区里面也有非常多的资料,建议多多学习!另外我不是高手,我很多时间也是上EDN等来充实自己,不过现在没有项目了,所以就暂时没有接触AGS了,所以只能向你提供这些了!呵呵
您好!我是一名arcgis server爱好者,看了您的文章感觉受益良多,由于刚刚接触GIS,有很多不明白的地方,希望能发到我的邮箱,在此非常感谢了!
请给我一份源代码,我的邮箱是zhangzk_sc_cn@126.com,谢谢!
您好,我是一位刚刚踏入社会参加工作的本科毕业生,最近刚刚接触学习ArcGIS Server 感觉比较迷茫,想跟您要份代码以作参考,我的邮箱是:kuchanly@163.com 十分感谢您将您的经验与大家共勉!
您好,我最近在研究arcserver web adf方面开发,楼主可否将此代码发给我一份,非常感谢! 邮箱:260774652@qq.com
@Zhangzk @来诺 @鲁洋 @小尧 目前暂时不在长沙,等回来了马上发
您好,我想多跟您学学GIS,请发我一份哟
cyscsharp@163.com
thanks
|