|
阅读:1774回复:0
[转帖]添加外部字段进行专题渲染源码下载
最近一直在搞专题图渲染的工作,发现了很多问题。尤其是在<FONT color=red>外部数据做关联进行渲染</FONT>这一块,很多人都遇到了问题,也包括我。<BR><BR><BR><FONT face="宋体 ">经过资料查找及</FONT><FONT face="Times New Roman ">esri</FONT><FONT face="宋体 ">官方咨询,得出的结果是</FONT><FONT face="Times New Roman ">IMS</FONT><FONT face="宋体 ">中进行表关联必须是在<FONT color=red>同源数据库下或者</FONT></FONT><FONT face="Times New Roman "><FONT color=red>dbf</FONT></FONT><FONT face="宋体 "><FONT color=red>数据下</FONT>才可以关联。这样就会有很大的局限性,如果我们需要关联的数据是其他数据库中,或者</FONT><FONT face="Times New Roman ">xml</FONT><FONT face="宋体 ">组织的话,那又如何去做呢,照官方的说法,只有放弃吗?或者改用</FONT><FONT face="Times New Roman ">server</FONT><FONT face="宋体 ">的产品?</FONT><BR><BR><BR><FONT face="宋体 ">经过一天的努力,终于找到了解决的办法!现共享出来给需要的朋友。</FONT><BR><FONT face="Times New Roman "></FONT><BR><FONT face="宋体 ">该方法主要运用了</FONT><FONT face="Times New Roman "><FONT color=red>GraphicsLayer</FONT></FONT><FONT face="宋体 ">服务。大体思路是,将需要渲染的图层加入到</FONT><FONT face="Times New Roman ">GraphicsLayer</FONT><FONT face="宋体 ">中,并以</FONT><FONT face="Times New Roman ">FeatureGrapchicsLayer</FONT><FONT face="宋体 ">进行实例化。通过对</FONT><FONT face="Times New Roman ">FeatureGraphicsLayer</FONT><FONT face="宋体 ">添加字段的方式,将需要绑定的数据添加进来,最后对新添加的字段进行渲染,得以完成!</FONT><BR><FONT face="Times New Roman "></FONT><BR><FONT face="宋体 ">下面贴出</FONT><FONT face="Times New Roman ">2</FONT><FONT face="宋体 ">幅图片,数据采用</FONT><FONT face="Times New Roman ">IMS</FONT><FONT face="宋体 ">自带的</FONT><FONT face="Times New Roman ">USA</FONT><FONT face="宋体 ">数据,进行渲染的图层名为</FONT><FONT face="Times New Roman ">”STATES_LYR”</FONT><FONT face="宋体 ">,我的数据是放在</FONT><FONT face="Times New Roman ">SDE</FONT><FONT face="宋体 ">下的。</FONT><BR><BR><BR><FONT face="宋体 ">图一是未经渲染的效果图。</FONT><BR><FONT face="宋体 ">图二是经过添加外部字段后的渲染效果图。</FONT><BR><FONT face="宋体 "></FONT><BR><FONT size=4><FONT face="宋体 "><FONT color=red>由于采用了</FONT></FONT><FONT face="Times New Roman "><FONT color=#ff0000>GraphicsLayer做渲染,这样,原来的图层是不会变化的,仍然会显示在图上,可以在做渲染的同时将对应的图层进行隐藏,当想恢复时,只需要清空GraphicsLayer即可,同时恢复对应图层的显示!!!</FONT></FONT></FONT><BR><BR><FONT face="Times New Roman "></FONT><BR><FONT face="宋体 ">由于用到</FONT><FONT face="Times New Roman ">graphicslayer</FONT><FONT face="宋体 ">服务,这里做渲染就只能用</FONT><FONT face="Times New Roman ">WEB ADF</FONT><FONT face="宋体 ">组件进行编写,需要引用</FONT><BR><BR><FONT face="新宋体 "><FONT style="FONT-SIZE: 9pt">using</FONT></FONT><FONT face="新宋体 "><FONT style="FONT-SIZE: 9pt"> ESRI.ArcGIS.ADF.Web.Display.Renderer;<FONT color=blue> using</FONT> ESRI.ArcGIS.ADF.Web.Display.Symbol;</FONT></FONT><BR><FONT face="新宋体 "><FONT style="FONT-SIZE: 9pt">详细代码如下:</FONT></FONT><BR><FONT face="新宋体 "><FONT style="FONT-SIZE: 9pt">
<DIV class=blockcode> <DIV> <OL> <LI><BR> <LI><BR> <LI>protected void CallbackButton7_Clicked(object sender, EventArgs args)<BR> <LI> {<BR> <LI> ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)Map1;<BR> <LI><BR> <LI> ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)mapctrl.GetFunctionality(mapctrl.MapResourceManagerInstance.ResourceItems.Count - 1);<BR> <LI><BR> <LI> ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = mf.Resource;<BR> <LI><BR> <LI> ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();<BR> <LI> spatialfilter.ReturnADFGeometries = true;<BR> <LI> spatialfilter.MaxRecords = 1000;<BR> <LI> spatialfilter.WhereClause = "";<BR> <LI><BR> <LI> ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);<BR> <LI><BR> <LI> //获得states_lyr图层的所有数据<BR> <LI> System.Data.DataTable datatable = qfunc.Query(null, "0", spatialfilter);<BR> <LI><BR> <LI> //创建FeatureGraphicsLayer<BR> <LI> ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer graphicslayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer)ESRI.ArcGIS.ADF.Web.UI.WebControls.Converter.ToGraphicsLayer(datatable, System.Drawing.Color.Yellow, System.Drawing.Color.Green);<BR> <LI> IEnumerable gfc = mapctrl.GetFunctionalities();<BR> <LI> ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = null;<BR> <LI> foreach (IGISFunctionality gfunc in gfc)<BR> <LI> {<BR> <LI> if ((gfunc.Resource is ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource) ;; (gfunc.Resource.Name == "Selection"))<BR> <LI> {<BR> <LI> gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;<BR> <LI> gResource.Graphics.Tables.Clear(); //清空数据<BR> <LI> }<BR> <LI> }<BR> <LI><BR> <LI> //添加字段,int型,名称YN<BR> <LI> System.Data.DataColumn dcol = new System.Data.DataColumn("YN", System.Type.GetType("System.Int32"));<BR> <LI> graphicslayer.Columns.Add(dcol);<BR> <LI><BR> <LI> //给字段赋值,这里可以将想渲染的字段加进来吧!!<BR> <LI> int i = 0;<BR> <LI> foreach (DataRow dd in graphicslayer.Rows)<BR> <LI> {<BR> <LI> dd["YN"] = i;<BR> <LI> i++;<BR> <LI> } <BR> <LI><BR> <LI> //对字段中数值为5的进行渲染<BR> <LI> ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int> onevalue = new ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int>(5);<BR> <LI> ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol fs = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();<BR> <LI> fs.Color = System.Drawing.Color.Red;<BR> <LI> fs.FillType = ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.LightGray;<BR> <LI> fs.BoundaryColor = System.Drawing.Color.Red;<BR> <LI> onevalue.Symbol = fs;<BR> <LI><BR> <LI> //对字段中数值为1的进行渲染<BR> <LI> ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int> twovalue = new ESRI.ArcGIS.ADF.Web.Display.Renderer.UniqueValue<int>(1);<BR> <LI> ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol fs2 = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();<BR> <LI> fs2.Color = System.Drawing.Color.Blue;<BR> <LI> fs2.FillType = ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.Vertical;<BR> <LI> fs2.BoundaryColor = System.Drawing.Color.Red;<BR> <LI> twovalue.Symbol = fs2;<BR> <LI><BR> <LI> //给出渲染的字段YN<BR> <LI> ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer<int> vmr = new ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueMapRenderer<int>();<BR> <LI> vmr.ValueColumnName = "YN";<BR> <LI> vmr.DefaultLabel = "NoValue";<BR> <LI> ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol fsd = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleFillSymbol();<BR> <LI> fsd.Color = System.Drawing.Color.Yellow;<BR> <LI> fsd.FillType = ESRI.ArcGIS.ADF.Web.Display.Symbol.PolygonFillType.Cross;<BR> <LI> fsd.BoundaryColor = System.Drawing.Color.Red;<BR> <LI> vmr.DefaultSymbol = fsd;<BR> <LI><BR> <LI> ESRI.ArcGIS.ADF.Web.Display.Renderer.ValueCollection<int> valcol = vmr.Values;<BR> <LI> valcol.Add(onevalue);<BR> <LI> valcol.Add(twovalue);<BR> <LI><BR> <LI> //对graphicslayer进行渲染<BR> <LI> graphicslayer.Renderer = vmr;<BR> <LI> <BR> <LI> //将graphicslayer添加到graphicslayer服务中<BR> <LI> gResource.Graphics.Tables.Add(graphicslayer);<BR> <LI> //刷新TOC<BR> <LI> Toc1.Refresh();<BR> <LI> mapctrl.CallbackResults.CopyFrom(Toc1.CallbackResults);<BR> <LI> mapctrl.Refresh();<BR> <LI> CallbackButton7.CallbackResults.CopyFrom(mapctrl.CallbackResults);<BR> <LI> }</LI></OL></DIV><EM>复制代码</EM></DIV> <P><FONT face="新宋体 "><FONT style="FONT-SIZE: 9pt">以上为添加外部字段进行渲染的方法,附件中还有<FONT color=red>IMS组件</FONT>的渲染代码供参考!(区间渲染,单一值渲染)</FONT></FONT></FONT></FONT><BR><FONT face="新宋体 "><FONT size=4><FONT color=blue><FONT style="FONT-SIZE: 9pt">代码中</FONT></FONT></FONT></FONT><BR><FONT face="新宋体 "><FONT style="FONT-SIZE: 9pt"><FONT size=4><FONT color=blue> //添加字段,int型,名称YN<BR> System.Data.DataColumn dcol = new System.Data.DataColumn("YN", System.Type.GetType("System.Int32"));<BR> graphicslayer.Columns.Add(dcol);<BR><BR> //给字段赋值,这里可以将想渲染的字段加进来吧!!<BR> int i = 0;<BR> foreach (DataRow dd in graphicslayer.Rows)<BR> {<BR> dd["YN"] = i;<BR> i++;<BR> } <BR>为添加新字段用以渲染,字段的值就可以通过外部信息往里添加了,不论是XML的,还是DATASET等<BR></FONT></FONT><BR><FONT size=4><FONT color=magenta>PS:YOYO,这个GraphicsLayer很强大吧,很值得利用一下,记得你说从来不用这个的</FONT></FONT></FONT></FONT></P> <P><FONT face=新宋体 color=#ff00ff size=4>作者:<EM><FONT color=#000000>tianshen2330</FONT></EM></FONT></P> |
|
|