示例#1
0
        /// <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();
            }
        }