ESRI.ArcGIS.Client.Toolkit.MapLayerItem.Refresh C# (CSharp) Méthode

Refresh() private méthode

Refreshes the legend from infos coming from the map layer.
private Refresh ( ) : void
Résultat void
		internal void Refresh()
		{
			if (_isQuerying || Layer == null)
				return; // already querying

			if (!(Layer is GroupLayerBase)) // GroupLayer : don't wait for layer intialized, so the user will see the layer hierarchy even if the group layer is not initialized yet (else would need to wait for all sublayers initialized)
			{
				if (!Layer.IsInitialized) 
				{
					IsBusy = true; // set busy indicator waiting for layer initialized
					return; // Refresh will be done on event Initialized
				}

				LayerItems = null;
			}
			LegendItems = null;

			var simplifiedLegendSupport = new SimplifiedLegendSupport(Layer);
			var legendSupport = LayerItemsOptions.ReturnLegendItems == false && simplifiedLegendSupport.IsSupported ? simplifiedLegendSupport : Layer as ILegendSupport;
			if (legendSupport != null)
			{
				IsBusy = true;
				_isQuerying = true;

				Action queryLegendInfosAction = delegate()
				{
					legendSupport.QueryLegendInfos(
						// callback
						(result) =>
						{
							if (LegendTree == null)
							{
								// The legend item has been detached ==> result no more needed
								IsBusy = _isQuerying = false;
								return;
							}

							if (result != null)
							{
								Description = result.LayerDescription;
								if (string.IsNullOrEmpty(Label)) // Label is set with LayerID : keep it if not null
									Label = result.LayerName;

								Map map = LegendTree.Map;

								// Convert scale to resolution
								maxServiceResolution = result.MinimumScale == 0.0 ? double.PositiveInfinity : ConvertToResolution(result.MinimumScale, map);
								minServiceResolution = ConvertToResolution(result.MaximumScale, map);

								// Combine Layer and Service resolution
								MinimumResolution = Math.Max(Layer.MinimumResolution, minServiceResolution);
								MaximumResolution = Math.Min(Layer.MaximumResolution, maxServiceResolution);

								IsHidden = result.IsHidden;

								if (result.LayerLegendInfos != null)
								{
									LayerItems = result.LayerLegendInfos.Select(info => new LayerItemViewModel(Layer, info, Description, map)).ToObservableCollection();
								}

								if (result.LegendItemInfos != null)
								{
									LegendItems = result.LegendItemInfos.Select(info => new LegendItemViewModel(info)).ToObservableCollection();
								}
							}

							// If groupLayer -> add the child layers 
							AddGroupChildLayers();

							// Kml layer particular case : if a KML layer has only a child which is not another KML layer ==> set the child item as transparent so it doesn't appear in the legend
							ProcessKmlLayer();

							LegendTree.UpdateLayerVisibilities();
							_isQuerying = false;
							// Fire event Refreshed without exception
							LegendTree.OnRefreshed(this, new Legend.RefreshedEventArgs(this, null));

							if (_dispatcher != null)
								_dispatcher.BeginInvoke(new Action(() => IsBusy = false));
							else
								IsBusy = false;
						},

						// errorCallback
						(ex) =>
						{
							// Fire event Refreshed with an exception
							if (LegendTree != null)
								LegendTree.OnRefreshed(this, new Legend.RefreshedEventArgs(this, ex));

							_isQuerying = false;
							IsBusy = false;
						}
					);
				};

				if (_dispatcher != null)
					_dispatcher.BeginInvoke(queryLegendInfosAction);
				else
					queryLegendInfosAction();
			}
			else
			{
				IsBusy = false;
				MinimumResolution = Layer.MinimumResolution;
				MaximumResolution = Layer.MaximumResolution;
				// Fire event Refreshed
				if (LegendTree != null)
					LegendTree.OnRefreshed(this, new Legend.RefreshedEventArgs(this, null));

			}
		}
		

Usage Example

		private void AddGroupChildLayers()
		{
			if (Layer is GroupLayerBase)
			{
				ObservableCollection<LayerItemViewModel> mapLayerItems = new ObservableCollection<LayerItemViewModel>();
				if ((Layer as GroupLayerBase).ChildLayers != null)
				{
					foreach (Layer layer in (Layer as GroupLayerBase).ChildLayers.Where(l => l.ShowLegend))
					{
						Layer layerToFind = layer;
						MapLayerItem mapLayerItem = LayerItems == null ? null : LayerItems.FirstOrDefault(item => item.Layer == layerToFind) as MapLayerItem;

						if (mapLayerItem == null || mapLayerItems.Contains(mapLayerItem)) // else reuse existing map layer item to avoid querying again the legend and lose the item states (note : contains test if for the degenerated case where a layer is twice or more in a group layer)
						{
							// Create a new map layer item
							mapLayerItem = new MapLayerItem(layer) { LegendTree = this.LegendTree, LayerItemsOptions = LegendTree.LayerItemsOptions};
							if (_dispatcher != null)
								_dispatcher.BeginInvoke(new Action(() => mapLayerItem.Refresh()));
							else
								mapLayerItem.Refresh();
						}
						mapLayerItems.Add(mapLayerItem);
					}
				}
				LayerItems = mapLayerItems;
#if !SILVERLIGHT
				// Don't display the AcceleratedDisplayLayers root node
				if (Layer is AcceleratedDisplayLayers)
					IsTransparent = true;
#endif
			}
		}
All Usage Examples Of ESRI.ArcGIS.Client.Toolkit.MapLayerItem::Refresh