Beispiel #1
0
        protected override void OnClick()
        {
            IMxDocument pmxdoc    = (IMxDocument)ArcMap.Application.Document;
            IMap        pmap      = pmxdoc.FocusMap;
            IGxDialog   pGxDialog = new GxDialog();

            pGxDialog.Title = "Browse Data";
            //pGxDialog.set_StartingLocation("C:\\Temp");
            pGxDialog.set_StartingLocation("GIS Servers");
            IEnumGxObject pEnumGx;

            if (!pGxDialog.DoModalOpen(0, out pEnumGx))
            {
                return;  // Exit if user press Cancel
            }
            IGxObject                pgxobject               = pEnumGx.Next();
            IGxAGSObject             gxAGSObject             = pgxobject as IGxAGSObject;
            IAGSServerObjectName     agsServerObjectName     = gxAGSObject.AGSServerObjectName;
            IAGSServerConnectionName agsServerConnectionName = agsServerObjectName.AGSServerConnectionName;
            IPropertySet             propertySet             = agsServerConnectionName.ConnectionProperties;
            //create a new ArcGIS Server connection factory
            IAGSServerConnectionFactory2 agsServerConnectionFactory2 = (IAGSServerConnectionFactory2) new AGSServerConnectionFactory();
            IAGSServerConnection         agsServerConnection         = agsServerConnectionFactory2.Open(propertySet, 0);
            //get an enum of all server object names from the server (GIS services, i.e.)
            IAGSEnumServerObjectName soNames        = agsServerConnection.ServerObjectNames;
            IAGSServerObjectName3    soName         = (IAGSServerObjectName3)soNames.Next();
            ILayerFactory            msLayerFactory = new MapServerLayerFactory();
            IEnumLayer      enumLyrs       = msLayerFactory.Create(soName);
            IMapServerLayer mapServerLayer = (IMapServerLayer)enumLyrs.Next();

            pmap.AddLayer((ILayer)mapServerLayer);

            ArcMap.Application.CurrentTool = null;
        }
        protected override void OnClick()
        {
             IMxDocument pmxdoc = (IMxDocument)ArcMap.Application.Document;
             IMap pmap = pmxdoc.FocusMap;
             IGxDialog pGxDialog = new GxDialog();
             pGxDialog.Title = "Browse Data";
             //pGxDialog.set_StartingLocation("C:\\Temp");
             pGxDialog.set_StartingLocation("GIS Servers");
             IEnumGxObject pEnumGx;
             if (!pGxDialog.DoModalOpen(0, out pEnumGx))
                 return; // Exit if user press Cancel
             IGxObject pgxobject = pEnumGx.Next();
             IGxAGSObject gxAGSObject = pgxobject as IGxAGSObject;
             IAGSServerObjectName agsServerObjectName = gxAGSObject.AGSServerObjectName;
             IAGSServerConnectionName agsServerConnectionName = agsServerObjectName.AGSServerConnectionName;
             IPropertySet propertySet = agsServerConnectionName.ConnectionProperties;
             //create a new ArcGIS Server connection factory
             IAGSServerConnectionFactory2 agsServerConnectionFactory2 = (IAGSServerConnectionFactory2)new AGSServerConnectionFactory();
             IAGSServerConnection agsServerConnection = agsServerConnectionFactory2.Open(propertySet, 0);
             //get an enum of all server object names from the server (GIS services, i.e.)
             IAGSEnumServerObjectName soNames = agsServerConnection.ServerObjectNames;
             IAGSServerObjectName3 soName = (IAGSServerObjectName3)soNames.Next();
             ILayerFactory msLayerFactory = new MapServerLayerFactory();
             IEnumLayer enumLyrs = msLayerFactory.Create(soName);
             IMapServerLayer mapServerLayer = (IMapServerLayer)enumLyrs.Next();
             pmap.AddLayer((ILayer)mapServerLayer);

             ArcMap.Application.CurrentTool = null;
        }
Beispiel #3
0
        public static string BrowseSaveRaster(string formTitle, IntPtr hParentWindowHandle, string sWorkspace = null, string sName = null)
        {
            IGxDialog pGxDialog = new GxDialog();
            IGxObjectFilterCollection pFilterCol = (IGxObjectFilterCollection)pGxDialog;

            pFilterCol.AddFilter(new GxFilterRasterDatasets(), true);
            pGxDialog.RememberLocation = true;
            pGxDialog.AllowMultiSelect = false;
            pGxDialog.Title            = formTitle;
            if (!string.IsNullOrEmpty(sWorkspace))
            {
                pGxDialog.set_StartingLocation(sWorkspace);
            }

            if (sWorkspace is string)
            {
                sWorkspace = string.Empty;
            }

            if (sName is string)
            {
                sName = string.Empty;
            }

            string sResult = string.Empty;

            try
            {
                if (pGxDialog.DoModalSave(hParentWindowHandle.ToInt32()))
                {
                    sWorkspace = pGxDialog.FinalLocation.FullName;
                    sName      = pGxDialog.Name;
                    sResult    = System.IO.Path.Combine(sWorkspace, sName);
                }
            }
            catch (Exception ex)
            {
                ex.Data["Title"]  = formTitle;
                ex.Data["Folder"] = sWorkspace;
                ex.Data["Name"]   = sName;
                throw;
            }

            return(sResult);
        }