Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Legend"/> class.
 /// </summary>
 public Legend()
 {
     DefaultStyleKey = typeof(Legend);
     _legendTree = new LegendTree();
     _legendTree.Refreshed += OnRefreshed;
     _legendTree.PropertyChanged += LegendTree_PropertyChanged;
 }
		//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)
		//			{
		//				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 };
		//					if (_dispatcher != null)
		//						_dispatcher.BeginInvoke(new Action(() => mapLayerItem.Refresh()));
		//					else
		//						mapLayerItem.Refresh();
		//				}
		//				mapLayerItems.Add(mapLayerItem);
		//			}
		//		}
		//		LayerItems = mapLayerItems;

		//		// Don't display the AcceleratedDisplayLayers root node
		//		if (Layer is AcceleratedDisplayLayers)
		//			IsTransparent = true;
		//	}
		//}

		//// KML Layer 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
		//private void ProcessKmlLayer()
		//{
		//	// Must be a group layer (KmlLayer inherits from GroupLayer)
		//	if (!(Layer is GroupLayer))
		//		return;

		//	// Must have only one child
		//	LayerCollection layers = (Layer as GroupLayer).ChildLayers;
		//	if (layers == null || layers.Count() != 1)
		//		return;

		//	// The child must not be a KMLLayer i.e. not a group layer (sub folder and sub document must not be removed from the legend)
		//	Layer childLayer = layers.FirstOrDefault();
		//	if (childLayer is GroupLayer)
		//		return;

		//	// The layer must be a KmlLayer
		//	if (!IsKmlLayer())
		//		return;

		//	// Set the child as transparent
		//	LayerItemViewModel childLayerItem = LayerItems == null ? null : LayerItems.FirstOrDefault();
		//	if (childLayerItem != null)
		//		childLayerItem.IsTransparent = true;
		//}

		// check that the layer inherits from kmllayer by using name in order to avoid a reference to DataSources project
		//private bool IsKmlLayer()
		//{
		//	Type type = Layer.GetType();
		//	while (type != null)
		//	{
		//		if ( type.Name == "KmlLayer")
		//			return true;
		//		type = type.BaseType;
		//	}
		//	return false;
		//}

		#endregion

		#region Attach/Detach

		internal override void Attach(LegendTree legendTree)
		{
			if (legendTree == null)
				return;

			base.Attach(legendTree);

			AttachLayerEventHandler(Layer);
		}