Arcengine 加载地图服务(MapServer)

实现在winform窗体中,显示Arcserver发布的地图服务
 
        /// <summary>
        /// 加载地图服务
        /// </summary>
        /// <param name="serverName">服务器名称</param>
        /// <param name="serviceName">地图服务名称</param>
        /// <returns>返回的Layer加到地图控件中</returns>
        private ILayer LoadMapservice(string serverName, string serviceName)
        {           
            IMapServer m_mapServer = null;
            IMapServerLayer layer = null;

            IPropertySet propertySet = new PropertySet();
            propertySet.SetProperty("url", "http://"+serverName+"/arcgis/services");

            IAGSServerConnectionFactory agsServerConnectionFactory = new  AGSServerConnectionFactory();
            IAGSServerConnection agsServerConnection = agsServerConnectionFactory.Open(propertySet, 0);

            IAGSEnumServerObjectName agsEnumServerObjectName = agsServerConnection.ServerObjectNames;
            agsEnumServerObjectName.Reset();

            IName serverObjectName;
            IAGSServerObject agsServerObject = null;
            IAGSServerObjectName agsServerObjectName = agsEnumServerObjectName.Next();
            while ((agsServerObjectName != null))
            {


                // Search for the MapServer Server Object
                if (agsServerObjectName.Type.ToUpper() == "MAPSERVER" &&
                    agsServerObjectName.Name == serviceName)
                {
                    serverObjectName = agsServerObjectName as IName;
                    agsServerObject = serverObjectName.Open() as IAGSServerObject;
                    if (agsServerObject as IMapServer != null)
                    {
                        m_mapServer = agsServerObject as IMapServer;
                    }
                    break;
                }

                // If we got both of them, exit out
                if (m_mapServer != null)
                {
                    layer = new MapServerLayerClass();
                    layer.ServerConnect(agsServerObjectName, m_mapServer.DefaultMapName);
                }

                agsServerObjectName = agsEnumServerObjectName.Next();
            }
            if (layer != null)
            {
                return (layer as ILayer);
            }
            else
            {
                return null;
            }
            
        }

 

www.0855map.com 黔东南公众信息网

欢迎加入技术交流QQ群:186226657

posted @ 2012-04-18 10:47 千禧牛 阅读(...) 评论(...) 编辑 收藏