From 3e8ea29d5bcde3e63350cb51a9e77628b221f0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Luiz=20Gomes=20Coelho?= Date: Thu, 4 May 2017 22:00:01 -0300 Subject: [PATCH] Inclusion of the method that opens a callout without clicking on the marker. --- .../TKCustomMapRenderer.cs | 17 ++++++++++++ .../TKCustomMapRenderer.cs | 26 +++++++++++++++++++ TK.CustomMap/TK.CustomMap/TKCustomMapPin.cs | 9 +++++++ 3 files changed, 52 insertions(+) diff --git a/TK.CustomMap/TK.CustomMap.Android/TKCustomMapRenderer.cs b/TK.CustomMap/TK.CustomMap.Android/TKCustomMapRenderer.cs index 13ea8d0..ce06a1c 100644 --- a/TK.CustomMap/TK.CustomMap.Android/TKCustomMapRenderer.cs +++ b/TK.CustomMap/TK.CustomMap.Android/TKCustomMapRenderer.cs @@ -261,6 +261,21 @@ private void OnMarkerClick(object sender, GoogleMap.MarkerClickEventArgs e) } } /// + /// Show Infowindow when OpenCallout is True + /// + /// + private void OpenCallOut(Marker marker) + { + if (this.FormsMap == null) return; + var item = this._markers.SingleOrDefault(i => i.Value.Id.Equals(marker.Id)); + if (item.Key == null) return; + + if (item.Key.ShowCallout) + { + item.Value.ShowInfoWindow(); + } + } + /// /// When a drag of a marker ends /// /// Event Sender @@ -515,6 +530,8 @@ private async void AddPin(TKCustomMapPin pin) } this._markers.Add(pin, this._googleMap.AddMarker(markerWithIcon)); + + this.OpenCallOut(this._googleMap.AddMarker(markerWithIcon)); } /// /// Remove a pin from the map and the internal dictionary diff --git a/TK.CustomMap/TK.CustomMap.iOSUnified/TKCustomMapRenderer.cs b/TK.CustomMap/TK.CustomMap.iOSUnified/TKCustomMapRenderer.cs index 6aadc3a..bf14d2b 100644 --- a/TK.CustomMap/TK.CustomMap.iOSUnified/TKCustomMapRenderer.cs +++ b/TK.CustomMap/TK.CustomMap.iOSUnified/TKCustomMapRenderer.cs @@ -520,6 +520,7 @@ private void UpdatePins(bool firstUpdate = true) { i.PropertyChanged -= OnPinPropertyChanged; this.AddPin(i); + this.OpenCallOut(i); } if (firstUpdate) @@ -533,6 +534,31 @@ private void UpdatePins(bool firstUpdate = true) this.MapFunctions.RaisePinsReady(); } /// + /// Show Infowindow when OpenCallout is True + /// + /// + private void OpenCallOut(TKCustomMapPin pin) + { + MKAnnotationViewEventArgs e; + if (pin == null) return; + + this._selectedAnnotation = new TKCustomMapAnnotation(pin); + this.FormsMap.SelectedPin = pin; + + if (pin.OpenCallout) + { + var selectedAnnotation = this.Map.Annotations + .OfType() + .SingleOrDefault(i => i.CustomPin.Equals(pin)); + + if (selectedAnnotation != null) + { + this._selectedAnnotation = selectedAnnotation; + this.Map.SelectAnnotation(selectedAnnotation, true); + } + } + } + /// /// Creates the lines /// private void UpdateLines(bool firstUpdate = true) diff --git a/TK.CustomMap/TK.CustomMap/TKCustomMapPin.cs b/TK.CustomMap/TK.CustomMap/TKCustomMapPin.cs index ead3779..2d0bd40 100644 --- a/TK.CustomMap/TK.CustomMap/TKCustomMapPin.cs +++ b/TK.CustomMap/TK.CustomMap/TKCustomMapPin.cs @@ -13,6 +13,7 @@ public class TKCustomMapPin : TKBase private string _title; private string _subtitle; private bool _showCallout; + private bool _openCallout; private Position _position; private ImageSource _image; private bool _isDraggable; @@ -75,6 +76,14 @@ public bool ShowCallout set { this.SetField(ref this._showCallout, value); } } /// + /// Gets/Sets open the callout without clicked marker + /// + public bool OpenShowCallout + { + get { return this._openCallout; } + set { this.SetField(ref this._openCallout, value); } + } + /// /// Gets/Sets the position of the pin /// public Position Position