在adf 中渲染SQL中的点数据

    技术2022-05-19  21

    Adf 支持Graphic渲染,GraphicLayer 又有两种类型,分别为FeatureLayer 和 Elementlayer。

    以下就两种方式的渲染如下:(其中它们各用了一种写法,两种写法都可以)

    Elementlayer:

    else if (eventArg == "ShouGeInfo22") //收割信息 { string LayerName = m_queryString["LayerName"]; string OjectID = m_queryString["ObjectID"]; string PointLayerName = m_queryString["PointLayerName"]; string TianName = m_queryString["TianName"]; string sql = "select * from " + PointLayerName + " where polt_id='" + TianName + "'"; Plot plot = new Plot(); DataTable dt = plot.GetPlotInformationJoin(sql); / ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource Resource1; ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality mf = Map1.GetFunctionality("Graphics"); Resource1 = mf.Resource as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource; Resource1.Graphics.Clear(); //创建或获得已经有的临时高亮图层ElementGraphicsLayer,这种图层可以同时容纳点、线、面多种类型 ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer layer = null; for (int i = 0; i < dt.Rows.Count; i++) { ESRI.ArcGIS.ADF.Web.Geometry.Point adfStarPoint = new ESRI.ArcGIS.ADF.Web.Geometry.Point(Convert.ToDouble(dt.Rows[i]["x"]), Convert.ToDouble(dt.Rows[i]["y"])); if (Resource1.Graphics.Tables.Count == 0) { layer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer(); layer.TableName = "Graphics"; Resource1.Graphics.Tables.Add(layer); } else { layer = Resource1.Graphics.Tables[0] as ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer; } //将临时图元“点”加入ElementGraphicsLayer ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement elementPoint = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(adfStarPoint, System.Drawing.Color.Brown); elementPoint.Symbol.Transparency = 0.5; layer.Add(elementPoint); } //保存查询信息,方便Identify点查询 Session["TianName"] = TianName; Session["PointLayerName"] = PointLayerName; ESRICommon Sc = new ESRICommon(this.Page, this.Map1); Session["IsNongTian"] = "0"; //Sc.LocationByID_NoHightLight(LayerName, OjectID); //ViewRegionOrPointByVML(); //地图定位到该点 // Map1.CenterAt(adfStarPoint); //因为数据源发生了变化,必须刷新MAP对象 Map1.Refresh(); //返回前台 response = Map1.CallbackResults.ToString(); }

     

    FeatureLayer:

    else if (eventArg == "ShouGeInfo") //收割信息 { string LayerName = m_queryString["LayerName"]; string OjectID = m_queryString["ObjectID"]; string PointLayerName = m_queryString["PointLayerName"]; string TianName = m_queryString["TianName"]; string pyear = PointLayerName; string sql = "select * from ShougeInfo where polt_id='" + TianName + "' and pyear= '" + pyear + "'"; Plot plot = new Plot(); DataTable dt = plot.GetPlotInformationJoin(sql); if (dt == null) { //加入用户自定义JS反馈 ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult callbackResult; callbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript("alert('" + PointLayerName + "收割信息表不存在,请导入!')"); Map1.CallbackResults.Add(callbackResult); response = Map1.CallbackResults.ToString(); } else if (dt.Rows.Count == 0) { //加入用户自定义JS反馈 ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult callbackResult; callbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript("alert('没有符合要求的收割信息!')"); Map1.CallbackResults.Add(callbackResult); response = Map1.CallbackResults.ToString(); } else { / ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource Resource1; ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality mf = Map1.GetFunctionality("Graphics"); Resource1 = mf.Resource as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource; Resource1.Graphics.Clear(); //创建或获得已经有的临时高亮图层ElementGraphicsLayer,这种图层可以同时容纳点、线、面多种类型 ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer fglayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer(); ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol fs = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol(); fs.Color = System.Drawing.Color.Brown; fs.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Circle; fs.Width = 6; ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer sr = new ESRI.ArcGIS.ADF.Web.Display.Renderer.SimpleRenderer(fs); //fglayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer)dt; double xAxes = Convert.ToDouble(ConfigurationManager.AppSettings["xAxes"]); double yAxes = Convert.ToDouble(ConfigurationManager.AppSettings["yAxes"]); for (int i = 0; i < dt.Rows.Count; i++) { ESRI.ArcGIS.ADF.Web.Geometry.Point adfStarPoint = new ESRI.ArcGIS.ADF.Web.Geometry.Point(Convert.ToDouble(dt.Rows[i]["x"]) + xAxes, Convert.ToDouble(dt.Rows[i]["y"]) + yAxes); fglayer.Renderer = sr; fglayer.Add(adfStarPoint); } Resource1.Graphics.Tables.Add(fglayer); //保存查询信息,方便Identify点查询 Session["TianName"] = TianName; Session["PointLayerName"] = PointLayerName; ESRICommon Sc = new ESRICommon(this.Page, this.Map1); Session["IsNongTian"] = "0"; Sc.LocationByID_NoHightLight(LayerName, OjectID); ViewRegionOrPointByVML(); //地图定位到该点 // Map1.CenterAt(adfStarPoint); //因为数据源发生了变化,必须刷新MAP对象 Map1.Refresh(); //返回前台 response = Map1.CallbackResults.ToString(); } }


    最新回复(0)