Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GeoMapViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
5using System;
6using Mapsui.Projections;
7using Mapsui.UI.Maui;
9
11{
12 public partial class GeoMapViewModel : ReturningPopupViewModel<string>
13 {
14 // Expose the MapControl so we can read the viewport center
15 public MapControl? MapControl { get; set; }
16
21
22 public GeoMapViewModel(double? Latitude = null, double? Longitude = null)
23 {
24 if (Latitude.HasValue && Longitude.HasValue)
25 InitialCoordinate = new GeoPosition(Latitude.Value, Longitude.Value);
26 }
27
28 [RelayCommand]
29 public async Task Confirm()
30 {
31 if (MapControl?.Map?.Navigator.Viewport is null)
32 {
33 this.TrySetResult(null);
34 await ServiceRef.PopupService.PopAsync();
35 return;
36 }
37
38 var vp = MapControl.Map.Navigator.Viewport;
39 // Convert world (Mercator) to lon/lat
40 var (lon, lat) = SphericalMercator.ToLonLat(vp.CenterX, vp.CenterY);
41 this.TrySetResult($"{lon},{lat}");
42 await ServiceRef.PopupService.PopAsync();
43 }
44 }
45}
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IPopupService PopupService
Popup service for presenting application popups.
Definition: ServiceRef.cs:142
GeoPosition? InitialCoordinate
Optional initial coordinate to center the map on.
Contains information about a position in a geo-spatial coordinate system.
Definition: GeoPosition.cs:17