1

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

我得到一个带有以下代码的 IMapServer3,其中 mapName = 地图服务:

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

看起来我可以从 IMapServerGroupLayer 获得 ILayer,但看起来 IMapServerGroupLayer 正在寻找与我正在使用的连接类型不同的连接类型。

如果您有从地图服务获取 ILayer 的示例,我们将不胜感激。

4

1 回答 1

1

This is what worked...

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();
} 
于 2011-03-23T21:23:24.980 回答