/// <summary>
 /// Updates the image of a pin
 /// </summary>
 /// <param name="pin">The forms pin</param>
 /// <param name="markerOptions">The native marker options</param>
 private async Task UpdateImage(TKCustomMapPin pin, MarkerOptions markerOptions)
 {
     BitmapDescriptor bitmap;
     try
     {
         if (pin.Image != null)
         {
             var icon = await new ImageLoaderSourceHandler().LoadImageAsync(pin.Image, this.Context);
             bitmap = BitmapDescriptorFactory.FromBitmap(icon);
         }
         else
         {
             if (pin.DefaultPinColor != Color.Default)
             {
                 bitmap = BitmapDescriptorFactory.DefaultMarker(pin.DefaultPinColor.ToAndroid().GetHue());
             }
             else
             {
                 bitmap = BitmapDescriptorFactory.DefaultMarker();
             }
         }
     }
     catch (Exception)
     {
         bitmap = BitmapDescriptorFactory.DefaultMarker();
     }
     markerOptions.SetIcon(bitmap);
 }
Beispiel #2
0
		public async void proceduralPolygonCall(Position pos){
			TKCustomMapPin addedPin = new TKCustomMapPin ();
			addedPin.IsDraggable = false;
			addedPin.IsVisible = true;
			addedPin.Image = "dot.png";
			addedPin.Position = pos;
			addedPin.ShowCallout = false;

			_pins.Add (addedPin);
			customAreaPolyPins.Add (addedPin);
			customAreaPolyPoints.Add (pos);

			if (customAreaPolyPoints.Count < 3) {
				return;
			} else {
				var action = await Application.Current.MainPage.DisplayActionSheet(							
					"Point Added",
					null,
					null,
					"Create Custom Area",
					"Add Another Point",
					"Delete Area");
				if (action == "Create Custom Area") {
					EIMAPolygon result = new EIMAPolygon ();
					result.Color = CONSTANTS.colorOptions[Array.IndexOf(CONSTANTS.dzTypeOptions, polyType)];

					result.Coordinates = customAreaPolyPoints;
					result.uid = CONSTANTS.generateUID();

					result.type = polyType;
					result.note = polyNote;
					_polygons.Add (result);

					creatingPolygon = false;
					customAreaPolyPoints = null;
					foreach (TKCustomMapPin element in customAreaPolyPins) {
						_pins.Remove (element);
					}
					customAreaPolyPins = null;
					saveData ();

				} else if (action == "Add Another Point") {
					return;
				} else if (action == "Delete Area") {
					creatingPolygon = false;
					customAreaPolyPoints = null;
					foreach (TKCustomMapPin element in customAreaPolyPins) {
						_pins.Remove (element);
					}
					customAreaPolyPins = null;
				}
			}
		}
        /// <summary>
        /// Adds a marker to the map
        /// </summary>
        /// <param name="pin">The Forms Pin</param>
        private async void AddPin(TKCustomMapPin pin)
        {
            var markerWithIcon = new MarkerOptions();
            markerWithIcon.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));

            if (!string.IsNullOrWhiteSpace(pin.Title))
                markerWithIcon.SetTitle(pin.Title);
            if (!string.IsNullOrWhiteSpace(pin.Subtitle))
                markerWithIcon.SetSnippet(pin.Subtitle);

            await this.UpdateImage(pin, markerWithIcon);
            markerWithIcon.Draggable(pin.IsDraggable);
            markerWithIcon.Visible(pin.IsVisible);

            this._markers.Add(pin, this._googleMap.AddMarker(markerWithIcon));
        }
        /// <summary>
        /// Remove a pin from the map and the internal dictionary
        /// </summary>
        /// <param name="pin">The pin to remove</param>
        private void RemovePin(TKCustomMapPin pin)
        {
            var item = this._markers[pin];
            if(item == null) return;

            if (this._selectedMarker != null)
            {
                if (item.Id.Equals(this._selectedMarker.Id))
                {
                    this.FormsMap.SelectedPin = null;
                }
            }

            item.Remove();
            pin.PropertyChanged -= OnPinPropertyChanged;
            this._markers.Remove(pin);
        }
 /// <summary>
 /// Set the visibility of an annotation view
 /// </summary>
 /// <param name="annotationView">The annotation view</param>
 /// <param name="pin">The forms pin</param>
 private void SetAnnotationViewVisibility(MKAnnotationView annotationView, TKCustomMapPin pin)
 {
     annotationView.Hidden = !pin.IsVisible;
     annotationView.UserInteractionEnabled = pin.IsVisible;
     annotationView.Enabled = pin.IsVisible;
 }
 /// <summary>
 /// Set the image of the annotation view
 /// </summary>
 /// <param name="annotationView">The annotation view</param>
 /// <param name="pin">The forms pin</param>
 private async void UpdateImage(MKAnnotationView annotationView, TKCustomMapPin pin)
 {
     if (pin.Image != null)
     {
         // If this is the case, we need to get a whole new annotation view. 
         if (annotationView.GetType() == typeof (MKPinAnnotationView))
         {
             this.Map.RemoveAnnotation(annotationView.Annotation);
             this.Map.AddAnnotation(new TKCustomMapAnnotation(pin));
             return;
         }
         UIImage image;
         if (pin.Image is FileImageSource)
         {
             image = await new FileImageSourceHandler().LoadImageAsync(pin.Image);
         }
         else
         {
             image = await new ImageLoaderSourceHandler().LoadImageAsync(pin.Image);
         }
         Device.BeginInvokeOnMainThread(() =>
         {
             annotationView.Image = image;
         });
     }
     else
     {
         var pinAnnotationView = annotationView as MKPinAnnotationView;
         if (pinAnnotationView != null)
         {
             pinAnnotationView.AnimatesDrop = true;
             if (pin.DefaultPinColor != Color.Default)
             {
                 pinAnnotationView.PinTintColor = pin.DefaultPinColor.ToUIColor();
             }
             else
             {
                 pinAnnotationView.PinTintColor = UIColor.Red;
             }
         }
     }
 }
