void OnSelection(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem == null) { return; //ItemSelected is called on deselection, which results in SelectedItem being set to null } var sampleName = e.SelectedItem.ToString(); var sample = allSamples.FirstOrDefault(x => x.Name == sampleName); if (sample != null) { Catch.Exceptions(async() => { await sample.SetupAsync(mapView); }); } clicker = null; if (sample is IFormsSample formsSample) { clicker = formsSample.OnClick; } listView.SelectedItem = null; }
private UIElement CreateRadioButton(ISampleBase sample) { var radioButton = new RadioButton { FontSize = 16, Content = sample.Name, Margin = new Thickness(4) }; radioButton.Click += (s, a) => { Catch.Exceptions(async() => { MapControl.Map?.Layers.Clear(); await sample.SetupAsync(MapControl); MapControl.Info += MapControlOnInfo; if (MapControl.Map != null) { LayerList.Initialize(MapControl.Map.Layers); } }); }; return(radioButton); }
public MapPage(ISampleBase sample, Func <MapView?, MapClickedEventArgs, bool>?c = null) { InitializeComponent(); // nullable warning workaround var test = this.mapView ?? throw new InvalidOperationException(); var test1 = this.info ?? throw new InvalidOperationException(); mapView !.RotationLock = false; mapView.UnSnapRotationDegrees = 30; mapView.ReSnapRotationDegrees = 5; mapView.PinClicked += OnPinClicked; mapView.MapClicked += OnMapClicked; Compass.ReadingChanged += Compass_ReadingChanged; mapView.MyLocationLayer.UpdateMyLocation(new Mapsui.UI.Maui.Position()); mapView.Info += MapView_Info; mapView.Renderer.WidgetRenders[typeof(CustomWidget.CustomWidget)] = new CustomWidgetSkiaRenderer(); _ = Task.Run(StartGPS); try { if (!Compass.IsMonitoring) { Compass.Start(SensorSpeed.Default); } } catch (Exception) { } Catch.Exceptions(async() => { await sample.SetupAsync(mapView); }); Clicker = c; }
private UIElement CreateRadioButton(ISampleBase sample) { var radioButton = new RadioButton { FontSize = 16, Content = sample.Name, Margin = new Thickness(4) }; radioButton.Click += (_, _) => { Catch.Exceptions(async() => { MapControl.Map?.Layers.Clear(); MapControl.Info -= MapOnInfo; await sample.SetupAsync(MapControl); MapControl.Info += MapOnInfo; MapControl.Refresh(); }); }; return(radioButton); }
protected override void OnCreate(Android.OS.Bundle?savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); var toolbar = FindViewById <AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); // Hack to tell the platform independent samples where the files can be found on Android. MbTilesSample.MbTilesLocation = MbTilesLocationOnAndroid; MbTilesHelper.DeployMbTilesFile(s => File.Create(System.IO.Path.Combine(MbTilesLocationOnAndroid, s))); _mapControl = FindViewById <MapControl>(Resource.Id.mapcontrol) ?? throw new NullReferenceException(); _mapControl.Map = MbTilesSample.CreateMap(); _mapControl.Info += MapOnInfo; _mapControl.Map.RotationLock = true; _mapControl.UnSnapRotationDegrees = 30; _mapControl.ReSnapRotationDegrees = 5; _mapControl.Renderer.WidgetRenders[typeof(CustomWidget.CustomWidget)] = new CustomWidgetSkiaRenderer(); var relativeLayout = FindViewById <RelativeLayout>(Resource.Id.mainLayout) ?? throw new NullReferenceException();; _popup?.Dispose(); relativeLayout.AddView(_popup = CreatePopup()); _mapControl.Map.Layers.Clear(); var sample = new MbTilesOverlaySample(); Catch.Exceptions(async() => { await sample.SetupAsync(_mapControl); }); //_mapControl.Info += MapControlOnInfo; //LayerList.Initialize(_mapControl.Map.Layers); }