2011-03-23 77 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