2011-03-23 93 views
1

我想添加一个从ArcGIS Server地图服务创建的ILayer到ArcObjects的IMap,但不知道如何去做。如何从ArcGIS地图服务创建ArcMap图层

我正在一个IMapServer3用下面的代码,其中,mapname =地图服务:

serverContext = som.CreateServerContext(mapName, "MapServer"); 
IServerObject serverObject = serverContext.ServerObject; 
IMapServer3 mapServer = (IMapServer3)serverObject; 

它看起来像我可以从一个IMapServerGroupLayer的iLayer的,但它看起来像IMapServerGroupLayer正在寻找不同于我使用的连接类型。

如果您有一个从地图服务中获得ILayer的例子,我们非常感谢您的帮助。

回答

1

这是什么工作?

private static void GetLayerFromMapServerLayer() 
{ 

IAGSServerConnectionName servConnName = new AGSServerConnectionNameClass(); 
IPropertySet props = new PropertySetClass(); 
props.SetProperty("machine", "server"); 
servConnName.ConnectionProperties = props; 



IAGSServerConnectionFactory pAGSServerConnectionFactory = new AGSServerConnectionFactoryClass(); 
IAGSServerConnection pAGSConnection = pAGSServerConnectionFactory.Open(props, 0); 



IAGSEnumServerObjectName pEnumSOName = pAGSConnection.ServerObjectNames; 

IAGSServerObjectName pSOName = pEnumSOName.Next(); 

while (pSOName != null) 
{ 
if (pSOName.Name == "Base_Map") 
break; 
pSOName = pEnumSOName.Next(); 
} 

IName pName = (IName)pSOName; 
IMapServer mapServer = (IMapServer)pName.Open(); 

IMapServerLayer msLyr = new MapServerLayerClass(); 
msLyr.ServerConnect(pSOName, mapServer.DefaultMapName); 

IMapServerGroupLayer group = (IMapServerGroupLayer)msLyr; 

ILayer msLayer = (ILayer)msLyr; 

//return msLayer; 
MapDocument mapDoc = new MapDocumentClass(); 
mapDoc.Open(@"F:\~mkoneya~2011_82_13_58_30.mxd"); 
IMap myMap = mapDoc.get_Map(0); 
myMap.AddLayer(msLayer); 
mapDoc.Save(); 
} 
+0

很高兴见到你解决你的问题!不要忘了点击左边的复选标记来标记答案。 – 2011-03-24 21:03:57

相关问题