Beispiel #7
0
 /// <inheritdoc/>
 void IMapFunctions.RaisePinDragEnd(TKCustomMapPin pin)
 {
     this.OnPinDragEnd(pin);
 }
Beispiel #8
0
 /// <inheritdoc/>
 void IMapFunctions.RaiseCalloutClicked(TKCustomMapPin pin)
 {
     this.OnCalloutClicked(pin);
 }
Beispiel #9
0
 /// <inheritdoc/>
 void IMapFunctions.RaisePinSelected(TKCustomMapPin pin)
 {
     this.OnPinSelected(pin);
 }
Beispiel #10
0
        /// <summary>
        /// Raises <see cref="CalloutClicked"/>
        /// </summary>
        protected void OnCalloutClicked(TKCustomMapPin pin)
        {
            this.CalloutClicked?.Invoke(this, new TKGenericEventArgs <TKCustomMapPin>(pin));

            this.RaiseCommand(this.CalloutClickedCommand, pin);
        }
Beispiel #11
0
        /// <summary>
        /// Raises <see cref="PinDragEnd"/>
        /// </summary>
        /// <param name="pin">The dragged pin</param>
        protected void OnPinDragEnd(TKCustomMapPin pin)
        {
            this.PinDragEnd?.Invoke(this, new TKGenericEventArgs <TKCustomMapPin>(pin));

            this.RaiseCommand(this.PinDragEndCommand, pin);
        }
Beispiel #12
0
        /// <summary>
        /// Raises <see cref="PinSelected"/>
        /// </summary>
        /// <param name="pin">The selected pin</param>
        protected void OnPinSelected(TKCustomMapPin pin)
        {
            PinSelected?.Invoke(this, new TKGenericEventArgs <TKCustomMapPin>(pin));

            RaiseCommand(PinSelectedCommand, pin);
        }
        /// <summary>
        /// Updates the image on a marker
        /// </summary>
        /// <param name="pin">The forms pin</param>
        /// <param name="marker">The native marker</param>
        private async Task UpdateImage(TKCustomMapPin pin, Marker marker)
        {
            BitmapDescriptor bitmap;
            try
            {
                if (pin.Image != null)
                {
                    Android.Graphics.Bitmap icon = null;

                    if (pin.Image is FileImageSource)
                    {
                        icon = await new FileImageSourceHandler().LoadImageAsync(pin.Image, this.Context);
                    }
                    else
                    {
                        icon = await new ImageLoaderSourceHandler().LoadImageAsync(pin.Image, this.Context);
                    }
                    bitmap = BitmapDescriptorFactory.FromBitmap(icon);
                }
                else
                {
                    if (pin.DefaultPinColor != Color.Default)
                    {
                        bitmap = BitmapDescriptorFactory.DefaultMarker((float)pin.DefaultPinColor.Hue);
                    }
                    else
                    {
                        bitmap = BitmapDescriptorFactory.DefaultMarker();
                    }
                }
            }
            catch (Exception)
            {
                bitmap = BitmapDescriptorFactory.DefaultMarker();
            }
            marker.SetIcon(bitmap);
        }