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;
}
}
}
ArcEngine加载在线地图天地图
最新推荐文章于 2024-03-21 16:16:34 发布