0

在 9.3 代码中,您只需执行 MapLayer.Layer 即可获得 FeatureLayer。但在 10.1.1 中,他们将 FeatureLayer 更改为 FeatureSource 并从 MapLayer 中删除了 Layer 属性。

这是别人写的我正在升级的旧代码:

static public MapLayer FindMapLayer(string sLayerName, Map theMap)
    {
        MapLayer lyr = null;
        try
        {
            lyr = theMap.MapLayers[sLayerName];
        }
        catch { }
        return lyr;
    }

static public FeatureLayer FindFeatureLayer(string sLayerName, Map theMap)
    {
        FeatureLayer featLyr = null;
        MapLayer lyr = FindMapLayer(sLayerName, theMap);
        if (lyr != null)
        {
            featLyr = lyr.Layer;
        }
        return featLyr;
    }
4

1 回答 1

0

我想到了。您必须查看 mobilecache.FeatureSources 集合。名称将与您在 MXD 中命名 LAYER 的名称(您在目录中看到的确切字符串)匹配,您在 ArcGIS Server 中作为服务发布。

    public static FeatureSource FindFeatureLayer(string featureSourceName, Map theMap)
    {
        //TODO: this may not work if the feature source name doesn't match the map layer name!
        FeatureSource featSource = null;
        //10.1.1
        //Just grab the first map layer in order to get at the mobile cache and its
        // collection of feature sources.
        MobileCacheMapLayer cacheMapLayer = GetMobileCacheLayer(theMap);
        if (cacheMapLayer != null)
        {
            featSource = cacheMapLayer.MobileCache.FeatureSources[featureSourceName];
        }

        return featSource;
    }

    public static MobileCacheMapLayer GetMobileCacheLayer(Map theMap)
    {
        foreach (var layer in theMap.MapLayers)
        {
            if(layer is MobileCacheMapLayer)
                return (MobileCacheMapLayer)layer;
        }
        return null;
    }
于 2013-09-27T15:32:25.047 回答