ArcEngine在地图上加载Server图层数据

例:加载服务地址"http://services.arcgisonline.com/ArcGIS/services"中的"ESRI_Imagery_World_2D"数据对象(图层)到地图上。
 
private void GetServerTest()
        {
            //获得服务对象名称
            IAGSServerObjectName serverObjectName =GetMapServer(
                "http://services.arcgisonline.com/ArcGIS/services", "ESRI_Imagery_World_2D", false);
            IName pName = (IName)serverObjectName;
            //访问地图服务
            IAGSServerObject serverObject = (IAGSServerObject)pName.Open();
            IMapServer mapServer = (IMapServer)serverObject;
 
            IMapServerLayer mapServerLayer = new MapServerLayer() as IMapServerLayer;
            
            //连接地图服务
            mapServerLayer.ServerConnect(serverObjectName, mapServer.DefaultMapName);
            
            //添加数据图层
            _application.MapControl.AddLayer(mapServerLayer as ILayer);
            _application.MapControl.Refresh();
        } 
 
        public IAGSServerObjectName GetMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN)
        {        
            //设置连接属性
            IPropertySet propertySet = new PropertySetClass();
            if (pIsLAN)
                propertySet.SetProperty("machine", pHostOrUrl);
            else
                propertySet.SetProperty("url", pHostOrUrl);
 
            //打开连接
            IAGSServerConnectionFactory factory = new AGSServerConnectionFactory();            
            IAGSServerConnection pConnection = factory.Open(propertySet, 0);
 
            //Get the image server.
            IAGSEnumServerObjectName pServerObjectNames = pConnection.ServerObjectNames;
            pServerObjectNames.Reset();
            IAGSServerObjectName ServerObjectName = pServerObjectNames.Next();
            while (ServerObjectName != null)
            {
                if ((ServerObjectName.Name.ToLower() == pServiceName.ToLower()) 
                    && (ServerObjectName.Type == "MapServer") )
                {                    
                    break;
                }
                ServerObjectName = pServerObjectNames.Next();
            }
 
            return ServerObjectName;
        }

 

posted @ 2022-06-29 13:47  devgis  阅读(175)  评论(0编辑  收藏  举报