public override MKOverlayRenderer OverlayRenderer(MKMapView mapView, IMKOverlay overlay) { if (overlay is MKCircle) { if (circleRenderer == null) { circleRenderer = new MKCircleRenderer(overlay as MKCircle); circleRenderer.FillColor = UIColor.Purple; circleRenderer.Alpha = 0.5f; } return(circleRenderer); } else if (overlay is MKPolygon) { if (polyRenderer == null) { polyRenderer = new MKPolygonRenderer(overlay as MKPolygon); polyRenderer.FillColor = UIColor.Green; polyRenderer.Alpha = 0.5f; } return(polyRenderer); } else { Debug.WriteLine("OverlayRenderer() - Unknown overlay type!"); return(null); } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { Control?.RemoveGestureRecognizer(_tapRecogniser); base.OnElementChanged(e); if (Control != null) { var nativeMap = Control as MKMapView; Control.AddGestureRecognizer(_tapRecogniser); nativeMap.DidChangeVisibleRegion += NativeMap_DidChangeVisibleRegion; } if (e.OldElement != null) { var nativeMap = Control as MKMapView; if (nativeMap != null) { if (nativeMap.Overlays != null) { nativeMap.RemoveOverlays(nativeMap.Overlays); } nativeMap.OverlayRenderer = null; _polygonRenderer = null; _polylineRenderer = null; } } if (e.NewElement != null) { DrawElements(); } }
/* TODO Readd LFHeatMap project first * Found at https://github.com/TreeWatch/LFHeatMaps * Code: * void ChangeRegion(object sender, MKMapViewChangeEventArgs e){ * * foreach (var item in mapView.Subviews) * { * var heatMap = item as UIHeatMapView; * if (heatMap != null) * heatMap.RefreshHeatMap(mapView); * } * } */ /// <summary> /// Gets the overlay render for a overlay. /// </summary> /// <returns>The overlay render.</returns> /// <param name="m">The Mapview.</param> /// <param name="o">The Overlay.</param> private MKOverlayRenderer GetOverlayRender(MKMapView m, IMKOverlay o) { var overlay = Runtime.GetNSObject(o.Handle) as MKPolygon; if (overlay != null) { var polygon = overlay; var polygonRenderer = new MKPolygonRenderer(polygon); if (polygon.Title == "Field") { polygonRenderer.FillColor = this.myMap.OverLayColor.ToUIColor(); polygonRenderer.StrokeColor = this.myMap.BoundaryColor.ToUIColor(); polygonRenderer.LineWidth = 1; } return(polygonRenderer); } if (o is MultiPolygon) { return(new MultiPolygonView(o)); } return(null); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.OldElement != null) { var nativeMap = Control as MKMapView; if (nativeMap != null) { nativeMap.RemoveOverlays(nativeMap.Overlays); nativeMap.OverlayRenderer = null; polygonRenderer = null; } } if (e.NewElement != null) { var formsMap = (BindableMap)e.NewElement; var nativeMap = Control as MKMapView; nativeMap.OverlayRenderer = GetOverlayRenderer; CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.ShapeCoordinates.Count]; int index = 0; foreach (var position in formsMap.ShapeCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } var blockOverlay = MKPolygon.FromCoordinates(coords); nativeMap.AddOverlay(blockOverlay); } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); #region Area if (e.OldElement != null) { var nativeMap = Control as MKMapView; if (nativeMap != null) { nativeMap.RemoveOverlays(nativeMap.Overlays); nativeMap.OverlayRenderer = null; polygonRenderer = null; } } if (e.NewElement != null) { var formsMap = (AreaMap)e.NewElement; var nativeMap = Control as MKMapView; nativeMap.OverlayRenderer = GetOverlayRenderer; CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.ShapeCoordinates.Count]; int index = 0; foreach (var position in formsMap.ShapeCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } var blockOverlay = MKPolygon.FromCoordinates(coords); nativeMap.AddOverlay(blockOverlay); } #endregion #region Pines if (e.OldElement != null) { var nativeMap = Control as MKMapView; if (nativeMap != null) { nativeMap.RemoveAnnotations(nativeMap.Annotations); nativeMap.GetViewForAnnotation = null; nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView -= OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView -= OnDidDeselectAnnotationView; } } if (e.NewElement != null) { var formsMap = (AreaMap)e.NewElement; var nativeMap = Control as MKMapView; customPins = formsMap.CustomPins; nativeMap.GetViewForAnnotation = GetViewForAnnotation; nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView += OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView += OnDidDeselectAnnotationView; } #endregion }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { try { base.OnElementChanged(e); if (e.OldElement != null) { var nativeMap = Control as MKMapView; nativeMap.GetViewForAnnotation = null; nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped; nativeMap.RemoveOverlays(nativeMap.Overlays); nativeMap.OverlayRenderer = null; polygonRenderer = null; } if (e.NewElement != null) { var formsMap = (ExtendedMap)e.NewElement; var nativeMap = Control as MKMapView; customPins = formsMap.ItemsSource; nativeMap.GetViewForAnnotation = GetViewForAnnotation; nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped; if (formsMap.Coverages != null) { List <IMKOverlay> overlayList = new List <IMKOverlay>(); nativeMap.OverlayRenderer = GetOverlayRenderer; foreach (Polygon poligon in formsMap.Coverages) { if (poligon != null && poligon.Points != null && poligon.Points.Count > 0) { CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[poligon.Points.Count]; int index = 0; foreach (var point in poligon.Points) { coords[index] = new CLLocationCoordinate2D(point.Latitude, point.Longitude); index++; } MKPolygon blockOverlay = MKPolygon.FromCoordinates(coords); blockOverlay.Title = poligon.CoverageCode; overlayList.Add(blockOverlay); } } IMKOverlay[] imko = overlayList.ToArray(); nativeMap.AddOverlays(imko); } } } catch (Exception ex) { Dictionary <string, string> properties = new Dictionary <string, string>(); properties.Add("Message", ex.Message); properties.Add("Source", ex.Source); properties.Add("StackTrace", ex.StackTrace); Analytics.TrackEvent("OnElementChanged", properties); } }
//when you click on a part of the callout, delete polygon public void removePolygon() { System.Diagnostics.Debug.WriteLine("delete polygon!------"); map.setPolygonPoints(0); map.ShapeCoordinates.Clear(); nativeMap.RemoveOverlay(polygon); polygonRenderer = null; polygon = null; clearShapeMarkers(); }
MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlay) { if (polygonRenderer == null) { polygonRenderer = new MKPolygonRenderer (overlay as MKPolygon); polygonRenderer.FillColor = UIColor.Red; polygonRenderer.StrokeColor = UIColor.Blue; polygonRenderer.Alpha = 0.4f; polygonRenderer.LineWidth = 9; } return polygonRenderer; }
MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlay) { if (polygonRenderer == null) { polygonRenderer = new MKPolygonRenderer(overlay as MKPolygon); polygonRenderer.FillColor = UIColor.Red; polygonRenderer.StrokeColor = UIColor.Blue; polygonRenderer.Alpha = 0.4f; polygonRenderer.LineWidth = 9; } return(polygonRenderer); }
MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlayWrapper) { if (polygonRenderer == null && !Equals(overlayWrapper, null)) { var overlay = Runtime.GetNSObject(overlayWrapper.Handle) as IMKOverlay; polygonRenderer = new MKPolygonRenderer(overlay as MKPolygon) { FillColor = UIColor.Red, StrokeColor = UIColor.Blue, Alpha = 0.4f, LineWidth = 9 }; } return(polygonRenderer); }
private MKOverlayRenderer GetBorderOverlayRenderer(MKMapView mapView, IMKOverlay overlayWrapper) { if (PolygonRenderer == null && !Equals(overlayWrapper, null)) { var overlay = Runtime.GetNSObject(overlayWrapper.Handle) as IMKOverlay; PolygonRenderer = new MKPolygonRenderer(overlay as MKPolygon) { FillColor = Color.FromHex("#71cce7").ToUIColor(), StrokeColor = Color.FromHex("#71cce7").ToUIColor(), Alpha = 0.4f, LineWidth = 1 }; } return(PolygonRenderer); }
MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlayWrapper) { if (!Equals(overlayWrapper, null)) { var overlay = Runtime.GetNSObject(overlayWrapper.Handle) as IMKOverlay; polygonRenderer = new MKPolygonRenderer(overlay as MKPolygon) { FillColor = overlay.GetTitle() == "CB" ? UIColor.FromRGB(18, 158, 224) : UIColor.FromRGB(1, 69, 107), StrokeColor = UIColor.Gray, Alpha = 0.4f, LineWidth = 1 }; } return(polygonRenderer); }
public override MKOverlayRenderer OverlayRenderer(MKMapView mapView, IMKOverlay overlay) { if (overlay is MKPolygon) { var polygon = overlay as MKPolygon; var polygonView = new MKPolygonRenderer(polygon); if (MapControlManager.IsOutOf && !ModeZoneFirstView.IsOnModeZone) { polygonView.FillColor = UIColor.FromRGB(255, 76, 57).ColorWithAlpha((nfloat)0.4); polygonView.StrokeColor = UIColor.FromRGB(255, 76, 57).ColorWithAlpha((nfloat)0.2); } else { polygonView.FillColor = UIColor.FromRGB(98, 218, 115).ColorWithAlpha((nfloat)0.4); polygonView.StrokeColor = UIColor.FromRGB(98, 218, 115).ColorWithAlpha((nfloat)0.2); } polygonView.LineWidth = 1; return(polygonView); } else if (overlay is MKCircle) { var circle = overlay as MKCircle; var circleView = new MKCircleRenderer(circle); circleView.FillColor = UIColor.Blue; circleView.Alpha = 0.2f; return(circleView); } else if (overlay is MKPolyline) { MKPolylineRenderer polylineRenderer = new MKPolylineRenderer(overlay as MKPolyline); if (MapControlManager.IsOutOf && !ModeZoneFirstView.IsOnModeZone) { polylineRenderer.FillColor = UIColor.FromRGB(255, 76, 57); polylineRenderer.StrokeColor = UIColor.FromRGB(255, 76, 57); } else { polylineRenderer.FillColor = UIColor.FromRGB(98, 218, 115); polylineRenderer.StrokeColor = UIColor.FromRGB(98, 218, 115); } polylineRenderer.LineWidth = 2; polylineRenderer.Alpha = 0.8f; return(polylineRenderer); } return(null); }
public MKOverlayRenderer OverlayRenderer(MKMapView mapView, IMKOverlay overlay) { if (polygonRenderer != null && polygonRenderer.Polygon == polygon) { return(polygonRenderer); } polygon = overlay as MKPolygon; polygonRenderer = new MKPolygonRenderer(polygon) { FillColor = new UIColor(0, 1, 0, .3f), StrokeColor = new UIColor(0, 1, 0, 0.9f), LineWidth = 1f }; return(polygonRenderer); }
public override MKOverlayRenderer OverlayRenderer(MKMapView mapView, IMKOverlay overlay) { var polygon = overlay as MKPolygon; if (polygon != null) { var polygonRenderer = new MKPolygonRenderer(polygon) { FillColor = UIColor.LightGray, StrokeColor = UIColor.DarkGray, LineWidth = 3f }; return(polygonRenderer); } return(mapView.RendererForOverlay(overlay)); }
public override MKOverlayRenderer OverlayRenderer(MKMapView mapView, IMKOverlay overlay) { switch (overlay) { case MKPolygon polygon: var prenderer = new MKPolygonRenderer(polygon) { FillColor = UIColor.Red, StrokeColor = UIColor.Blue, Alpha = 0.4f, LineWidth = 9 }; return(prenderer); default: throw new Exception($"Not supported: {overlay.GetType()}"); } }
protected override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (annotation is MKUserLocation) { return(null); } var customPin = GetCustomPin(annotation as MKPointAnnotation); if (customPin == null) { Debug.WriteLine("Custom pin not found"); return(null); } var annotationView = new MKAnnotationView(annotation, string.Empty); annotationView.Image = UIImage.FromFile(customPin.ImageUrl); annotationView.CalloutOffset = new CGPoint(0, 0); annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile(customPin.ImageUrl)); annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure); annotationView.CanShowCallout = true; var nativeMap = Control as MKMapView; if (nativeMap.Overlays != null) { nativeMap.RemoveOverlays(nativeMap.Overlays); nativeMap.OverlayRenderer = null; PolylineRenderer = null; PolygonRenderer = null; } if (FormsMap.RoutePins != null && FormsMap.RoutePins.Count > 2) { DrawRoutePolyLine(nativeMap); } else if (FormsMap.AvailableRegions != null) { DrawRegionBorderPolyGon(nativeMap); } return(annotationView); }
void FindSafeZones() { var polygonOverlay = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[] { new CLLocationCoordinate2D(45.00, -111.00), new CLLocationCoordinate2D(45, -104), new CLLocationCoordinate2D(41, -104), new CLLocationCoordinate2D(41, -111) }); map.AddOverlay(polygonOverlay); map.OverlayRenderer = (mapView, overlay) => { if (overlay is MKCircle) { if (circleRenderer == null) { circleRenderer = new MKCircleRenderer(overlay as MKCircle) { FillColor = UIColor.Red, Alpha = 0.5f }; } return(circleRenderer); } else if (overlay is MKPolygon) { if (polyRenderer == null) { polyRenderer = new MKPolygonRenderer(overlay as MKPolygon); polyRenderer.FillColor = UIColor.Green; polyRenderer.Alpha = 0.5f; } return(polyRenderer); } return(null); }; Helpers.CenterOnCheyenne(map); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.OldElement != null) { nativeMap = Control as MKMapView; if (nativeMap != null) { nativeMap.RemoveAnnotations(nativeMap.Annotations); nativeMap.GetViewForAnnotation = null; nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView -= OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView -= OnDidDeselectAnnotationView; nativeMap.RemoveOverlays(nativeMap.Overlays); nativeMap.OverlayRenderer = null; polygonRenderer = null; } } if (e.NewElement != null) { map = (CustomMap)e.NewElement; var nativeMap = Control as MKMapView; customPins = map.CustomPins; nativeMap.GetViewForAnnotation = GetViewForAnnotation; nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView += OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView += OnDidDeselectAnnotationView; customPins = map.CustomPins; shapeCoordinates = map.ShapeCoordinates; nativeMap.DidSelectAnnotationView += onViewClick; nativeMap.ScrollEnabled = false; nativeMap.ZoomEnabled = false; } }
public MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlay) { if (overlay is MKPolyline) { var polylineRenderer = new MKPolylineRenderer(overlay as MKPolyline); polylineRenderer.FillColor = _formsMap.RouteColor.ToUIColor(); polylineRenderer.StrokeColor = _formsMap.RouteColor.ToUIColor(); polylineRenderer.LineWidth = 8; return(polylineRenderer); } else if (overlay is MKPolygon) { var polygonRenderer = new MKPolygonRenderer(overlay as MKPolygon); polygonRenderer.FillColor = _formsMap.SearchPolygonColor.ToUIColor(); polygonRenderer.StrokeColor = Xamarin.Forms.Color.Transparent.ToUIColor(); return(polygonRenderer); } return(null); }
void FindRouteToSafeZone() { MKPlacemarkAddress address = null; //Start at our current location var fromLocation = new MKPlacemark(CDC.Coordinates, address); //Go to the safe zone var destinationLocation = new MKPlacemark(new CLLocationCoordinate2D(Cheyenne.Latitude, Cheyenne.Longitude), address); var request = new MKDirectionsRequest { Source = new MKMapItem(fromLocation), Destination = new MKMapItem(destinationLocation), RequestsAlternateRoutes = false }; var directions = new MKDirections(request); //Async network call to Apple's servers directions.CalculateDirections((response, error) => { if (error != null) { Console.WriteLine(error.LocalizedDescription); } else { foreach (var route in response.Routes) { map.AddOverlay(route.Polyline); } } }); map.OverlayRenderer = (mapView, overlay) => { if (overlay is MKCircle) { if (circleRenderer == null) { circleRenderer = new MKCircleRenderer(overlay as MKCircle) { FillColor = UIColor.Red, Alpha = 0.5f }; } return(circleRenderer); } else if (overlay is MKPolygon) { if (polyRenderer == null) { polyRenderer = new MKPolygonRenderer(overlay as MKPolygon); polyRenderer.FillColor = UIColor.Green; polyRenderer.Alpha = 0.5f; } return(polyRenderer); } else if (overlay is MKPolyline) { var route = (MKPolyline)overlay; var renderer = new MKPolylineRenderer(route) { StrokeColor = UIColor.Blue }; return(renderer); } return(null); }; Helpers.CenterOnUnitedStates(map); }
/* TODO Readd LFHeatMap project first * Found at https://github.com/TreeWatch/LFHeatMaps * Code: void ChangeRegion(object sender, MKMapViewChangeEventArgs e){ foreach (var item in mapView.Subviews) { var heatMap = item as UIHeatMapView; if (heatMap != null) heatMap.RefreshHeatMap(mapView); } } */ /// <summary> /// Gets the overlay render for a overlay. /// </summary> /// <returns>The overlay render.</returns> /// <param name="m">The Mapview.</param> /// <param name="o">The Overlay.</param> private MKOverlayRenderer GetOverlayRender(MKMapView m, IMKOverlay o) { var overlay = Runtime.GetNSObject(o.Handle) as MKPolygon; if (overlay != null) { var polygon = overlay; var polygonRenderer = new MKPolygonRenderer(polygon); if (polygon.Title == "Field") { polygonRenderer.FillColor = this.myMap.OverLayColor.ToUIColor(); polygonRenderer.StrokeColor = this.myMap.BoundaryColor.ToUIColor(); polygonRenderer.LineWidth = 1; } return polygonRenderer; } if (o is MultiPolygon) { return new MultiPolygonView(o); } return null; }
void FindRouteToSafeZone() { MKPlacemarkAddress address = null; //Start at our current location var fromLocation = new MKPlacemark (CDC.Coordinates, address); //Go to the safe zone var destinationLocation = new MKPlacemark (new CLLocationCoordinate2D (Cheyenne.Latitude, Cheyenne.Longitude), address); var request = new MKDirectionsRequest { Source = new MKMapItem (fromLocation), Destination = new MKMapItem (destinationLocation), RequestsAlternateRoutes = false }; var directions = new MKDirections (request); //Async network call to Apple's servers directions.CalculateDirections ((response, error) => { if (error != null) { Console.WriteLine (error.LocalizedDescription); } else { foreach (var route in response.Routes) { map.AddOverlay (route.Polyline); } } }); map.OverlayRenderer = (mapView, overlay) => { if (overlay is MKCircle) { if (circleRenderer == null) { circleRenderer = new MKCircleRenderer (overlay as MKCircle) { FillColor = UIColor.Red, Alpha = 0.5f }; } return circleRenderer; } else if (overlay is MKPolygon) { if (polyRenderer == null) { polyRenderer = new MKPolygonRenderer (overlay as MKPolygon); polyRenderer.FillColor = UIColor.Green; polyRenderer.Alpha = 0.5f; } return polyRenderer; } else if (overlay is MKPolyline) { var route = (MKPolyline)overlay; var renderer = new MKPolylineRenderer (route) { StrokeColor = UIColor.Blue }; return renderer; } return null; }; Helpers.CenterOnUnitedStates (map); }
void FindSafeZones() { var polygonOverlay = MKPolygon.FromCoordinates (new CLLocationCoordinate2D[] { new CLLocationCoordinate2D (45.00, -111.00), new CLLocationCoordinate2D (45, -104), new CLLocationCoordinate2D (41, -104), new CLLocationCoordinate2D (41, -111) }); map.AddOverlay (polygonOverlay); map.OverlayRenderer = (mapView, overlay) => { if (overlay is MKCircle) { if (circleRenderer == null) { circleRenderer = new MKCircleRenderer (overlay as MKCircle) { FillColor = UIColor.Red, Alpha = 0.5f }; } return circleRenderer; } else if (overlay is MKPolygon) { if (polyRenderer == null) { polyRenderer = new MKPolygonRenderer (overlay as MKPolygon); polyRenderer.FillColor = UIColor.Green; polyRenderer.Alpha = 0.5f; } return polyRenderer; } return null; }; Helpers.CenterOnCheyenne (map); }
protected override void OnDetached() { mapView.DidUpdateUserLocation -= DidUpdateUserLocation; mapView.MapLoaded -= MapView_MapLoaded; // mapView.RemoveGestureRecognizer(tapGesture); // tapGesture.Dispose(); // tapGesture = null; mapView = null; behavior = null; polygon?.Dispose(); polygon = null; polygonRenderer?.Dispose(); polygonRenderer = null; }
public override MKOverlayRenderer OverlayRenderer(MKMapView mapView, IMKOverlay overlay) { if (overlay is MKCircle) { if (circleRenderer == null) { circleRenderer = new MKCircleRenderer(overlay as MKCircle); circleRenderer.FillColor = UIColor.Purple; circleRenderer.Alpha = 0.5f; } return circleRenderer; } else if (overlay is MKPolygon) { if (polyRenderer == null) { polyRenderer = new MKPolygonRenderer(overlay as MKPolygon); polyRenderer.FillColor = UIColor.Green; polyRenderer.Alpha = 0.5f; } return polyRenderer; } else { Debug.WriteLine("OverlayRenderer() - Unknown overlay type!"); return null; } }