2013-05-03 11 views
0

在9.3的代碼,你可以只是做一個MapLayer.Layer得到FeatureLayer。 但在10.1.1中,他們將FeatureLayer更改爲FeatureSource,並從MapLayer中移除了Layer屬性。你如何從一個MapLayer在FeatureSource ESRI移動10.1.1

這裏的舊代碼,別人寫的,我升級:

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; 
    } 

回答

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; 
    } 
相關問題