/// <summary> /// This function update the tiles of the Map for this plateform. /// </summary> private void UpdateTiles() { var tileOverlay = new MKTileOverlay(customMap.MapTileTemplate); if (nativeMap != null) { if (this.customMap.MapTileTemplate != null) { if (this.tileOverlay != null) { this.nativeMap.RemoveOverlay(this.tileOverlay); this.tileOverlay = null; } nativeMap.OverlayRenderer = (MKMapView mapView, IMKOverlay overlay) => { var _tileOverlay = overlay as MKTileOverlay; if (_tileOverlay != null) { return(new MKTileOverlayRenderer(_tileOverlay)); } return(new MKOverlayRenderer(overlay)); }; } } nativeMap.AddOverlay(tileOverlay); }
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 <OsmMap> e) { base.OnElementChanged(e); if (Control == null) { // set up the native control var mapView = new MKMapView(); SetNativeControl(mapView); Control.ShowsCompass = true; var overlay = new MKTileOverlay("http://b.sm.mapstack.stamen.com/(watercolor,streets-and-labels)/{z}/{x}/{y}.png") { CanReplaceMapContent = true }; mapView.AddOverlay(overlay, MKOverlayLevel.AboveLabels); mapView.OverlayRenderer = OverlayRenderer; mapView.RegionChanged += MapViewOnRegionChanged; } if (routeCalculator == null) { routeCalculator = RouteCalculator.Instance; } if (e.OldElement != null) { // remove connections to the old instance Control.GetViewForAnnotation = null; Control.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped; e.OldElement.GpsLocationChanged -= OnGpsLocationChanged; e.OldElement.ExhibitSetChanged -= OnExhibitSetChanged; e.OldElement.DetailsRouteChanged -= OnDetailsRouteChanged; e.OldElement.CenterLocationCalled -= CenterLocation; } if (e.NewElement != null) { // setup connections to the new instance osmMap = e.NewElement; InitAnnotations(e.NewElement.ExhibitSet, e.NewElement.DetailsRoute); Control.GetViewForAnnotation = GetViewForAnnotation; Control.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped; e.NewElement.GpsLocationChanged += OnGpsLocationChanged; OnGpsLocationChanged(osmMap.GpsLocation); e.NewElement.ExhibitSetChanged += OnExhibitSetChanged; e.NewElement.DetailsRouteChanged += OnDetailsRouteChanged; OnDetailsRouteChanged(osmMap.DetailsRoute); e.NewElement.CenterLocationCalled += CenterLocation; InitMapPosition(); if (e.NewElement.ShowNavigation) { UpdateRoute(); } } }
private void AddTileOverlay(TileOverlay tileOverlay) { if (tileOverlay is UrlTileOverlay) { MKTileOverlay overlay = new MKTileOverlay((tileOverlay as UrlTileOverlay).Url); overlay.CanReplaceMapContent = true; overlay.TileSize = new CoreGraphics.CGSize(tileOverlay.TileWidth, tileOverlay.TileHeight); Control.InsertOverlay(overlay, 0); TileOverlays.Add(tileOverlay, overlay); } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.NewElement != null) { map = Control as MKMapView; TileOverlay = new CustomTileProvider( (IReadOnlyTileService)((App)Xamarin.Forms.Application.Current).Container.Resolve( typeof(IReadOnlyTileService))); if (map != null) { map.AddOverlay(TileOverlay); map.OverlayRenderer = OverlayRenderer; } } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.NewElement != null) { this.map = Control as MKMapView; TileOverlay = new CustomTileProvider( (IReadOnlyTileService)((App)Application.Current).Container.Resolve(typeof(IReadOnlyTileService))); if (this.map != null) { this.map.AddOverlay(TileOverlay); PointHandler = new PointHandler { Map = this.map, Points = CustomMap.Points, }; this.map.OverlayRenderer = OverlayRenderer; PointHandler.OnMapClicked += OnMapClicked; } } }
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"); } }
public override void ViewDidLoad() { base.ViewDidLoad(); //map - should be switched with separate reusable map view /OSMMapView/ MapViewDelegate mapDelegate = new MapViewDelegate(); mapView.Delegate = mapDelegate; string template = "http://tile.openstreetmap.org/{z}/{x}/{y}.png"; MKTileOverlay overlay = new MKTileOverlay(template); overlay.CanReplaceMapContent = true; mapView.AddOverlay(overlay, MKOverlayLevel.AboveLabels); // Center the map, for development purposes MKCoordinateRegion region = mapView.Region; region.Span.LatitudeDelta = 0.05; region.Span.LongitudeDelta = 0.05; region.Center = new CLLocationCoordinate2D(51.7166700, 8.7666700); mapView.Region = region; // Disable rotation programatically because value of designer is somehow ignored mapView.RotateEnabled = false; //tableView exhibitsTableView.RowHeight = 44; //exhibitsTableView.RegisterNibForCellReuse(UINib.FromName("ExhibitTableViewCell", null), // ExhibitTableViewCell.key); ExhibitsTableViewSource source = new ExhibitsTableViewSource(); source.Exhibits = LoadExhibitsData(); exhibitsTableView.Source = source; }