private void FormsMap_ClearRouteRequested(object sender, EventArgs e) { if (map.Overlays != null && map.Overlays.Any()) { map.RemoveOverlays(map.Overlays); } SetNeedsDisplay(); SetNeedsLayout(); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (_nativeMap != null) { return; } _nativeMap = Control as MKMapView; _nativeMap.ZoomEnabled = true; _nativeMap.ScrollEnabled = true; var uiTapGesture = new UITapGestureRecognizer(tappedGesture => MapTapped(_nativeMap, tappedGesture)); _nativeMap.AddGestureRecognizer(uiTapGesture); if (e.OldElement != null) { _nativeMap.RemoveOverlays(_nativeMap.Overlays); _nativeMap.OverlayRenderer = null; } if (e.NewElement != null) { _nativeMap.OverlayRenderer = OverlayRendererHandler; OnUpdateFeatures(); } }
public void Overlays7() { if (!TestRuntime.CheckSystemAndSDKVersion(7, 0)) { Assert.Inconclusive("requires 7.0+"); } using (var polygon = new MKPolygon()) using (var polyline = new MKPolyline()) using (var circle = new MKCircle()) using (var tile = new MKTileOverlay()) using (MKMapView mv = new MKMapView()) { // new API accepted MKOverlay (better protocol support) mv.AddOverlay(polygon, MKOverlayLevel.AboveLabels); mv.AddOverlay(tile, MKOverlayLevel.AboveLabels); Assert.That(mv.Overlays.Length, Is.EqualTo(2), "1"); mv.RemoveOverlay(tile); mv.RemoveOverlay(polygon); Assert.That(mv.Overlays, Is.Empty, "2"); IMKOverlay[] list = { polygon, polyline, circle, tile }; mv.AddOverlays(list, MKOverlayLevel.AboveRoads); Assert.That(mv.Overlays.Length, Is.EqualTo(4), "3"); mv.RemoveOverlays(list); Assert.That(mv.Overlays, Is.Empty, "4"); } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.OldElement != null) { _nativeMap = Control as MKMapView; if (_nativeMap != null) { _nativeMap.RemoveOverlays(_nativeMap.Overlays); _nativeMap.OverlayRenderer = null; _polylineRenderer = null; } } if (e.NewElement != null) { _formsMap = (CustomMap)e.NewElement; _nativeMap = Control as MKMapView; _nativeMap.OverlayRenderer = GetOverlayRenderer; Update(); } }
private void RemoveRouteCoordinates() { if (_polylines != null && _polylines.Count > 0) { _mapView.RemoveOverlays(_mapView.Overlays); _polylines.Clear(); } }
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if ((e.PropertyName.Equals("DrawPoint")) && formsMap.LocFlag == CommonMap.LocationFlag.Start && formsMap.DrawPoint != null && lastCoordinates.Count >= positionCount) { var polylineOptions = CreatePolylineOpty(lastCoordinates); lastCoordinates.RemoveRange(0, positionCount - 1); nativeMap.AddOverlay(polylineOptions); } if ((e.PropertyName.Equals("LastPFlag")) && formsMap.LocFlag == CommonMap.LocationFlag.Stop && formsMap.LastPFlag != null) { if (lastCoordinates.Count > 1) { var polylineOptions = CreatePolylineOpty(lastCoordinates); lastCoordinates.RemoveRange(0, lastCoordinates.Count - 1); nativeMap.AddOverlay(polylineOptions); } } if ((e.PropertyName.Equals("LastPFlag")) && formsMap.LocFlag == CommonMap.LocationFlag.Stop && formsMap.LastPFlag == null) { nativeMap.RemoveOverlays(nativeMap.Overlays); formsMap.platformRoad = new List <CLLocationCoordinate2D>(); wholeRoad = (List <CLLocationCoordinate2D>)formsMap.platformRoad; } if (e.PropertyName.Equals("DrawPoint") && formsMap.LocFlag == CommonMap.LocationFlag.Start && routeCoordinates != null && routeCoordinates.Count > 1 && (routeCoordinates.Count % refreshRoud) == 0) { RoudCreateOptimization(); } }
public override void ClearAllUserRoutes() { var allRoutes = _nativeMap.Overlays?.Where(o => o.GetType() != typeof(MKPolygon)) .ToArray(); if (allRoutes?.Any() == true) { _nativeMap.RemoveOverlays(allRoutes); } _currentUserRoute = null; }
public void Overlays() { using (var polygon = new MKPolygon()) using (var polyline = new MKPolyline()) using (var circle = new MKCircle()) using (MKMapView mv = new MKMapView()) { // old API accepted NSObject (limited protocol support) mv.AddOverlay(polygon); Assert.That(mv.Overlays.Length, Is.EqualTo(1), "1"); mv.RemoveOverlay(polygon); Assert.That(mv.Overlays, Is.Empty, "2"); IMKOverlay[] list = { polygon, polyline, circle }; mv.AddOverlays(list); Assert.That(mv.Overlays.Length, Is.EqualTo(3), "3"); mv.RemoveOverlays(list); Assert.That(mv.Overlays, Is.Empty, "4"); } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (isLoaded) { nativeMap.RemoveOverlays(nativeMap.Overlays); } if (e.OldElement != null) { nativeMap = Control as MKMapView; nativeMap.OverlayRenderer = null; } if (e.NewElement != null) { var formsMap = (CustomMap)e.NewElement; nativeMap = Control as MKMapView; isCircle = formsMap.DrawCircle; if (!isCircle) { nativeMap.OverlayRenderer = GetOverlayRenderer; CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count]; int index = 0; foreach (var position in formsMap.RouteCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } var routeOverlay = MKPolyline.FromCoordinates(coords); nativeMap.AddOverlay(routeOverlay); } if (isCircle) { var circle = formsMap.Circle; nativeMap.OverlayRenderer = GetOverlayRenderer; var circleOverlay = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius); nativeMap.AddOverlay(circleOverlay); } } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.OldElement != null) { if (nativeMap != null) { nativeMap.RemoveOverlays(nativeMap.Overlays); nativeMap.OverlayRenderer = null; polylineRenderer = null; } } if (e.NewElement != null) { formsMap = (CustomMap)e.NewElement; nativeMap = Control as MKMapView; UpdatePolyLine(); } }
public override void ChangedDragState( MKMapView mapView, MKAnnotationView annotationView, MKAnnotationViewDragState newState, MKAnnotationViewDragState oldState) { if (newState == MKAnnotationViewDragState.Ending) { isDragging = false; if (mapView.Overlays != null) { mapView.RemoveOverlays(mapView.Overlays); } var annotation = (PolylinePointAnnotation)annotationView.Annotation; annotation.Polyline.Value.Points [annotation.Index] = new GeoLocation( annotation.Coordinate.Latitude, annotation.Coordinate.Longitude); var newPolyline = annotation.Polyline.Value.ToMKPolyline(); mapView.AddOverlay(newPolyline); annotation.Polyline.RaisePropertyChanged(); return; } else if (newState == MKAnnotationViewDragState.Starting || newState == MKAnnotationViewDragState.Dragging) { isDragging = true; } else { isDragging = false; if (editPolyline != null) { mapView.RemoveOverlay(editPolyline); } } }
protected override void DataSourceUpdated(WebDataSource oldDataSource, WebDataSource newDataSource) { if (mapView.Overlays != null) { mapView.RemoveOverlays(mapView.Overlays); } var representation = (XIMapViewWebDocumentRepresentation)newDataSource?.Representation; if (representation == null || !representation.LocationIsValid) { return; } if (representation.Polyline == null) { var coordinate = representation.Location.ToCoordinate(); AddLocationAnnotation(coordinate); mapView.Region = MKCoordinateRegion.FromDistance(coordinate, 15000, 15000); } else { var coords = representation.Polyline.Value.ToCoordinates(); for (var i = 0; i < coords.Length; i++) { AddLocationAnnotation( coords [i], representation.Polyline, i); } var mkpolyline = MKPolyline.FromCoordinates(coords); mapView.AddOverlay(mkpolyline); mapView.SetVisibleMapRect( mkpolyline.BoundingMapRect, new NSEdgeInsets(45, 35, 35, 35), false); } }
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 void Overlays7() { TestRuntime.AssertXcodeVersion(5, 0, 1); using (var polygon = new MKPolygon()) using (var polyline = new MKPolyline()) using (var circle = new MKCircle()) using (var tile = new MKTileOverlay()) using (MKMapView mv = new MKMapView()) { // new API accepted MKOverlay (better protocol support) mv.AddOverlay(polygon, MKOverlayLevel.AboveLabels); mv.AddOverlay(tile, MKOverlayLevel.AboveLabels); Assert.That(mv.Overlays.Length, Is.EqualTo(2), "1"); mv.RemoveOverlay(tile); mv.RemoveOverlay(polygon); Assert.That(mv.Overlays, Is.Empty, "2"); IMKOverlay[] list = { polygon, polyline, circle, tile }; mv.AddOverlays(list, MKOverlayLevel.AboveRoads); Assert.That(mv.Overlays.Length, Is.EqualTo(4), "3"); mv.RemoveOverlays(list); Assert.That(mv.Overlays, Is.Empty, "4"); } }