/// <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)
        {
            // add a new POI layer if needed
            MapLayer poiLayer = PoiLayer(m);
            if (poiLayer == null)
            {
                poiLayer = new MapLayer();
                m.Layers.Add(poiLayer);
            }

            // add a new overlay for the current pin
            var poiOverlay = new MapOverlay();
            poiOverlay.Content = pin;
            poiOverlay.GeoCoordinate = new GeoCoordinate(position.Latitude, position.Longitude);
            poiOverlay.PositionOrigin = pin.AnchorPoint;

            // add overlay to the layer
            poiLayer.Add(poiOverlay);
        }
예제 #2
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)
        {
            // add a new POI layer if needed
            MapLayer poiLayer = PoiLayer(m);

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

            // add a new overlay for the current pin
            var poiOverlay = new MapOverlay();

            poiOverlay.Content        = pin;
            poiOverlay.GeoCoordinate  = new GeoCoordinate(position.Latitude, position.Longitude);
            poiOverlay.PositionOrigin = pin.AnchorPoint;

            // add overlay to the layer
            poiLayer.Add(poiOverlay);
        }
        /// <summary>
        /// Synchronizes changes to the ApiViewModel's Results collection. The elements of that collection are assumed
        /// to implement IMappable (see the APIMASH_TomTom.TomTomCameraViewModel implementation for a sample reference).
        /// This code should require no changed regardless as long as the items in the Results collection implement IMappable.
        /// </summary>
        void Results_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
             // 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.Tap += async (s, e2) =>
                        {
                            TheMap.HighlightPointOfInterestPin(DefaultViewModel.SelectedItem, false);
                            TheMap.HighlightPointOfInterestPin(poiPin.PointOfInterest, true);

                            await ProcessSelectedItem(item);
                        };

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

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

                // case NotifyCollectionChangedAction.Remove:    
                //
                // TODO: (optional) if your application allows items to be selectively removed from the view model
                //       code to remove a single associated push pin will be required.
                //
                //
                //
                // break;


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