コード例 #1
0
        public LayerDetailViewModel()
        {
            try
            {
                var instance = SimpleIoc.Default.GetInstance <MainDataViewModel>();
                Map = instance.SelectedMapView.Map;

                ExportToCsvCommand = new RelayCommand(() =>
                {
                    var dlg = new SaveFileDialog {
                        Filter = "Comma Separated Values|*.csv"
                    };
                    if (dlg.ShowDialog() == true)
                    {
                        using (var sw = new StreamWriter(dlg.FileName))
                            using (var csv = new CsvWriter(sw))
                            {
                                csv.Configuration.TypeConverterCache.AddConverter <FeatureTable>(
                                    new FeatureTableTypeConverter());
                                csv.WriteRecords(FeatureLayers);
                            }
                    }
                });

                InspectCommand = new RelayCommand <object>(obj =>
                {
                    var inspectWindow = new InspectWindow
                    {
                        DataContext = obj
                    };
                    inspectWindow.Show();
                }, obj => obj != null);

                //der Wechsel eines Tabs interessiert mich
                instance.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName == nameof(MainDataViewModel.SelectedMapView))
                    {
                        if (instance.SelectedMapView == null)
                        {
                            return;
                        }

                        Map = instance.SelectedMapView.Map;
                        //der Wechsel einer Map innerhalb eines Tabs interessiert mich auch
                        instance.SelectedMapView.PropertyChanged += (sender1, args1) =>
                        {
                            if (args1.PropertyName == nameof(MapViewModel.Map))
                            {
                                Map = instance.SelectedMapView.Map;
                            }
                        };
                    }
                };
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(MainDataViewModel mainDataViewModel)
        {
            // create accent color menu items for the demo
            this.AccentColors = ThemeManager.Accents
                                .Select(a => new AccentColorMenuData()
            {
                Name = a.Name, ColorBrush = a.Resources["AccentColorBrush"] as Brush
            })
                                .ToList();

            // create metro theme color menu items for the demo
            this.AppThemes = ThemeManager.AppThemes
                             .Select(a => new AppThemeMenuData()
            {
                Name = a.Name, BorderColorBrush = a.Resources["BlackColorBrush"] as Brush, ColorBrush = a.Resources["WhiteColorBrush"] as Brush
            })
                             .ToList();

            LayerDetailsCommand = new RelayCommand(() =>
            {
                LayerDetailWindow view = new LayerDetailWindow();
                view.ShowDialog();
            },
                                                   () => mainDataViewModel.SelectedMapView != null);

            FileOpenCommand = new RelayCommand(() =>
            {
                Debug.WriteLine("File open");
                var dlg    = new OpenFileDialog();
                dlg.Filter =
                    "ArcGIS Runtime Mobile Formats|*.mmpk;*.geodatabase|Mobile Map Packages (*.mmpk)|*.mmpk|Mobile Geodatabases (*.geodatabase)|*.geodatabase|All Files (*.*)|*.*";
                if (dlg.ShowDialog() == true)
                {
                    FilePath = dlg.FileName;
                }
            });

            InspectMmpkCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.Mmpk
                };
                inspectWindow.Show();
            }, () => mainDataViewModel.Mmpk != null);
            InspectGeodatabaseCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.Geodatabase
                };
                inspectWindow.Show();
            }, () => mainDataViewModel.Geodatabase != null);
            InspectMapCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.SelectedMapView.Map
                };
                inspectWindow.Show();
            }, () => mainDataViewModel.SelectedMapView != null);
            InspectLayerCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.SelectedMapView.SelectedLayer
                };
                inspectWindow.Show();
            }, () => mainDataViewModel?.SelectedMapView?.SelectedLayer != null);
            InspectBackgroundGridCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.SelectedMapView.MapView.BackgroundGrid
                };
                inspectWindow.Show();
            }, () => mainDataViewModel?.SelectedMapView?.MapView?.BackgroundGrid != null);

            AddBasemapCommand = new RelayCommand(() =>
            {
                var map = mainDataViewModel?.SelectedMapView?.Map;
                if (map != null)
                {
                    map.Basemap = Basemap.CreateTopographic();
                    if (map.SpatialReference != map.Basemap.BaseLayers.First().SpatialReference)
                    {
                        MessageBox.Show(
                            "Basemap applied, but SpatialReference of current map differs from basemaps SpatialReference. Basemap is not visible.");
                    }
                }
            },
                                                 () => mainDataViewModel.SelectedMapView != null);
            AddTpkBasemapCommand = new RelayCommand(() =>
            {
                var dlg    = new OpenFileDialog();
                dlg.Filter =
                    "ArcGIS Tile Package|*.tpk|All Files (*.*)|*.*";
                if (dlg.ShowDialog() == true)
                {
                    var map = mainDataViewModel?.SelectedMapView?.Map;
                    if (map != null)
                    {
                        var tileCache = new TileCache(dlg.FileName);
                        var tileLayer = new ArcGISTiledLayer(tileCache);
                        map.Basemap   = new Basemap(tileLayer);
                    }
                }
            },
                                                    () => mainDataViewModel.SelectedMapView != null);

            ShowAboutCommand = new RelayCommand(() =>
            {
                // await((MainWindow)sender).ShowMessageAsync("", $"You clicked on {menuItem.Label} button");
            },
                                                () => mainDataViewModel.SelectedMapView != null);

            PropertyChanged += (sender, args) =>
            {
                mainDataViewModel.FilePath = FilePath;
            };
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(MainDataViewModel mainDataViewModel)
        {
            // create accent color menu items for the demo
            this.AccentColors = ThemeManager.Accents
                                .Select(a => new AccentColorMenuData()
            {
                Name = a.Name, ColorBrush = a.Resources["AccentColorBrush"] as Brush
            })
                                .ToList();

            // create metro theme color menu items for the demo
            this.AppThemes = ThemeManager.AppThemes
                             .Select(a => new AppThemeMenuData()
            {
                Name = a.Name, BorderColorBrush = a.Resources["BlackColorBrush"] as Brush, ColorBrush = a.Resources["WhiteColorBrush"] as Brush
            })
                             .ToList();

            LayerDetailsCommand = new RelayCommand(() =>
            {
                LayerDetailWindow view = new LayerDetailWindow();
                view.ShowDialog();
            },
                                                   () => mainDataViewModel.SelectedMapView != null);

            FileOpenCommand = new RelayCommand(() =>
            {
                Debug.WriteLine("File open");
                var dlg    = new OpenFileDialog();
                dlg.Filter = string.Join("|", new[]
                {
                    "ArcGIS Runtime Mobile Formats|*.mmpk;*.geodatabase",
                    "Mobile Map Packages|*.mmpk",
                    "Unpacked Mobile Map Packages|*.info",
                    "Mobile Geodatabases|*.geodatabase",
                    "All Files|*.*"
                });
                if (dlg.ShowDialog() == true)
                {
                    var selectedPath = dlg.FileName;
                    if (selectedPath.EndsWith(".info"))
                    {
                        selectedPath = System.IO.Path.GetDirectoryName(selectedPath);
                    }
                    FilePath = selectedPath;
                }
            });

            InspectMmpkCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.Mmpk
                };
                inspectWindow.Show();
            }, () => mainDataViewModel.Mmpk != null);
            InspectGeodatabaseCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.Geodatabase
                };
                inspectWindow.Show();
            }, () => mainDataViewModel.Geodatabase != null);
            InspectMapCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.SelectedMapView.Map
                };
                inspectWindow.Show();
            }, () => mainDataViewModel.SelectedMapView != null);
            InspectLayerCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.SelectedMapView.SelectedLayer
                };
                inspectWindow.Show();
            }, () => mainDataViewModel?.SelectedMapView?.SelectedLayer != null);
            InspectBackgroundGridCommand = new RelayCommand(() =>
            {
                var inspectWindow = new InspectWindow
                {
                    DataContext = mainDataViewModel.SelectedMapView.MapView.BackgroundGrid
                };
                inspectWindow.Show();
            }, () => mainDataViewModel?.SelectedMapView?.MapView?.BackgroundGrid != null);

            AddBasemapCommand = new RelayCommand(() =>
            {
                var map = mainDataViewModel?.SelectedMapView?.Map;
                if (map != null)
                {
                    map.Basemap = Basemap.CreateTopographic();
                    ValidateSpatialReference(map);
                }
            },
                                                 () => mainDataViewModel.SelectedMapView != null);
            AddFileBasemapCommand = new RelayCommand(() =>
            {
                var dlg    = new OpenFileDialog();
                dlg.Filter =
                    "ArcGIS Offline Basemap Packages|*.tpk;*.vtpk|ArcGIS Tile Package|*.tpk|ArcGIS Vector Tile Package|*.vtpk|All Files (*.*)|*.*";
                if (dlg.ShowDialog() == true)
                {
                    var map = mainDataViewModel?.SelectedMapView?.Map;
                    if (map != null)
                    {
                        switch (System.IO.Path.GetExtension(dlg.FileName).ToLower())
                        {
                        case ".tpk":
                            var tileCache = new TileCache(dlg.FileName);
                            var tileLayer = new ArcGISTiledLayer(tileCache);
                            map.Basemap   = new Basemap(tileLayer);
                            ValidateSpatialReference(map);
                            break;

                        case ".vtpk":
                            //var vectorTileCache = new Esri.ArcGISRuntime.Mapping.VectorTileCache()
                            var vectorTileLayer = new ArcGISVectorTiledLayer(new Uri(dlg.FileName));
                            map.Basemap         = new Basemap(vectorTileLayer);
                            ValidateSpatialReference(map);
                            break;

                        default:
                            break;
                        }
                    }
                }
            },
                                                     () => mainDataViewModel.SelectedMapView != null);

            ShowAboutCommand = new RelayCommand(() =>
            {
                // await((MainWindow)sender).ShowMessageAsync("", $"You clicked on {menuItem.Label} button");
            },
                                                () => mainDataViewModel.SelectedMapView != null);

            ToggleLayerExtentGraphicsVisibility = new RelayCommand(() =>
            {
                LayerExtentGraphicsVisible = !LayerExtentGraphicsVisible;
                if (mainDataViewModel.SelectedMapView != null)
                {
                    mainDataViewModel.SelectedMapView.LayerExtentGraphicsVisible = LayerExtentGraphicsVisible;
                }
            });

            ToggleBookmarkExtentGraphicsVisibility = new RelayCommand(() =>
            {
                BookmarkExtentGraphicsVisible = !BookmarkExtentGraphicsVisible;
                if (mainDataViewModel.SelectedMapView != null)
                {
                    mainDataViewModel.SelectedMapView.BookmarkExtentGraphicsVisible = BookmarkExtentGraphicsVisible;
                }
            });

            ZoomToLayerCommand = new RelayCommand(async() =>
            {
                var mapView = mainDataViewModel?.SelectedMapView?.MapView;
                if (mapView != null)
                {
                    var extent = mainDataViewModel.SelectedMapView.SelectedLayer.FullExtent;
                    await mapView.SetViewpointAsync(new Viewpoint(extent));
                }
            },
                                                  () => mainDataViewModel?.SelectedMapView?.SelectedLayer != null);

            PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(FilePath))
                {
                    mainDataViewModel.FilePath = FilePath;
                }
                if (args.PropertyName == nameof(MapDrawStatus))
                {
                    AppStatus = MapDrawStatus.ToString();
                }
            };
        }