gisempire100
捉鬼专家
捉鬼专家
  • 注册日期2004-08-13
  • 发帖数552
  • QQ
  • 铜币2462枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2232回复:2

ArcGIS Server 开发系列(三)--漫游 Graphics data sources

楼主#
更多 发布于:2008-03-06 20:21
<P>    和ArcGIS Server Local、ArcGIS Server Internet一样,GraphicsLayer是ArcGIS Server MapResource的一种,提供functionality给web controls使用。本文将在《ArcGIS Server 开发系列(二)--Web ADF 编程》示例基础上,增加查询结果高亮显示的功能,因为高亮显示的结果并不是图层本身所具备的,因此只需将高亮显示的图片存为graphics即可。</P>
<P>    目标:<BR>    查询结果的高亮显示</P>
<P>    准备工作:<BR>    1.以《ArcGIS Server 开发系列(二)--Web ADF 编程》示例配置和代码为基础。<BR>    2.MapResourceManager属性中增加一个名为Selection的MapResource,并将它移动到编号为0的位置,即显示在所有MapResource最上面。<BR><IMG src="http://www.cnblogs.com/images/cnblogs_com/flyingis/server301.gif" border=0><BR><BR>    可以看到GraphicsLayer的datasource是在内存中的,也就是说是为了临时显示或存储使用的,这样速度比较快。Selection一定要放在World上面,否则就被World图层覆盖掉了。</P>
<P >    代码实现:</P>
<P >    在UI界面上,增加一个command,用来清除graphics。<BR><IMG src="http://www.cnblogs.com/images/cnblogs_com/flyingis/server302.gif" border=0><BR><BR>    双击“Select”生成事件响应方法:</P>
<P >protected void cmdSelect_Click(object sender, EventArgs e)<BR>{<BR>    SelectFeatures();<BR>}</P>
<P >    代码的核心就在SelectFeature()里,它分为两个步骤,第一步对图层进行属性查询,第二步对查询结果进行高亮显示。首先是图层的属性查询:</P>
<P >int resource_index = 1;<BR>string targetlayername = "countries";<BR>System.Data.DataTable datatable = null;<BR>//直接获取MapResourceName为world的MapFunctionality,它的编号为1<BR>ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)Map1.GetFunctionality(resource_index);<BR>//先得到functionality,再获取resource<BR>ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = mf.Resource;<BR>bool supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));<BR>if (supported)<BR>{<BR>    ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;<BR>    qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);</P>
<P >    string[] lids;<BR>    string[] lnames;<BR>    qfunc.GetQueryableLayers(null, out lids, out lnames);</P>
<P >    ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();<BR>    spatialfilter.ReturnADFGeometries = false;<BR>    spatialfilter.MaxRecords = 1000;<BR>    spatialfilter.WhereClause = txtQuery.Text;<BR>           <BR>    datatable = qfunc.Query(null, lids[0], spatialfilter);<BR>}<BR>    这段代码和《ArcGIS Server 开发系列(二)--Web ADF 编程》示例中的代码相比,没有太多改动的地方,用到了ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality,它继承于ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality 接口。每一个web control可能拥有多个functionality,而funtionality是各种resource展现出来的,因此可以通过web controls--funcionalities--resources这条路线来获得当前的资源,那么如何让查询结果高亮显示呢?</P>
<P ><BR>//重新获得Map1控件所有的functionality<BR>IEnumerable gfc = Map1.GetFunctionalities();<BR>ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = null;<BR>foreach (IGISFunctionality gfunc in gfc)<BR>{<BR>    //找到名为"Selection"的MapResource<BR>    if (gfunc.Resource.Name == "Selection")<BR>    {<BR>        //down cast到ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource<BR>        gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;<BR>    }<BR>}</P>
<P >if (gResource == null)<BR>    return;</P>
<P >ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;</P>
<P >foreach (System.Data.DataTable dt in gResource.Graphics.Tables)<BR>{<BR>    if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)<BR>    {<BR>        glayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt;<BR>        break;<BR>    }<BR>}</P>
<P >if (glayer == null)<BR>{<BR>    glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();</P>
<P >    gResource.Graphics.Tables.Add(glayer);<BR>}</P>
<P >//清除已有数据<BR>glayer.Clear();</P>
<P >DataRowCollection drs = datatable.Rows;</P>
<P >int shpind = -1;<BR>for (int i = 0; i < datatable.Columns.Count; i++)<BR>{<BR>    if (datatable.Columns.DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))<BR>    {<BR>        //找到Geometry字段的序号<BR>        shpind = i;<BR>        break;<BR>    }<BR>}</P>
<P >try<BR>{<BR>    foreach (DataRow dr in drs)<BR>    {<BR>        ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)dr[shpind];<BR>       <BR>        //创建一个GraphicElement<BR>        ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge = null;<BR>        ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.Yellow);<BR>        ge.Symbol.Transparency = 50.0;<BR>       <BR>        //将GraphicElement添加到ElementGraphicsLayer中<BR>        glayer.Add(ge);<BR>    }<BR>}<BR>catch (InvalidCastException ice)<BR>{<BR>    throw new Exception("No geometry available in datatable");<BR>}</P>
<P >if (Map1.ImageBlendingMode == ImageBlendingMode.WebTier)<BR>{ Map1.Refresh(); }<BR>else if (Map1.ImageBlendingMode == ImageBlendingMode.Browser)<BR>{<BR>    //只刷新Graphics Resource<BR>    Map1.RefreshResource(gResource.Name);<BR>}<BR>    这次我们没有将搜索到的结果绑定到控件上,只要得到高亮显示的结果,测试一下程序,看看能得到什么样的效果。</P>
<P >protected void cmdSelect_Click(object sender, EventArgs e)<BR>{<BR>    SelectFeatures();<BR>}</P>
<P >    代码的核心就在SelectFeature()里,它分为两个步骤,第一步对图层进行属性查询,第二步对查询结果进行高亮显示。首先是图层的属性查询:</P>
<P >int resource_index = 1;<BR>string targetlayername = "countries";<BR>System.Data.DataTable datatable = null;<BR>//直接获取MapResourceName为world的MapFunctionality,它的编号为1<BR>ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)Map1.GetFunctionality(resource_index);<BR>//先得到functionality,再获取resource<BR>ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = mf.Resource;<BR>bool supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));<BR>if (supported)<BR>{<BR>    ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;<BR>    qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);</P>
<P >    string[] lids;<BR>    string[] lnames;<BR>    qfunc.GetQueryableLayers(null, out lids, out lnames);</P>
<P >    ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();<BR>    spatialfilter.ReturnADFGeometries = false;<BR>    spatialfilter.MaxRecords = 1000;<BR>    spatialfilter.WhereClause = txtQuery.Text;<BR>           <BR>    datatable = qfunc.Query(null, lids[0], spatialfilter);<BR>}<BR>    这段代码和《ArcGIS Server 开发系列(二)--Web ADF 编程》示例中的代码相比,没有太多改动的地方,用到了ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality,它继承于ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality 接口。每一个web control可能拥有多个functionality,而funtionality是各种resource展现出来的,因此可以通过web controls--funcionalities--resources这条路线来获得当前的资源,那么如何让查询结果高亮显示呢?</P>
<P ><BR>//重新获得Map1控件所有的functionality<BR>IEnumerable gfc = Map1.GetFunctionalities();<BR>ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = null;<BR>foreach (IGISFunctionality gfunc in gfc)<BR>{<BR>    //找到名为"Selection"的MapResource<BR>    if (gfunc.Resource.Name == "Selection")<BR>    {<BR>        //down cast到ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource<BR>        gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;<BR>    }<BR>}</P>
<P >if (gResource == null)<BR>    return;</P>
<P >ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;</P>
<P >foreach (System.Data.DataTable dt in gResource.Graphics.Tables)<BR>{<BR>    if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)<BR>    {<BR>        glayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt;<BR>        break;<BR>    }<BR>}</P>
<P >if (glayer == null)<BR>{<BR>    glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();</P>
<P >    gResource.Graphics.Tables.Add(glayer);<BR>}</P>
<P >//清除已有数据<BR>glayer.Clear();</P>
<P >DataRowCollection drs = datatable.Rows;</P>
<P >int shpind = -1;<BR>for (int i = 0; i < datatable.Columns.Count; i++)<BR>{<BR>    if (datatable.Columns.DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))<BR>    {<BR>        //找到Geometry字段的序号<BR>        shpind = i;<BR>        break;<BR>    }<BR>}</P>
<P >try<BR>{<BR>    foreach (DataRow dr in drs)<BR>    {<BR>        ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)dr[shpind];<BR>       <BR>        //创建一个GraphicElement<BR>        ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge = null;<BR>        ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.Yellow);<BR>        ge.Symbol.Transparency = 50.0;<BR>       <BR>        //将GraphicElement添加到ElementGraphicsLayer中<BR>        glayer.Add(ge);<BR>    }<BR>}<BR>catch (InvalidCastException ice)<BR>{<BR>    throw new Exception("No geometry available in datatable");<BR>}</P>
<P >if (Map1.ImageBlendingMode == ImageBlendingMode.WebTier)<BR>{ Map1.Refresh(); }<BR>else if (Map1.ImageBlendingMode == ImageBlendingMode.Browser)<BR>{<BR>    //只刷新Graphics Resource<BR>    Map1.RefreshResource(gResource.Name);<BR>}<BR>    这次我们没有将搜索到的结果绑定到控件上,只要得到高亮显示的结果,测试一下程序,看看能得到什么样的效果。</P>
<P >protected void cmdSelect_Click(object sender, EventArgs e)<BR>{<BR>    SelectFeatures();<BR>}</P>
<P >    代码的核心就在SelectFeature()里,它分为两个步骤,第一步对图层进行属性查询,第二步对查询结果进行高亮显示。首先是图层的属性查询:</P>
<P >int resource_index = 1;<BR>string targetlayername = "countries";<BR>System.Data.DataTable datatable = null;<BR>//直接获取MapResourceName为world的MapFunctionality,它的编号为1<BR>ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)Map1.GetFunctionality(resource_index);<BR>//先得到functionality,再获取resource<BR>ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = mf.Resource;<BR>bool supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));<BR>if (supported)<BR>{<BR>    ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;<BR>    qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);</P>
<P >    string[] lids;<BR>    string[] lnames;<BR>    qfunc.GetQueryableLayers(null, out lids, out lnames);</P>
<P >    ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();<BR>    spatialfilter.ReturnADFGeometries = false;<BR>    spatialfilter.MaxRecords = 1000;<BR>    spatialfilter.WhereClause = txtQuery.Text;<BR>           <BR>    datatable = qfunc.Query(null, lids[0], spatialfilter);<BR>}<BR>    这段代码和《ArcGIS Server 开发系列(二)--Web ADF 编程》示例中的代码相比,没有太多改动的地方,用到了ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality,它继承于ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality 接口。每一个web control可能拥有多个functionality,而funtionality是各种resource展现出来的,因此可以通过web controls--funcionalities--resources这条路线来获得当前的资源,那么如何让查询结果高亮显示呢?</P>
<P ><BR>//重新获得Map1控件所有的functionality<BR>IEnumerable gfc = Map1.GetFunctionalities();<BR>ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = null;<BR>foreach (IGISFunctionality gfunc in gfc)<BR>{<BR>    //找到名为"Selection"的MapResource<BR>    if (gfunc.Resource.Name == "Selection")<BR>    {<BR>        //down cast到ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource<BR>        gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;<BR>    }<BR>}</P>
<P >if (gResource == null)<BR>    return;</P>
<P >ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;</P>
<P >foreach (System.Data.DataTable dt in gResource.Graphics.Tables)<BR>{<BR>    if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)<BR>    {<BR>        glayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt;<BR>        break;<BR>    }<BR>}</P>
<P >if (glayer == null)<BR>{<BR>    glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();</P>
<P >    gResource.Graphics.Tables.Add(glayer);<BR>}</P>
<P >//清除已有数据<BR>glayer.Clear();</P>
<P >DataRowCollection drs = datatable.Rows;</P>
<P >int shpind = -1;<BR>for (int i = 0; i < datatable.Columns.Count; i++)<BR>{<BR>    if (datatable.Columns.DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))<BR>    {<BR>        //找到Geometry字段的序号<BR>        shpind = i;<BR>        break;<BR>    }<BR>}</P>
<P >try<BR>{<BR>    foreach (DataRow dr in drs)<BR>    {<BR>        ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)dr[shpind];<BR>       <BR>        //创建一个GraphicElement<BR>        ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge = null;<BR>        ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom, System.Drawing.Color.Yellow);<BR>        ge.Symbol.Transparency = 50.0;<BR>       <BR>        //将GraphicElement添加到ElementGraphicsLayer中<BR>        glayer.Add(ge);<BR>    }<BR>}<BR>catch (InvalidCastException ice)<BR>{<BR>    throw new Exception("No geometry available in datatable");<BR>}</P>
<P >if (Map1.ImageBlendingMode == ImageBlendingMode.WebTier)<BR>{ Map1.Refresh(); }<BR>else if (Map1.ImageBlendingMode == ImageBlendingMode.Browser)<BR>{<BR>    //只刷新Graphics Resource<BR>    Map1.RefreshResource(gResource.Name);<BR>}<BR>    这次我们没有将搜索到的结果绑定到控件上,只要得到高亮显示的结果,测试一下程序,看看能得到什么样的效果。</P>
<P ><IMG src="http://www.cnblogs.com/images/cnblogs_com/flyingis/server303.gif" border=0><BR><BR>    搜索出国家名称以"C"开头的国家,最典型的“中国”、“加拿大”已经找到了,这样我们就实现了高亮显示的功能。同样,我们进行开发后的小结,能想到些什么呢?还是按照CH风格来进行总结:<BR><BR>    第一,GraphicsLayer有两个子类,ElementGraphicLayer和FeatureGraphicLayer,因为程序中只需要暂时显示查询的结果,因此将查询要素存为ElementGraphicLayer就可以,想想在什么情况下使用FeatureGraphicLayer。<BR><BR>    第二,ElementGraphicLayer继承于System.Data.DataTable,gResource.graphics属于 System.Data.DataSet类型,这样使得我们在开发过程中,可以将GraphicElement添加到 ElementGraphicLayer,然后将ElementGraphicLayer添加到gResource.graphics,通过这种途径来向 GraphicsLayer的mapresource中添加数据,这种机制方便了我们能够像操纵datatable和dataset一样来控制 mapresource中的数据,既和.Net无缝整合,也在一定程度上降低了Server开发难度,例如代码中glayer.Clear()调用了datatable的clear()方法,还有后面GraphicElement的创建。<BR><BR>    第三,Map1.ImageBlendingMode决定了地图的刷新是刷新整个页面,还是仅刷新当前mapresource,这样的设计在web开发中尽可能的较少了网络数据传输量。<BR><BR>    Graphics data sources是学习ArcGIS Server data sources的基础,下面一篇,将介绍ArcGIS Server data sources的开发。</P>
喜欢0 评分0
A friend is never known till a man has need. ...CL
东博楠楠
路人甲
路人甲
  • 注册日期2009-03-23
  • 发帖数12
  • QQ357750979
  • 铜币142枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2009-03-24 11:44
学习了!<img src="images/post/smile/dvbbs/em02.gif" />
我要用自己的双足走在自己的双手铺设的轨道上!
举报 回复(0) 喜欢(0)     评分
muhaikun
路人甲
路人甲
  • 注册日期2009-03-20
  • 发帖数2
  • QQ
  • 铜币109枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2009-07-15 20:54
<img src="images/post/smile/dvbbs/em08.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部