Example #1
0
        /// <summary>
        /// Hides/shows point-of-interest pin
        /// </summary>
        /// <param name="item">Item associated with the point-of-interest pin</param>
        /// <param name="highlight">Flag indicating whether point-of-interest pin should be highlighted or unhighlighted</param>
        public static void HighlightPointOfInterestPin(this Map m, IMappable item, Boolean highlight)
        {
            MapLayer poiLayer = PoiLayer(m);

            if ((poiLayer != null) && (item != null))
            {
                // search for pin in the layer matching by id - some defensive programming here to not assume everything
                // in this layer is a point-of-interest pin (but it should be!)
                PointOfInterestPin poiPin = poiLayer.Children.Where((c) =>
                {
                    var p = c as PointOfInterestPin;
                    return((p != null) && (p.PointOfInterest.Id == item.Id));
                }).FirstOrDefault() as PointOfInterestPin;

                // if pin is found
                if (poiPin != null)
                {
                    // set highlight appropriately
                    poiPin.IsHighlighted = highlight;

                    // if it's highlighted, bring to top by removing and adding back in
                    if (highlight)
                    {
                        poiLayer.Children.Remove(poiPin);
                        poiLayer.Children.Add(poiPin);
                    }
                }
            }
        }
        /// <summary>
        /// Adds point-of-interest pin to designated location
        /// </summary>
        /// <param name="pin">Point-of-interest pin instance</param>
        /// <param name="position">Latitude/longitude for pin placement</param>
        public static void AddPointOfInterestPin(this Map m, PointOfInterestPin pin, LatLong position)
        {
            MapLayer poiLayer = PoiLayer(m);
            if (poiLayer == null)
            {
                poiLayer = new MapLayer();
                m.Children.Add(poiLayer);
            }

            MapLayer.SetPositionAnchor(pin, pin.AnchorPoint);

            MapLayer.SetPosition(pin, new Location(position.Latitude, position.Longitude));
            poiLayer.Children.Add(pin);
        }
Example #3
0
        /// <summary>
        /// Adds point-of-interest pin to designated location
        /// </summary>
        /// <param name="pin">Point-of-interest pin instance</param>
        /// <param name="position">Latitude/longitude for pin placement</param>
        public static void AddPointOfInterestPin(this Map m, PointOfInterestPin pin, LatLong position)
        {
            MapLayer poiLayer = PoiLayer(m);

            if (poiLayer == null)
            {
                poiLayer = new MapLayer();
                m.Children.Add(poiLayer);
            }

            MapLayer.SetPositionAnchor(pin, pin.AnchorPoint);

            MapLayer.SetPosition(pin, new Location(position.Latitude, position.Longitude));
            poiLayer.Children.Add(pin);
        }
Example #4
0
        // synchronize changes in the view model collection with the map push pins
        void Results_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // the synchronization requires a reference to a Bing.Maps object on the Main page
            if (Map == null)
                throw new System.NullReferenceException("An instance of Bing.Maps is required here, yet the Map property was found to be null.");

            // only additions and wholesale reset of the ObservableCollection are currently supported
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    foreach (var item in e.NewItems)
                    {
                        IMappable mapItem = (IMappable)item;

                        PointOfInterestPin poiPin = new PointOfInterestPin(mapItem);
                        poiPin.Selected += (s2, e2) =>
                        {
                            MappableListView.SelectedItem = MappableListView.Items.Where((c) => (c as IMappable).Id == e2.PointOfInterest.Id).FirstOrDefault();
                        };
                        poiPin.Tapped += (s3, e3) => { e3.Handled = true; };

                        Map.AddPointOfInterestPin(poiPin, mapItem.Position);
                    }
                    break;

                case NotifyCollectionChangedAction.Reset:
                    Map.ClearPointOfInterestPins();
                    break;

                // not implemented in this context
                // case NotifyCollectionChangesAction.Remove:
                // case NotifyCollectionChangedAction.Replace:
                // case NotifyCollectionChangedAction.Move:
            }
        }