去年写的server9.2编辑工具条代码,现在贴出来

it2022-05-05  123

protected void Toolbar2_CommandClick(object sender, ToolbarCommandClickEventArgs args)     {         switch (args.CommandName)         {             case "deletePolygon":                 ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapCtrl;                 mapCtrl =Map1;                 MapFunctionality mapFunc = (MapFunctionality)mapCtrl.GetFunctionality(0);                 MapResourceLocal mapResLocal = mapFunc.Resource as MapResourceLocal;                 ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesc;                 mapDesc = mapFunc.MapDescription;                 IServerContext pSOC;                 IMapServer pMapServer;                 IMap pMap;                 pSOC = mapResLocal.ServerContextInfo.ServerContext;                 pMapServer = pSOC.ServerObject as IMapServer;                 IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;                 pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);                 ILayer pLayer = pMap.get_Layer(1);                 IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;                 IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;                 IDataset pDataset = pFeatCls as IDataset;                 IWorkspace pWS = pDataset.Workspace;                 IWorkspaceEdit pWorkspaceEdit = pWS as IWorkspaceEdit;                 pWorkspaceEdit.StartEditing(false);                 pWorkspaceEdit.StartEditOperation();                 //IFeatureBuffer pFeatureBuffer;                 //IFeatureCursor pFeatureCuror;                 IFeature pFeature;                 ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription featureLayer = mapDesc.LayerDescriptions[1];                // pFeature = featureLayer.SelectionFeatures[0];                 //pFeatureCuror = pFeatCls.GetFeature(featureLayer.SelectionFeatures[0]);                // pFeature=pFeatureCuror.NextFeature();                 pFeature = pFeatCls.GetFeature(featureLayer.SelectionFeatures[0]);                 pFeature.Delete();                 pWorkspaceEdit.StopEditOperation();                 pWorkspaceEdit.StopEditing(true);                 mapCtrl.Refresh();                 break;             case "back":                 zoomback();                 break;             case "forward":                 zoomforward();                 break;         }     }

前后视图

private ArrayList ExtentList = new ArrayList();     private ArrayList m_extenthistory;     private ESRI.ArcGIS.ADF.Web.Geometry.Envelope m_lastextent;     private bool isPooled = false;     internal const int MAXIMUM_EXTENT_HISTORY_COUNT = 10; //地图视图改变     protected void Map1_ExtentChanged(object sender, ExtentEventArgs args)     {         m_extenthistory = Session["extenthistory"] as ArrayList;         int index = 0;         if (Session["index"] != null)         {             index = (int)Session["index"];         }         if (m_extenthistory == null)         {             m_extenthistory = new ArrayList();         }         if (m_extenthistory.Count >= MAXIMUM_EXTENT_HISTORY_COUNT)             m_extenthistory.RemoveAt(0);         m_extenthistory.Add(Map1.Extent);         index++;         if (index == m_extenthistory.Count)         {             index = m_extenthistory.Count - 1;         }         // Add extent history and index to Session         Session.Add("index", index);         Session.Add("extenthistory", m_extenthistory);         m_lastextent = Map1.Extent as ESRI.ArcGIS.ADF.Web.Geometry.Envelope;         UpdateViewerSessionObjects();     }     private void UpdateViewerSessionObjects()     {         Session.Add("Map1_CurrentExtent", this.Map1.Extent);     }     //前一视图     public void zoomback()     {         int index = 0;         if (Session["index"] != null) index = (int)Session["index"];         m_extenthistory = Session["extenthistory"] as ArrayList;         if (m_extenthistory == null)             return;         index--;         if (index < 0)             index = 0;         ESRI.ArcGIS.ADF.Web.Geometry.Envelope myencelope = m_extenthistory[index] as ESRI.ArcGIS.ADF.Web.Geometry.Envelope;         this.Map1.Extent = myencelope;         this.Map1.Refresh();         Session["index"] = index;         UpdateViewerSessionObjects();     }     //后一视图     public void zoomforward()     {         int index = 0;         if (Session["index"] != null) index = (int)Session["index"];         m_extenthistory = Session["extenthistory"] as ArrayList;         if (m_extenthistory == null)             return;         index++;         if (index == m_extenthistory.Count)             index = m_extenthistory.Count - 1;         ESRI.ArcGIS.ADF.Web.Geometry.Envelope myencelope = m_extenthistory[index] as ESRI.ArcGIS.ADF.Web.Geometry.Envelope;         this.Map1.Extent = myencelope;         this.Map1.Refresh();         Session["index"] = index;         UpdateViewerSessionObjects();     } 选中 using System; using System.Data; using System.Configuration; using System.Web; using System.Collections.Generic; using System.Text; using System.Collections; //引用arcgis类 using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools; using ESRI.ArcGIS.ADF.Web.UI.WebControls; using ESRI.ArcGIS.ADF.Web.DataSources; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using ESRI.ArcGIS.ADF.ArcGISServer; /// <summary> /// selectPolygon 的摘要说明 /// </summary> public class selectPolygon : IMapServerToolAction { public selectPolygon() {   //   // TODO: 在此处添加构造函数逻辑   // }     void IMapServerToolAction.ServerAction(ToolEventArgs args)     {         int resource_index = 0;         ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;         //按名称取得图层         string sourcelayername = "房屋层";         ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)mapctrl.GetFunctionality(resource_index);         ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = mf.Resource;         RectangleEventArgs rectargs = (RectangleEventArgs)args;         System.Drawing.Rectangle myrect = rectargs.ScreenExtent;         ESRI.ArcGIS.ADF.Web.Geometry.Point minpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Left, myrect.Bottom, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);         ESRI.ArcGIS.ADF.Web.Geometry.Point maxpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Right, myrect.Top, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);         //ESRI.ArcGIS.ADF.Web.Geometry.Point minpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Left, myrect.Bottom, mapctrl.Extent, mf.DisplaySettings.ImageDescriptor.Width, mf.DisplaySettings.ImageDescriptor.Height);         //ESRI.ArcGIS.ADF.Web.Geometry.Point maxpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Right, myrect.Top, mapctrl.Extent, mf.DisplaySettings.ImageDescriptor.Width, mf.DisplaySettings.ImageDescriptor.Height);         ESRI.ArcGIS.ADF.Web.Geometry.Envelope mappoly = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpnt, maxpnt);         bool supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));         if (supported)         {             ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality 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);             int layer_index = 0;             for (int i = 0; i < lnames.Length; i++)             {                 if (lnames == sourcelayername)                 {                     if (lids is string)                     {                         if (!int.TryParse((string)lids, out layer_index))                             layer_index = i;                     }                     else                     {                         layer_index = i;                     }                     break;                 }             }             if (qfunc.Resource is ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)             {                 ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)mf;                 ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase ags_mr = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase)qfunc.Resource;                 ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapdescription;                 mapdescription = ags_mf.MapDescription;                 LayerDescription[] layerdescs = mapdescription.LayerDescriptions;                 MapLayerInfo[] mli = ags_mr.MapServerInfo.MapLayerInfos;                 LayerDescription featureLayer = layerdescs[layer_index];                 if (featureLayer == null)                 {                     // 图层为空                     throw new Exception("featurelayer null");                 }                 else                 {                     EnvelopeN envelopen = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfEnvelope(mappoly);                     SpatialFilter sf = new SpatialFilter();                     sf.FilterGeometry = envelopen;                     sf.GeometryFieldName = "SHAPE";                     sf.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;                     MapServerProxy msdp = ags_mr.MapServerProxy;                     RgbColor irgbc = new RgbColor();                     irgbc.Red = 250;                     irgbc.Green = 250;                     irgbc.Blue = 0;                     irgbc.AlphaValue = 255;                     featureLayer.SelectionColor = irgbc;                     FIDSet ifid = msdp.QueryFeatureIDs(mapdescription.Name, featureLayer.LayerID, sf);                     featureLayer.SelectionFeatures = ifid.FIDArray;                     args.Control.Page.Session.Add("fid", ifid.FIDArray[0].ToString().Trim());                     mapctrl.Refresh();                 }             }         }     } } 分割 using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; //引用arcgis类 using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools; using ESRI.ArcGIS.ADF.Web.UI.WebControls; using ESRI.ArcGIS.ADF.ArcGISServer; using ESRI.ArcGIS.Server; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Display; using System.Collections; using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.ADF.Web; using ESRI.ArcGIS.ADF.Web.DataSources; using ESRI.ArcGIS.ADF.Web.Geometry; using ESRI.ArcGIS.ADF.Web.Display.Graphics; using System.Collections.Generic; /// <summary> /// splitPolygon 的摘要说明 /// </summary> public class splitPolygon:IMapServerToolAction { public splitPolygon() {   //   // TODO: 在此处添加构造函数逻辑   // }     void IMapServerToolAction.ServerAction(ToolEventArgs args)     {         //取得所画屏幕线的点集         ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapCtrl = args.Control as ESRI.ArcGIS.ADF.Web.UI.WebControls.Map;         PolylineEventArgs peag = (PolylineEventArgs)args;         System.Drawing.Point[] screen_points = peag.Vectors;         //定义地图参数         MapFunctionality mapFunc = (MapFunctionality)mapCtrl.GetFunctionality(0);         MapResourceLocal mapResLocal = mapFunc.Resource as MapResourceLocal;         ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesc;         mapDesc = mapFunc.MapDescription;         IServerContext pSOC;         IMapServer pMapServer;         IMap pMap;         pSOC = mapResLocal.ServerContextInfo.ServerContext;         pMapServer = pSOC.ServerObject as IMapServer;         IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;         pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);         //转化屏幕线为地图线         IPointCollection pPointColl;         pPointColl = (IPointCollection)pSOC.CreateObject("esriGeometry.Polyline");         for (int i = 0; i < screen_points.Length; i++)         {             IPoint pPoint;             ESRI.ArcGIS.ADF.Web.Geometry.Point mappnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points, mapCtrl.Extent, (int)mapCtrl.Width.Value, (int)mapCtrl.Height.Value);             pPoint = (IPoint)pSOC.CreateObject("esriGeometry.Point");             pPoint.X = mappnt.X;             pPoint.Y = mappnt.Y;             object missingVal = System.Reflection.Missing.Value;             pPointColl.AddPoint(pPoint, ref missingVal, ref missingVal);         }         IGeometry pPolylineGeo = pPointColl as IGeometry;         //取得要分割的feature         IFeatureLayer featurelayer = pMap.get_Layer(1) as IFeatureLayer;         IFeatureClass featureclass = featurelayer.FeatureClass;         IFeature feature = featureclass.GetFeature(Convert.ToInt32(args.Control.Page.Session["fid"].ToString().Trim()));         //打开工作空间         IDataset pDataset = featureclass as IDataset;         IWorkspace pWS = pDataset.Workspace;         IWorkspaceEdit pWorkspaceEdit = pWS as IWorkspaceEdit;         pWorkspaceEdit.StartEditing(false);         pWorkspaceEdit.StartEditOperation();         //开始分割         ESRI.ArcGIS.Geometry.ITopologicalOperator tt;         tt = feature.Shape as ESRI.ArcGIS.Geometry.ITopologicalOperator;         IGeometry t1, t2;         t1 = pSOC.CreateObject("esriGeometry.Polygon") as IGeometry;         t2 = pSOC.CreateObject("esriGeometry.Polygon") as IGeometry;         IPolyline pline =pSOC.CreateObject("esriGeometry.Polyline") as IPolyline;         pline = pPolylineGeo as IPolyline;         tt.Cut(pline,out t1, out t2);         feature.Shape = t1;         IFeature feature2 = featureclass.CreateFeature();         feature2.Shape = t2;                //保存分割结果及刷新地图         feature.Store();         feature2.Store();         pWorkspaceEdit.StopEditOperation();         pWorkspaceEdit.StopEditing(true);         mapCtrl.Refresh();       } } 合并 using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; //引用arcgis类 using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools; using ESRI.ArcGIS.ADF.Web.UI.WebControls; using ESRI.ArcGIS.ADF.ArcGISServer; using ESRI.ArcGIS.Server; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Display; using System.Collections; using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.ADF.Web; using ESRI.ArcGIS.ADF.Web.DataSources; using ESRI.ArcGIS.ADF.Web.Geometry; using ESRI.ArcGIS.ADF.Web.Display.Graphics; using System.Collections.Generic; /// <summary> /// unionPolygon 的摘要说明 /// </summary> public class unionPolygon : IMapServerToolAction { public unionPolygon() {   //   // TODO: 在此处添加构造函数逻辑   // }     void IMapServerToolAction.ServerAction(ToolEventArgs args)     {         //取屏幕点         ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapCtrl;         mapCtrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;         PointEventArgs peag = (PointEventArgs)args;         System.Drawing.Point screen_point = peag.ScreenPoint;         //定义地图参数         MapFunctionality mapFunc = (MapFunctionality)mapCtrl.GetFunctionality(0);         MapResourceLocal mapResLocal = mapFunc.Resource as MapResourceLocal;         ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesc;         mapDesc = mapFunc.MapDescription;         IServerContext pSOC;         IMapServer pMapServer;         IMap pMap;         pSOC = mapResLocal.ServerContextInfo.ServerContext;         pMapServer = pSOC.ServerObject as IMapServer;         IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;         pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);         //转屏幕点到地图点         IPoint pPoint;         ESRI.ArcGIS.ADF.Web.Geometry.Point mappnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_point, mapCtrl.Extent, (int)mapCtrl.Width.Value, (int)mapCtrl.Height.Value);         pPoint = (IPoint)pSOC.CreateObject("esriGeometry.Point");         pPoint.X = mappnt.X;         pPoint.Y = mappnt.Y;         //另外一种转换方法         ESRI.ArcGIS.ADF.Web.Geometry.Point mapPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_point.X, screen_point.Y, mapCtrl.GetTransformationParams(TransformationDirection.ToMap));         IdentifyOption m_idOption = IdentifyOption.VisibleLayers;         IGISResource resource;         IQueryFunctionality query;         string[] layerIds;         string[] layerNames;                  resource = mapFunc.Resource;         query = resource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), "select") as IQueryFunctionality;         query.GetQueryableLayers(null, out layerIds, out layerNames);         //根据fid查找另外一个feature         DataTable[] ds=null;         ds = query.Identify(mapFunc.Name, mapPoint, 5, m_idOption, null);         string my="";         if (ds.Length < 2)         {             my = ds[0].Rows[0]["OBJECTID"].ToString().Trim();         }         ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase ags_mr = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase)mapFunc.Resource;         MapServerProxy msdp = ags_mr.MapServerProxy;         ESRI.ArcGIS.ADF.ArcGISServer.SpatialFilter sf = new ESRI.ArcGIS.ADF.ArcGISServer.SpatialFilter();         sf.GeometryFieldName = "SHAPE";         sf.WhereClause = "OBJECTID = '" + my + "'";         sf.SpatialRel = ESRI.ArcGIS.ADF.ArcGISServer.esriSpatialRelEnum.esriSpatialRelIntersects;         ESRI.ArcGIS.ADF.ArcGISServer.FIDSet fidset = msdp.QueryFeatureIDs(mapDesc.Name,1,sf);         //取得原来选中的feature         int selected_fid = Convert.ToInt32(args.Control.Page.Session["fid"].ToString().Trim());         IFeatureLayer featurelayer = pMap.get_Layer(1) as IFeatureLayer;         IFeatureClass featureclass = featurelayer.FeatureClass;         //打开工作空间         IDataset pDataset = featureclass as IDataset;         IWorkspace pWS = pDataset.Workspace;         IWorkspaceEdit pWorkspaceEdit = pWS as IWorkspaceEdit;         pWorkspaceEdit.StartEditing(false);         pWorkspaceEdit.StartEditOperation();         //开始合并         IFeature feature1 = featureclass.GetFeature(Convert.ToInt32(my));         IFeature feature2 = featureclass.GetFeature(selected_fid);                  ESRI.ArcGIS.Geometry.IPolygon un1,un2;         un1 = feature1.Shape as ESRI.ArcGIS.Geometry.IPolygon;         if (un1.SpatialReference == null)         {             un1.SpatialReference = mapCtrl.SpatialReference as ISpatialReference;         }         un2 = feature2.Shape as ESRI.ArcGIS.Geometry.IPolygon;         if (un2.SpatialReference == null)         {             un2.SpatialReference = mapCtrl.SpatialReference as ISpatialReference;         }         un1.Project(feature2.Shape.SpatialReference);         un1.SnapToSpatialReference();         un2.SnapToSpatialReference();                ESRI.ArcGIS.Geometry.ITopologicalOperator tt=un1 as ESRI.ArcGIS.Geometry.ITopologicalOperator;         try         {             feature1.Shape = tt.Union((IGeometry)un2) as IGeometry;         }         catch         {             args.Control.Page.Response.Write("不能合并");         }             feature1.Store();             feature2.Delete();             pWorkspaceEdit.StopEditOperation();             pWorkspaceEdit.StopEditing(true);             mapCtrl.Refresh();       } } 修改属性就不写了,只要选中feature,然后feature.setvalue()就好了

转载于:https://www.cnblogs.com/jamszeng/archive/2008/05/07/1187123.html

相关资源:各显卡算力对照表!

最新回复(0)