/// <summary> /// Handles the ProportyChanged event of map pin. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> with arguments of the event.</param> private void OnPinPropertyChanged(object sender, PropertyChangedEventArgs e) { // Get the pin and corresponding marker var pin = (MapExPin)sender; var marker = this.markers?.FirstOrDefault(m => m.Id.Equals((string)pin.InternalId)); if (marker == null) { // Remove event handler pin.PropertyChanged -= this.OnPinPropertyChanged; return; } // If pin label changed if (e.PropertyName == MapExPin.LabelProperty.PropertyName) { marker.Title = pin.Label; } // If the address property changed if (e.PropertyName == MapExPin.AddressProperty.PropertyName) { marker.Snippet = pin.Address; } // If the position changed if (e.PropertyName == MapExPin.PositionProperty.PropertyName) { marker.Position = new LatLng(pin.Position.Latitude, pin.Position.Longitude); } // If the type changed if (e.PropertyName == MapExPin.TypeProperty.PropertyName) { // Change the marker icon var icon = MapExRenderer.GetResourceId(pin.Type); marker.SetIcon(BitmapDescriptorFactory.FromResource(icon)); // If the marker info window is shown if (marker.IsInfoWindowShown) { marker.ShowInfoWindow(); } } }
/// <summary> /// Adds a pin to the current map. /// </summary> /// <param name="pin">A pin to add.</param> private void AddPin(MapExPin pin) { // If map is not present if (this.map == null) { return; } // Create a new marker collection if (this.markers == null) { this.markers = new List <Marker>(); } // Setup market options var markerOptions = new MarkerOptions(); markerOptions.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude)); markerOptions.Anchor(0.5f, 0.5f); markerOptions.SetTitle(pin.Label); markerOptions.SetSnippet(pin.Address); markerOptions.InfoWindowAnchor(0.5f, 0.5f); // Setup marker icon var icon = MapExRenderer.GetResourceId(pin.Type); markerOptions.SetIcon(BitmapDescriptorFactory.FromResource(icon)); // Add marker to the map var marker = this.map.AddMarker(markerOptions); this.markers.Add(marker); pin.InternalId = marker.Id; // Add event handlers pin.PropertyChanged += this.OnPinPropertyChanged; }