天厚地宽无限美,怎么可与你相比......

我们的故事不能忘,太多的回忆和希望,不管它有多疯狂,我们的故事不能忘,太多的情节要发展.....

 

9.2不使用editortask的编辑,以一小段加点和加属性为例


using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
using ESRI.ArcGIS.ADF.ArcGISServer;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.Server;
using System.Collections;
using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;
using ESRI.ArcGIS.ADF.Resources;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using ESRI.ArcGIS.Utility;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.ADF.Web.Geometry;
using ESRI.ArcGIS.Editor;
using System.Configuration;
using System.Web.Security;
/// <summary>
///江西省地矿测绘院...草样年华测试
/// Modifity 的摘要说明
/// </summary>
public class Modifity:IMapServerToolAction
{
    void IMapServerToolAction.ServerAction(ToolEventArgs args)
{
        //创建server上下文
        //IServerContext mapContext = this.getServerContext();
        //使用server上下文来定义地图服务
        //IMapServer mapserver = mapContext.ServerObject as MapServer;
        //获得地图服务信息
        //IMapServerInfo mapInfo = mapserver.GetServerInfo(mapserver.DefaultMapName);
        //获得地图描述信息
        //IMapDescription mapDesc = mapInfo.DefaultMapDescription;
        PointEventArgs myargs = (PointEventArgs)args;
        System.Drawing.Point screenPoint = myargs.ScreenPoint;
        ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;
        ESRI.ArcGIS.ADF.Web.Geometry.Point mappnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screenPoint, mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);
        ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass();
        //ESRI.ArcGIS.Geometry.IPoint pPoint = mapContext.CreateObject("esriGeometry.Point") as IPoint;
        //pPoint.X = mappnt.X;
        //pPoint.Y = mappnt.Y;
        point.X = mappnt.X;
        point.Y = mappnt.Y;
        ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)mapctrl.GetFunctionality(0);
        ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = mf.Resource;
        ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
      
      //  ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal ags_mapresourcelocal =(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)ags_mapfunctionality.Resource;
       // ESRI.ArcGIS.Geometry.IPoint com_point = (ESRI.ArcGIS.Geometry.IPoint)ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToIGeometry(adf_point,ags_mapresourcelocal.ServerContextInfo.ServerContext);
        if(qfunc.Resource is ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)
        {
        MapResourceItem mri = mapctrl.MapResourceManagerInstance.ResourceItems[0];
        MapResourceLocal mr = (MapResourceLocal)mri.Resource;
        ESRI.ArcGIS.Server.IServerContext serverContext = null;
        //ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.ServerContextInfo my = mr.ServerContextInfo.ServerContext;
        serverContext = mr.ServerContextInfo.ServerContext;
        ESRI.ArcGIS.Geometry.IPoint mypoint = (ESRI.ArcGIS.Geometry.IPoint)ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToIGeometry(mappnt, serverContext);
        IMapServerObjects mso = (IMapServerObjects)mr.MapServer;
        ILayer layer = mso.get_Layer(mr.MapServer.DefaultMapName, 0);
        IFeatureLayer fl = (IFeatureLayer)layer;
        IDataset dataset = fl.FeatureClass as IDataset;
        IWorkspace workspace = dataset.Workspace;
        IWorkspaceEdit wse = dataset.Workspace as IWorkspaceEdit;
        wse.StartEditing(false);
        wse.StartEditOperation();
        IFeatureClass featureclass = fl.FeatureClass as IFeatureClass;
        IFeature feature = featureclass.CreateFeature();
        feature.Shape = mypoint as IGeometry;
        feature.set_Value(feature.Fields.FindField("TEXTSTRING"), "ztf");  
        feature.Store();
        wse.StopEditOperation();
        wse.StopEditing(true);
        mapctrl.Refresh();
        }
}
//以下的是无效代码
    private IServerContext getServerContext()
    {
        string servername = "localhost";
        string mapserverobject = "test";
        IServerObjectManager serverManager;
            // *** Using Web ADF Common API
            ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection gisconnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection();
            gisconnection.Host = servername;
            gisconnection.Connect();
            serverManager = gisconnection.ServerObjectManager;
        // *** Change the map server object name as needed
        IServerContext mapContext = serverManager.CreateServerContext(mapserverobject, "MapServer");
        return mapContext;
    }
}

注意这个是写到shp文件(sde数据也是没有问题的,如果要多用户编辑,可能没有加版本编辑)里的,请大家对照例子里的那个addpr什么来着加到custom临时层的例子看,可能理解更深点

posted on 2007-10-22 16:19  草样年华........  阅读(829)  评论(1编辑  收藏  举报

导航