Exemple #1
0
 /// <summary>
 /// Determines the map units for the map
 /// </summary>
 /// <param name="map">The map to find map units for</param>
 /// <param name="callback">The method to invoke once map units have been retrieved</param>
 /// <param name="failedCallback">The method to invoke when map unit retrieval fails</param>
 public static void GetMapUnitsAsync(this Map Map, Action <MapUnit> callback,
                                     Action <object, ExceptionEventArgs> failedCallback = null)
 {
     if (Map != null)
     {
         Layer layer = Map.Layers.FirstOrDefault();
         if (layer != null)
         {
             ESRI.ArcGIS.Client.Bing.TileLayer tiledLayer = layer as ESRI.ArcGIS.Client.Bing.TileLayer;
             if (tiledLayer != null)
             {
                 // Bing is web mercator
                 callback(Core.DataSources.MapUnit.Meters);
             }
             else
             {
                 ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer osmLayer = layer as ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer;
                 if (osmLayer != null)
                 {
                     // Open Streem map is web mercator
                     callback(Core.DataSources.MapUnit.Meters);
                 }
                 else
                 {
                     // ArcGIS Server Base Map
                     string layerUrl = null;
                     ArcGISTiledMapServiceLayer agsTiledlayer = layer as ArcGISTiledMapServiceLayer;
                     if (agsTiledlayer != null)
                     {
                         layerUrl = agsTiledlayer.Url;
                     }
                     else
                     {
                         ArcGISDynamicMapServiceLayer agsDynamicLayer = layer as ArcGISDynamicMapServiceLayer;
                         if (agsDynamicLayer != null)
                         {
                             layerUrl = agsDynamicLayer.Url;
                         }
                         else
                         {
                             ArcGISImageServiceLayer agsImageLayer = layer as ArcGISImageServiceLayer;
                             if (agsImageLayer != null)
                             {
                                 layerUrl = agsImageLayer.Url;
                             }
                         }
                     }
                     if (!string.IsNullOrWhiteSpace(layerUrl))
                     {
                         DataSourceProvider agsDataSource = new DataSourceProvider();
                         IBaseMapDataSource dataSource    = agsDataSource.CreateDataSourceForBaseMapType(BaseMapType.ArcGISServer) as IBaseMapDataSource;
                         dataSource.GetMapServiceMetaDataCompleted += (o, args) =>
                         {
                             callback(args.MapUnit);
                         };
                         dataSource.GetMapServiceMetaDataFailed += (o, args) =>
                         {
                             if (failedCallback != null)
                             {
                                 failedCallback(Map, args);
                             }
                         };
                         dataSource.GetMapServiceMetaDataAsync(layerUrl, null);
                         return;
                     }
                 }
             }
         }
     }
 }