/// <summary> /// Navigate to show all geometries once the mapview has been initialised /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VMMapView_ViewportInitialized(object sender, EventArgs e) { var shapeLayers = MapModel.CreateShapes(); ILayer allShapesLayer; shapeLayers.TryGetValue("all", out allShapesLayer); if (allShapesLayer != null) { VMMapView.Navigator.NavigateTo(allShapesLayer.Envelope, Mapsui.Utilities.ScaleMethod.Fit); } else { Mapsui.Geometries.Point LL = new Mapsui.Geometries.Point(Convert.ToDouble(5.84), 45.86); var sphericalMercatorCoordinateLL = SphericalMercator.FromLonLat(LL.X, LL.Y); Mapsui.Geometries.Point UR = new Mapsui.Geometries.Point(Convert.ToDouble(10.56), 47.83); var sphericalMercatorCoordinateUR = SphericalMercator.FromLonLat(UR.X, UR.Y); VMMapView.Navigator.NavigateTo(new BoundingBox(sphericalMercatorCoordinateLL, sphericalMercatorCoordinateUR), Mapsui.Utilities.ScaleMethod.Fit); } }
/// <summary> /// Replage the geometries, but do not change the map position /// </summary> public void NewShapes() { foreach (var layer in Map.Layers) { if (layer.Name == "Polygons" || layer.Name == "Lines" || layer.Name == "Points" || layer.Name == "PolygonsNoRecords" || layer.Name == "LinesNoRecords" || layer.Name == "PointsNoRecords") { Map.Layers.Remove(layer); } } var shapeLayers = MapModel.CreateShapes(); if (shapeLayers != null && shapeLayers.Count > 0) { ILayer polylayer; ILayer linelayer; ILayer pointlayer; ILayer polylayerNoRecords; ILayer linelayerNoRecords; ILayer pointlayerNoRecords; ILayer allShapesLayer; shapeLayers.TryGetValue("polygons", out polylayer); shapeLayers.TryGetValue("lines", out linelayer); shapeLayers.TryGetValue("points", out pointlayer); shapeLayers.TryGetValue("polygonsNoRecords", out polylayerNoRecords); shapeLayers.TryGetValue("linesNoRecords", out linelayerNoRecords); shapeLayers.TryGetValue("pointsNoRecords", out pointlayerNoRecords); shapeLayers.TryGetValue("all", out allShapesLayer); Map.Layers.Insert(Map.Layers.Count, polylayer); Map.Layers.Insert(Map.Layers.Count, linelayer); Map.Layers.Insert(Map.Layers.Count, pointlayer); Map.Layers.Insert(Map.Layers.Count, polylayerNoRecords); Map.Layers.Insert(Map.Layers.Count, linelayerNoRecords); Map.Layers.Insert(Map.Layers.Count, pointlayerNoRecords); if (allShapesLayer != null) { VMMapView.Navigator.NavigateTo(allShapesLayer.Envelope, Mapsui.Utilities.ScaleMethod.Fit); } } }
/// <summary> /// Remove and replace the geometries /// </summary> public void RefreshShapes() { foreach (var layer in Map.Layers) { if (layer.Name == "Polygons" || layer.Name == "Lines" || layer.Name == "Points") { Device.BeginInvokeOnMainThread(() => { Map.Layers.Remove(layer); }); } } var shapeLayers = MapModel.CreateShapes(); if (shapeLayers != null && shapeLayers.Count > 0) { ILayer polylayer; ILayer linelayer; ILayer pointlayer; ILayer polylayerNoRecords; ILayer linelayerNoRecords; ILayer pointlayerNoRecords; ILayer allShapesLayer; shapeLayers.TryGetValue("polygons", out polylayer); shapeLayers.TryGetValue("lines", out linelayer); shapeLayers.TryGetValue("points", out pointlayer); shapeLayers.TryGetValue("polygonsNoRecords", out polylayerNoRecords); shapeLayers.TryGetValue("linesNoRecords", out linelayerNoRecords); shapeLayers.TryGetValue("pointsNoRecords", out pointlayerNoRecords); shapeLayers.TryGetValue("all", out allShapesLayer); Device.BeginInvokeOnMainThread(() => { Map.Layers.Insert(Map.Layers.Count, polylayer); Map.Layers.Insert(Map.Layers.Count, linelayer); Map.Layers.Insert(Map.Layers.Count, pointlayer); Map.Layers.Insert(Map.Layers.Count, polylayerNoRecords); Map.Layers.Insert(Map.Layers.Count, linelayerNoRecords); Map.Layers.Insert(Map.Layers.Count, pointlayerNoRecords); }); } var filterGeom = Preferences.Get("FilterGeometry", String.Empty); if (filterGeom != String.Empty) { int geomId; int.TryParse(filterGeom, out geomId); if (geomId != 0) { try { Device.BeginInvokeOnMainThread(() => { var centre = MapModel.GetCentreOfGeometry(geomId); VMMapView.Navigator.NavigateTo(centre, VMMapView.Viewport.Resolution); }); } catch { } } Preferences.Set("FilterGeometry", String.Empty); //Only centre once. After this, forget the filter, and don't keep returning to this position } else { ReCentreMap(); } }