private void btnOpenMapServer_Click(object sender, EventArgs e)
{
try
{
//加载进度条
//Progressor.ShowProgressDialog(0, 10000, "Load MapServer ... ");
//连接服务器
IAGSServerConnectionFactory pAGSServerConnFactory = new AGSServerConnectionFactoryClass();
IAGSServerConnection pAGSServerConn = new AGSServerConnectionClass();
IPropertySet pPropSet = new PropertySetClass();
//url = url + "/" + tokenVale;
pPropSet.SetProperty("url", "http://192.168.0.187:6080/arcgis/rest/services");
pPropSet.SetProperty("USER", "");
pPropSet.SetProperty("PASSWORD", "");
pAGSServerConn = pAGSServerConnFactory.Open(pPropSet, 0);
if (pAGSServerConn == null)
return;
//获取所有server服务
IAGSEnumServerObjectName pAGSEnumServerObjName = pAGSServerConn.ServerObjectNames;
if (pAGSEnumServerObjName == null)
return;
pAGSEnumServerObjName.Reset();
//具体某个server服务
IAGSServerObjectName pAGSServerObjName = new AGSServerObjectNameClass();
pAGSServerObjName = pAGSEnumServerObjName.Next();
IMapServer pMapServer = null;
while (pAGSServerObjName.Name != null)
{
//查找制定名称的server服务AllVector
if (pAGSServerObjName.Name == "HKGX/MMDW" && pAGSServerObjName.Type == "MapServer")
{
IName pName = pAGSServerObjName as IName;
pMapServer = pName.Open() as IMapServer;
//获取该server服务的所有服务信息
IMapServerInfo pMapServerInfo = new MapServerInfoClass();
pMapServerInfo = pMapServer.GetServerInfo(pMapServer.DefaultMapName);
//获取该server服务下的所有图层信息
IMapLayerInfos pMapLayerInfos = new MapLayerInfosClass();
pMapLayerInfos = pMapServerInfo.MapLayerInfos;
for (int infocount = 0; infocount < pMapLayerInfos.Count; infocount++)
{
IMapLayerInfo pMapLayerInfo1 = pMapLayerInfos.get_Element(infocount);
IMapLayerInfo2 pMapLayerInfo2 = (IMapLayerInfo2)pMapLayerInfo1;
IMapServerLayer pMapServer1 = pMapLayerInfo2 as IMapServerLayer;//null
}
//获取某个图层信息
IMapLayerInfo pMapLayerInfo = pMapLayerInfos.get_Element(0);
if (pMapLayerInfo.IsFeatureLayer == true)
{
IFeatureLayer pfealayer = pMapLayerInfo as IFeatureLayer;//null
//IMapServer pMapServer = pMapLayerInfo as IMapServer;//null
//axMapControl1.AddLayer(player);
}
//图层
IMapServerLayer pMapServerLayer = new MapServerLayerClass();
pMapServerLayer.ServerConnect(pAGSServerObjName, pMapServer.DefaultMapName);
//必须
IMapDescription pMapDesc = pMapServerInfo.DefaultMapDescription;
ImageDisplayClass imageDisplay = new ImageDisplayClass();
imageDisplay.Width = 600;
imageDisplay.Height = 480;
IMapServerFindResults pMapServerFindResults = pMapServer.Find(pMapDesc, imageDisplay, "路", true, "NAME", esriFindOption.esriFindAllLayers, null);
IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;//null
//IMap pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);
//IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
ICompositeLayer pCompositeLayer = pMapServerLayer as ICompositeLayer;
ILayer pLayer = pCompositeLayer.get_Layer(0);
// axMapControl1.AddLayer(pCompositeLayer as ILayer);
//
// pLayer.Visible = true;
// ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = pLayer.AreaOfInterest;
// axMapControl1.ActiveView.Extent = pEnvelope;
// axMapControl1.ActiveView.Refresh();
//
// axMapControl1.Refresh();
//结束进度条
//Progressor.AbortProgressDialog();
break;
}
pAGSServerObjName = pAGSEnumServerObjName.Next();
}
}
catch (System.Exception ex)
{
}
}