ArcEngine加载在线地图天地图

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.GISClient;
using ESRI.ArcGIS.esriSystem;

namespace TianDiTu
{
    class loadmap
    {
         /// <summary>
        /// 获取在线天地图图层
        /// </summary>  
        IWMTSLayer map = GetWMTSLayer("http://t0.tianditu.com/vec_c/wmts");
        IWMTSLayer mapMark = GetWMTSLayer("http://t0.tianditu.com/cva_c/wmts");
        axMapControl1.AddLayer(map as ILayer);
        axMapControl1.AddLayer(mapMark as ILayer);
        axMapControl1.Refresh();



        /// <summary>
        /// 获取在线ESRI图层
        /// </summary>
        IAGSServerObjectName pServerObjectName = GetMapServer("http://cache1.arcgisonline.cn/arcgis/rest/services", "ChinaOnlineCommunity", false);
        ESRI.ArcGIS.esriSystem.IName pName = (ESRI.ArcGIS.esriSystem.IName)pServerObjectName;
        //访问地图服务
        IAGSServerObject pServerObject = (IAGSServerObject)pName.Open();
        IMapServer pMapServer = (IMapServer)pServerObject;
        IMapServerLayer pMapServerLayer = new MapServerLayer() as IMapServerLayer;
        //连接地图服务
        pMapServerLayer.ServerConnect(pServerObjectName, pMapServer.DefaultMapName);
        //添加数据图层
        axMapControl1.AddLayer(pMapServerLayer as ILayer);
        axMapControl1.Refresh();

         /// <summary>
        /// 获取在线天地图图层
        /// </summary>  
        public IWMTSLayer GetWMTSLayer(string location)
        {
            try
            {
                IPropertySet pPropertyset = new PropertySet();
                pPropertyset.SetProperty("url", location);

                IWMTSConnectionFactory pwmtsconnectionfactory = new WMTSConnectionFactory();
                IWMTSConnection con = pwmtsconnectionfactory.Open(pPropertyset, 0, null);
                IWMTSLayer ly = new WMTSLayer();
                ESRI.ArcGIS.esriSystem.IName n = con.FullName;
                ly.Connect(n);

                return ly;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }


        }
        /// <summary>
        /// 获取在线ESRI图层
        /// </summary>
       public IAGSServerObjectName GetMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN)
       {
         

           //设置连接属性
           IPropertySet pPropertySet = new PropertySet();
           if (pIsLAN)
               pPropertySet.SetProperty("machine", pHostOrUrl);
           else
               pPropertySet.SetProperty("url", pHostOrUrl);

           //打开连接

           IAGSServerConnectionFactory pFactory = new AGSServerConnectionFactory();
           //Type factoryType = Type.GetTypeFromProgID(
           //   "esriGISClient.AGSServerConnectionFactory");
           //IAGSServerConnectionFactory agsFactory =(IAGSServerConnectionFactory)
           //   Activator.CreateInstance(factoryType);
           IAGSServerConnection pConnection = pFactory.Open(pPropertySet,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;
       }


    }
}

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值