Represents a child of a map, which uses geographic coordinates to position itself.
コード例 #1
0
        /// <summary>
        /// Implements the RemoveItemInternal from the parent class.
        /// Will take the object and remove the target item from the Map.Layers collection
        /// </summary>
        /// <param name="obj">Object to be removed</param>
        protected override void RemoveItemInternal(DependencyObject obj)
        {
            bool mappingContainsObject;

            mappingContainsObject = this.ObjectToMapLayerMapping.ContainsKey(obj);

            Debug.Assert(mappingContainsObject, "It is expected that there is a mapping for the object");

            if (mappingContainsObject)
            {
                MapLayer mapLayer;

                mapLayer = this.ObjectToMapLayerMapping[obj];
                this.ObjectToMapLayerMapping.Remove(obj);
                this.Map.Layers.Remove(mapLayer);

                if (!(obj is MapItemsControl))
                {
                    Debug.Assert(mapLayer.Count == 1, "Expected that the map overlay once created is still there");
                }

                // Clear the bindings in the map overlays.
                foreach (MapOverlay mapOverlay in mapLayer)
                {
                    MapChild.ClearMapOverlayBindings(mapOverlay);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Takes the target object and create the corresponding MapLayer that will be used
        /// to host in MapOverlays all the items provided.
        /// </summary>
        /// <param name="obj">Object from the source collection to be processed</param>
        /// <returns>The MapLayer that will be used to host the items from the source</returns>
        /// <remarks>
        /// It only supports two types of objects 1) MapItemsControl or 2) anything else.
        /// For MapItemsControls, the creation of the MapOverlays will be deferred to the MapItemsControl
        /// </remarks>
        private static MapLayer GetMapLayerForObject(object obj)
        {
            MapLayer        mapLayer;
            MapItemsControl mapItemsControl;

            // Only to types of objects supported per se.
            // 1) MapItemsControl
            // 2) Everything else
            mapItemsControl = obj as MapItemsControl;

            if (mapItemsControl != null)
            {
                // MapsItemsControl does their own control of creation of MapOverlays
                // because by the time we are here, items may be there already.
                // For that reason, we only bring the MapLayer an add it.
                mapLayer = mapItemsControl.MapLayer;

                Debug.Assert(mapLayer.Count == mapItemsControl.Items.Count, "MapLayer and MapItemsControl.Items count should match");
            }
            else
            {
                // Only 1 element. Create MapOverlay and insert
                mapLayer = new MapLayer();
                MapOverlay mapOverlay;

                mapOverlay = MapChild.CreateMapOverlay(obj, null);

                mapLayer.Add(mapOverlay);
            }

            return(mapLayer);
        }
コード例 #3
0
        /// <summary>
        /// Resets the target collection and internal state
        /// </summary>
        protected override void ResetInternal()
        {
            foreach (MapOverlay mapOverlay in this.MapLayer)
            {
                MapChild.ClearMapOverlayBindings(mapOverlay);
            }

            this.MapLayer.Clear();
            this.ObjectToMapOverlayMapping.Clear();
        }
コード例 #4
0
        /// <summary>
        /// Inserts the item at the specified index in the target collection
        /// </summary>
        /// <param name="index">Index at which object will be inserted</param>
        /// <param name="obj">Object to be inserted</param>
        protected override void InsertItemInternal(int index, object obj)
        {
            MapOverlay mapOverlay;

            if (this.ObjectToMapOverlayMapping.ContainsKey(obj))
            {
                throw new InvalidOperationException("Attempted to insert the same object twice");
            }

            mapOverlay = MapChild.CreateMapOverlay(obj, this.ItemTemplate);

            this.MapLayer.Insert(index, mapOverlay);
            this.ObjectToMapOverlayMapping.Add(obj, mapOverlay);
        }
コード例 #5
0
        /// <summary>
        /// Implements the behavior the target collection will have when the source is reset
        /// </summary>
        protected override void ResetInternal()
        {
            // The source collection has changed drastically enough.
            // Clear all the MapOverlay bindings.
            foreach (MapLayer mapLayer in this.Map.Layers)
            {
                foreach (MapOverlay mapOverlay in mapLayer)
                {
                    MapChild.ClearMapOverlayBindings(mapOverlay);
                }
            }

            this.Map.Layers.Clear();
            this.ObjectToMapLayerMapping.Clear();
        }
コード例 #6
0
        /// <summary>
        /// Remove the specified item from the target collection
        /// </summary>
        /// <param name="obj">Object to be removed</param>
        protected override void RemoveItemInternal(object obj)
        {
            bool mappingContainsObject;

            mappingContainsObject = this.ObjectToMapOverlayMapping.ContainsKey(obj);

            Debug.Assert(mappingContainsObject, "expected to have a mapping for the object");

            if (mappingContainsObject)
            {
                MapOverlay mapOverlay;

                mapOverlay = this.ObjectToMapOverlayMapping[obj];
                this.ObjectToMapOverlayMapping.Remove(obj);
                this.MapLayer.Remove(mapOverlay);

                MapChild.ClearMapOverlayBindings(mapOverlay);
            }
        }
コード例 #7
0
        /// <summary>
        /// Will handle the item template change
        /// </summary>
        /// <param name="d">DependencyObject that triggers the event.</param>
        /// <param name="e">Event args</param>
        private static void OnItemTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MapItemsControl mapsItemControl;
            DataTemplate    dataTemplate;

            mapsItemControl = (MapItemsControl)d;
            dataTemplate    = (DataTemplate)e.NewValue;

            mapsItemControl.ItemsChangeManager.ItemTemplate = dataTemplate;

            foreach (MapOverlay mapOverlay in mapsItemControl.MapLayer)
            {
                // New template, so there will be a new ui element created
                MapChild.ClearMapOverlayBindings(mapOverlay);

                MapOverlayItem mapOverlayPresenterHelper = (MapOverlayItem)mapOverlay.Content;
                mapOverlayPresenterHelper.ContentTemplate = dataTemplate;
            }
        }
コード例 #8
0
ファイル: MapOverlayItem.cs プロジェクト: wingc-china/wpaudio
        /// <summary>
        /// OnApplyTemplate override.
        /// Will take care of binding the dependency properties.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            MapChild.BindMapOverlayProperties(this.MapOverlay);
        }