Exemple #1
0
        async void LoadGeoDb(EngineeringMap emap)
        {
            string file = ProjDef.LocalFilePath + "\\" + emap.LocalGeoDbFileName;

            if (File.Exists(file))
            {
                Geodatabase gdb = await Geodatabase.OpenAsync(file);

                IEnumerable <GeodatabaseFeatureTable> featureTables =
                    gdb.FeatureTables;
                List <GdbLayer> gdbLayers = new List <GdbLayer>();
                foreach (var table in featureTables)
                {
                    GdbLayer layer = new GdbLayer();
                    layer.Name         = table.Name;
                    layer.Visibility   = false;
                    layer.FeatureTable = table;
                    gdbLayers.Add(layer);

                    LayerDef lyrDef = emap.LocalGdbLayersDef.Find(x => x.Name == table.Name);
                    if (lyrDef == null)
                    {
                        lyrDef = GdbHelper.GenerateDefaultLayerDef(table);
                        emap.LocalGdbLayersDef.Add(lyrDef);
                    }
                    await GdbHelper.addGeodatabaseLayer(Map, lyrDef, table);
                }

                GeoDBLayrList.ItemsSource = gdbLayers;
            }
        }
        private async void LyrSetting_Click(object sender, RoutedEventArgs e)
        {
            EngineeringMap emap = EMapsLB.SelectedItem as EngineeringMap;

            if (emap == null)
            {
                return;
            }

            GdbLayer gdbLyr = GeoDBLayrLB.SelectedItem as GdbLayer;

            if (gdbLyr == null)
            {
                return;
            }

            LayerDef lyrDef = emap.LocalGdbLayersDef.Find(x => x.Name == gdbLyr.Name);

            LayerDefWindow lyrDefWnd = new LayerDefWindow(lyrDef);

            lyrDefWnd.Owner = this;
            lyrDefWnd.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            bool?success = lyrDefWnd.ShowDialog();

            if (success != null && success.Value == true)
            {
                Layer lyr = Map.Layers[gdbLyr.Name];
                if (lyr != null)
                {
                    // Reload the layer
                    Map.Layers.Remove(lyr);
                    await GdbHelper.addGeodatabaseLayer(Map, lyrDef, gdbLyr.FeatureTable);
                }
            }
        }
        private void LayerCB_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.CheckBox chkBox = sender as System.Windows.Controls.CheckBox;

            // Click => Switch the layer on/off
            GdbLayer gdbLyr = chkBox.Tag as GdbLayer;
            Layer    lyr    = Map.Layers[gdbLyr.Name];

            lyr.IsVisible = chkBox.IsChecked.Value;

            // Update layer definition
            EngineeringMap emap = EMapsLB.SelectedItem as EngineeringMap;

            if (emap == null)
            {
                return;
            }
            LayerDef lyrDef = emap.LocalGdbLayersDef.Find(x => x.Name == gdbLyr.Name);

            if (lyrDef == null)
            {
                return;
            }
            lyrDef.IsVisible = chkBox.IsChecked.Value;
        }
        private void LayrCB_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Controls.CheckBox chkBox = sender as System.Windows.Controls.CheckBox;

            // Double click => Zoom to the layer
            GdbLayer gdbLayer = chkBox.Tag as GdbLayer;

            MyMapView.SetView(gdbLayer.Extent);
        }
        // Load the specifiled emap's geodatabase, and add all the features layers to the map.
        //
        async Task ReloadGeoDb(EngineeringMap emap)
        {
            // Clear existing Local GeoDB layers
            if (GeoDBLayrLB.ItemsSource != null)
            {
                foreach (var item in GeoDBLayrLB.ItemsSource)
                {
                    GdbLayer lyr    = item as GdbLayer;
                    Layer    mapLyr = Map.Layers[lyr.Name];
                    if (mapLyr != null)
                    {
                        Map.Layers.Remove(mapLyr);
                    }
                }
                GeoDBLayrLB.ItemsSource = null;
            }

            // Load new
            string file = _projDef.LocalFilePath + "\\" + emap.LocalGeoDbFileName;

            if (File.Exists(file))
            {
                // Open geodatabase
                Geodatabase gdb = await Geodatabase.OpenAsync(file);

                IEnumerable <GeodatabaseFeatureTable> featureTables =
                    gdb.FeatureTables;
                List <GdbLayer> gdbLayers = new List <GdbLayer>();
                foreach (var table in featureTables)
                {
                    // Search LayerDef, use default if not found.
                    LayerDef lyrDef = emap.LocalGdbLayersDef.Find(x => x.Name == table.Name);
                    if (lyrDef == null)
                    {
                        lyrDef = GdbHelper.GenerateDefaultLayerDef(table);
                        emap.LocalGdbLayersDef.Add(lyrDef);
                    }

                    // GdbLayer is used for UI binding and selection operations.
                    GdbLayer layer = new GdbLayer();
                    layer.Name         = table.Name;
                    layer.Visibility   = lyrDef.IsVisible;
                    layer.LayerObject  = layer;
                    layer.FeatureTable = table;
                    layer.Extent       = table.Extent;
                    gdbLayers.Add(layer);


                    // Add the feature layer to the map
                    await GdbHelper.addGeodatabaseLayer(Map, lyrDef, table);
                }

                // Refresh UI
                GeoDBLayrLB.ItemsSource = gdbLayers;
            }
        }