Пример #1
0
        // TODO: If we're setting an icon's state to PointerOver, maybe make sure it's the only icon in a PointerOver state?
        // Hope that's not too slow.
        // Maybe keep a list of all icons currently in a PointerOver state...
        public void SetIconState(Guid iconId, MapIconState iconState)
        {
            MapIcon matchingIcon = DigiTransitMapControl.MapElements
                                   .OfType <MapIcon>()
                                   .FirstOrDefault(x => (Guid)x.GetValue(PoiIdProperty) == iconId);

            if (matchingIcon == null)
            {
                return;
            }

            // The MapIconChanged callback in the Attached Property handles Image changing on State changes. See MapElementExtensions.cs.
            matchingIcon.SetValue(MapIconStateProperty, iconState);


            // Only allow one icon to be highlighted at at time by external callers.
            if (iconState != MapIconState.None)
            {
                foreach (MapIcon activeIcon in DigiTransitMapControl.MapElements.
                         OfType <MapIcon>()
                         .Where(x => (MapIconState)x.GetValue(MapIconStateProperty) != MapIconState.None &&
                                (Guid)x.GetValue(PoiIdProperty) != iconId))
                {
                    activeIcon.SetValue(MapIconStateProperty, MapIconState.None);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Converts a Point object into a MapIcon
        /// </summary>
        /// <param name="point">A Point object</param>
        /// <returns>A MapIcon object</returns>
        public static MapIcon ToBMGeometry(this Point point)
        {
            var pushpin = new MapIcon()
            {
                Location = new Geopoint(point.Coordinate.ToBMGeometry())
            };

            pushpin.SetValue(MapElementExt.TagProperty, point.Metadata);

            return(pushpin);
        }
Пример #3
0
        private void DigiTransitMapControl_MapElementPointerExited(MapControl sender, MapElementPointerExitedEventArgs args)
        {
            MapIcon icon = args.MapElement as MapIcon;

            if (icon == null)
            {
                return;
            }

            if ((MapIconState)icon.GetValue(MapIconStateProperty) == MapIconState.PointerOver)
            {
                // The MapIconChanged callback in the Attached Property handles Image changing on State changes. See MapElementExtensions.cs.
                icon.SetValue(MapIconStateProperty, MapIconState.None);
            }
        }
Пример #4
0
        private async void OnPlacesCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            if (args.Action == NotifyCollectionChangedAction.Move)
            {
                return;
            }
            if (args.Action == NotifyCollectionChangedAction.Reset)
            {
                SetMapIcons(null);
            }

            if (args.NewItems != null)
            {
                var newIcons = new List <MapIcon>();
                foreach (IMapPoi place in args.NewItems.OfType <IMapPoi>())
                {
                    var element = new MapIcon();
                    element.Image = RandomAccessStreamReference.CreateFromStream(await _themeIconSource);
                    element.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
                    element.Location = new Geopoint(place.Coords);
                    element.Title    = place.Name;
                    element.NormalizedAnchorPoint = new Point(0.5, 1.0);
                    element.SetValue(PoiIdProperty, place.Id);
                    MapElementExtensions.SetPoiId(element, place.Id);
                    newIcons.Add(element);
                }
                AddMapIcons(newIcons);
            }

            if (args.OldItems != null)
            {
                var removedIcons = new List <MapIcon>();
                foreach (IMapPoi place in args.OldItems.OfType <IMapPoi>())
                {
                    var removedIcon = DigiTransitMapControl.MapElements
                                      .OfType <MapIcon>()
                                      .FirstOrDefault(x => x.Location.Position.Equals(place.Coords));
                    removedIcons.Add(removedIcon);
                }
                RemoveMapIcons(removedIcons);
            }
        }