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;
        }
Beispiel #2
0
        private static IMapServerLayer GetArcGisServerGroupLayer(IAGSServerObjectName3 soName)
        {
            IMapServerLayer outLayer = null;
            var             factory  = new MapServerLayerFactory() as ILayerFactory;

            try
            {
                //create an enum of layers using the name object (will contain only a single layer)
                outLayer = factory.Create(soName).Next() as IMapServerLayer;
            }
            catch
            {
                throw;
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(factory);
            }
            return(outLayer);
        }
Beispiel #3
0
        private void loadLayers()
        {
            chbLayers.Items.Clear();
            Dictionary <string, bool> lyrDic = msUtil.getLayerDic(cmbCon.Text, cmbSrv.Text);

            if (lyrDic.Count < 1)
            {
                this.UseWaitCursor = true;
                IAGSServerConnection2    sConn    = msUtil.getServiceConnection(cmbCon.Text);
                Dictionary <string, int> lyrIdDic = new Dictionary <string, int>();
                string sType = msUtil.getServiceType(cmbCon.Text, cmbSrv.Text);
                IAGSServerObjectName3 sObj = msUtil.getServiceObject(sConn, cmbSrv.Text, sType);
                if (sType.ToLower() == "mapserver")
                {
                    IMapServer2 ms2 = msUtil.getMapService(sObj);
                    lyrIdDic = msUtil.getLayers(ms2);
                }
                else if (sType.ToLower() == "imageserver")
                {
                    IImageServer ims = msUtil.getIMageService(sObj);
                    lyrIdDic = msUtil.getImages(ims);
                }
                msUtil.updateLayerTable(lyrIdDic, cmbCon.Text, cmbSrv.Text);
                lyrDic             = msUtil.getLayerDic(cmbCon.Text, cmbSrv.Text);
                this.UseWaitCursor = false;
            }
            if (lyrDic.Count < 1)
            {
                MessageBox.Show("Can't find any layers that will allow users to download information. Setting server name to blank.");
                cmbSrv.Text = "";
            }
            else
            {
                foreach (KeyValuePair <string, bool> kvp in lyrDic)
                {
                    chbLayers.Items.Add(kvp.Key, kvp.Value);
                }
            }
        }
 private static ILayer GetLayer(IAGSServerObjectName3 objectName)
 {
     ILayerFactory msLayerFactory = new MapServerLayerFactory();
     IEnumLayer enumLyrs = msLayerFactory.Create(objectName);
     var mapServerLayer = (IMapServerLayer)enumLyrs.Next();
     if (mapServerLayer != null)
     {
         return (ILayer)mapServerLayer;
     }
     return null;
 }
 /// <summary>
 /// Return the map service given a sereverobject name
 /// </summary>
 /// <param name="sobj">server object</param>
 public IMapServer2 getMapService(IAGSServerObjectName3 sobj)
 {
     string typ = sobj.Type.ToLower();
     if (typ == "mapserver")
     {
         return (IMapServer2)((IName)sobj).Open();
     }
     else
     {
         return null;
     }
 }
 /// <summary>
 /// return an image server object given a serverobject name
 /// </summary>
 /// <param name="sobj">server object name</param>
 /// <returns></returns>
 public IImageServer getIMageService(IAGSServerObjectName3 sobj)
 {
     string typ = sobj.Type.ToLower();
     if (typ == "imageserver")
     {
         return (IImageServer)((IName)sobj).Open();
     }
     else
     {
         return null;
     }
 }