// Creates a feature layer from a local .geodatabase file private async void CreateFeatureLayers() { try { var file = await ApplicationData.Current.LocalFolder.TryGetItemAsync(GdbPath); if (file == null) { throw new Exception("Local geodatabase not found. Please download sample data from 'Sample Data Settings'"); } var gdb = await Geodatabase.OpenAsync(file.Path); var table = gdb.FeatureTables.First(ft => ft.Name == "US-States"); _statesLayer = new FeatureLayer() { ID = table.Name, FeatureTable = table }; MyMapView.Map.Layers.Insert(1, _statesLayer); } catch (Exception ex) { var _x = new MessageDialog("Error creating feature layer: " + ex.Message, "Sample Error").ShowAsync(); } }
private async void AddFeatureLayerToMap(string path) { try { //Open the .geodatabase file var gdb = await Geodatabase.OpenAsync(path); //Loop through each table in the geodatabase foreach (var table in gdb.FeatureTables) { //Create a new featurelayer from each feature table var flayer = new FeatureLayer() { ID = table.Name, DisplayName = table.Name, FeatureTable = table }; //Add each featurelayer to the map MyMapView.Map.Layers.Add(flayer); } } catch (Exception ex) { Console.WriteLine("Cannot Add Layers"); } }
private async void SyncEditsButton_Click(object sender, RoutedEventArgs e) { var gdb = await Geodatabase.OpenAsync(this.LocalDataPathTextBlock.Text); // create a new GeodatabaseSyncTask with the uri of the feature server to pull from var serverUrl = this.featureLayerServiceUrl.Substring(0, this.featureLayerServiceUrl.LastIndexOf('/')); var uri = new Uri(serverUrl); var geodatabaseSyncTask = new GeodatabaseSyncTask(uri); var geodatabaseSyncParams = new SyncGeodatabaseParameters(); geodatabaseSyncParams.SyncDirection = SyncDirection.Bidirectional; var checkStatusInterval = new TimeSpan(0, 0, 3); // Create a System.Progress<T> object to report status as the task executes var progress = new Progress <GeodatabaseStatusInfo>(); progress.ProgressChanged += (s, info) => { this.SyncStatusTextBlock.Text = "Sync edits: " + info.Status; }; this.SyncStatusTextBlock.Text = "Starting sync ..."; this.SyncProgressBar.Visibility = System.Windows.Visibility.Visible; this.SyncStatusPanel.Visibility = System.Windows.Visibility.Visible; var result = await geodatabaseSyncTask.SyncGeodatabaseAsync(geodatabaseSyncParams, gdb, syncCompleteCallback, uploadCompleteCallback, checkStatusInterval, progress, new CancellationToken()); }
private async void CreateFeatureLayers() { var gdb = await Geodatabase.OpenAsync(this.GDB); Envelope extent = null; foreach (var table in gdb.FeatureTables) { var flayer = new FeatureLayer() { ID = table.Name, DisplayName = "Parking Meters", FeatureTable = table }; // OverlayItemsControl overlays = this.mapView.Overlays; // OverlayItemsCollection collection = overlays.Items; // System.Text.StringBuilder sb = new System.Text.StringBuilder(@"<Border CornerRadius=""10"" // xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" // BorderBrush=""Black"" // Margin=""0,0,25,25"" Visibility=""Hidden"" // BorderThickness=""2"" Background=""#995C90B2"" >"); // sb.Append(@" <StackPanel Orientation=""Vertical"" Margin=""5,10,18,15"">"); // sb.Append(@" <StackPanel Orientation=""Horizontal"">"); // sb.Append(@" <TextBlock Text=""ID: "" FontWeight=""Normal"" Height=""20"" Foreground=""White""/>"); // sb.Append(@" <TextBlock Text=""{Binding [POST_ID]}"" FontWeight=""Normal"" "); // sb.Append(@" Foreground=""White"" Height=""20""/>"); // sb.Append(@" </StackPanel>"); // sb.Append(@" <StackPanel Orientation=""Horizontal"">"); // sb.Append(@" <TextBlock Text=""Street: "" FontWeight=""Normal"" Height=""20"" Foreground=""White""/>"); // sb.Append(@" <TextBlock Text=""{Binding [STREETNAME]}"" FontWeight=""Normal"" "); // sb.Append(@" Foreground=""White"" Height=""20""/>"); // sb.Append(@" </StackPanel>"); // sb.Append(@" </StackPanel>"); // sb.Append(@" </Border>"); // System.Windows.FrameworkElement element = // (System.Windows.FrameworkElement)System.Windows.Markup.XamlReader.Parse(sb.ToString()); // collection.Add(element); if (!Geometry.IsNullOrEmpty(table.ServiceInfo.Extent)) { if (Geometry.IsNullOrEmpty(extent)) { extent = table.ServiceInfo.Extent; } else { extent = extent.Union(table.ServiceInfo.Extent); } } this.mapView.Map.Layers.Add(flayer); } await this.mapView.SetViewAsync(extent.Expand(1.10)); }
private async void Initialize() { // NOTE: to be a writable geodatabase, this geodatabase must be generated from a service with a GeodatabaseSyncTask. See the "Generate geodatabase" sample. try { // Create and load geodatabase. string geodatabasePath = DataManager.GetDataFolder("74c0c9fa80f4498c9739cc42531e9948", "loudoun_anno.geodatabase"); Geodatabase geodatabase = await Geodatabase.OpenAsync(geodatabasePath); // Create feature layers from tables in the geodatabase. FeatureLayer addressFeatureLayer = new FeatureLayer(geodatabase.GeodatabaseFeatureTable("Loudoun_Address_Points_1")); FeatureLayer parcelFeatureLayer = new FeatureLayer(geodatabase.GeodatabaseFeatureTable("ParcelLines_1")); // Create annotation layers from tables in the geodatabase. AnnotationLayer addressAnnotationLayer = new AnnotationLayer(geodatabase.GeodatabaseAnnotationTable("Loudoun_Address_PointsAnno_1")); AnnotationLayer parcelAnnotationLayer = new AnnotationLayer(geodatabase.GeodatabaseAnnotationTable("ParcelLinesAnno_1")); // Create a map with the layers. _myMapView.Map = new Map(BasemapStyle.ArcGISLightGray); _myMapView.Map.OperationalLayers.AddRange(new List <Layer> { addressFeatureLayer, parcelFeatureLayer, addressAnnotationLayer, parcelAnnotationLayer }); // Zoom to the extent of the parcels. await parcelFeatureLayer.LoadAsync(); _myMapView.SetViewpoint(new Viewpoint(parcelFeatureLayer.FullExtent)); } catch (Exception ex) { new UIAlertView(ex.GetType().Name, ex.Message, (IUIAlertViewDelegate)null, "Ok", null).Show(); } }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap. _myMapView.Map = new Map(Basemap.CreateStreets()); // Get the path to the downloaded mobile geodatabase (.geodatabase file). string mobileGeodatabaseFilePath = GetMobileGeodatabasePath(); try { // Open the mobile geodatabase. Geodatabase mobileGeodatabase = await Geodatabase.OpenAsync(mobileGeodatabaseFilePath); // Get the 'Trailheads' geodatabase feature table from the mobile geodatabase. GeodatabaseFeatureTable trailheadsGeodatabaseFeatureTable = mobileGeodatabase.GeodatabaseFeatureTable("Trailheads"); // Asynchronously load the 'Trailheads' geodatabase feature table. await trailheadsGeodatabaseFeatureTable.LoadAsync(); // Create a feature layer based on the geodatabase feature table. FeatureLayer trailheadsFeatureLayer = new FeatureLayer(trailheadsGeodatabaseFeatureTable); // Add the feature layer to the operations layers collection of the map. _myMapView.Map.OperationalLayers.Add(trailheadsFeatureLayer); // Zoom the map to the extent of the feature layer. await _myMapView.SetViewpointGeometryAsync(trailheadsFeatureLayer.FullExtent, 50); } catch (Exception e) { new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show(); } }
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 Initialize() { // Create a new map to display in the map view with a streets basemap. _myMapView.Map = new Map(Basemap.CreateStreets()); // Get the path to the downloaded mobile geodatabase (.geodatabase file). string mobileGeodatabaseFilePath = DataManager.GetDataFolder("2b0f9e17105847809dfeb04e3cad69e0", "LA_Trails.geodatabase"); try { // Open the mobile geodatabase. Geodatabase mobileGeodatabase = await Geodatabase.OpenAsync(mobileGeodatabaseFilePath); // Get the 'Trailheads' geodatabase feature table from the mobile geodatabase. GeodatabaseFeatureTable trailheadsGeodatabaseFeatureTable = mobileGeodatabase.GeodatabaseFeatureTable("Trailheads"); // Asynchronously load the 'Trailheads' geodatabase feature table. await trailheadsGeodatabaseFeatureTable.LoadAsync(); // Create a feature layer based on the geodatabase feature table. FeatureLayer trailheadsFeatureLayer = new FeatureLayer(trailheadsGeodatabaseFeatureTable); // Add the feature layer to the operations layers collection of the map. _myMapView.Map.OperationalLayers.Add(trailheadsFeatureLayer); // Zoom the map to the extent of the feature layer. await _myMapView.SetViewpointGeometryAsync(trailheadsFeatureLayer.FullExtent, 50); } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private async void Next_Click(object sender, RoutedEventArgs e) { EMapLayersList = new List <EMapLayers>(); foreach (EngineeringMap emap in _projDef.EngineeringMaps) { string file = _projDef.LocalFilePath + "\\" + emap.LocalGeoDbFileName; if (File.Exists(file)) { EMapLayers eMapLayers = new EMapLayers(); eMapLayers.EMapName = emap.MapID; // Open geodatabase Geodatabase gdb = await Geodatabase.OpenAsync(file); IEnumerable <GeodatabaseFeatureTable> featureTables = gdb.FeatureTables; foreach (var table in featureTables) { eMapLayers.EMapLayerNameList.Add(table.Name); } EMapLayersList.Add(eMapLayers); } } // finish DialogResult = true; Close(); }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap. MyMapView.Map = new Map(Basemap.CreateStreets()); // Get the path to the downloaded mobile geodatabase (.geodatabase file). string mobileGeodatabaseFilePath = GetMobileGeodatabasePath(); // Open the mobile geodatabase. Geodatabase mobileGeodatabase = await Geodatabase.OpenAsync(mobileGeodatabaseFilePath); // Get the 'Trailheads' geodatabase feature table from the mobile geodatabase. GeodatabaseFeatureTable trailheadsGeodatabaseFeatureTable = mobileGeodatabase.GeodatabaseFeatureTable("Trailheads"); // Asynchronously load the 'Trailheads' geodatabase feature table. await trailheadsGeodatabaseFeatureTable.LoadAsync(); // Create a feature layer based on the geodatabase feature table. FeatureLayer trailheadsFeatureLayer = new FeatureLayer(trailheadsGeodatabaseFeatureTable); // Add the feature layer to the operations layers collection of the map. MyMapView.Map.OperationalLayers.Add(trailheadsFeatureLayer); // Zoom the map to the extent of the feature layer. await MyMapView.SetViewpointGeometryAsync(trailheadsFeatureLayer.FullExtent); }
/// <summary> /// Create layers from all tables in given geodatabase. /// </summary> /// <param name="path">Full path to geodatabase</param> /// <returns>Returns list of <see cref="FeatureLayer"/> that are defind in the local geodatabase.</returns> private async Task <List <FeatureLayer> > CreateOfflineOperationalLayersAsync(string path) { var layers = new List <FeatureLayer>(); // When working with files, API differs on Windows Phone / Store and WPF. // This works for WPF and Windows Phone but for Windows Store doesn't // implement FileInfo class so this should be abstracted if targeted for multipatform. //var fileInfo = new FileInfo(path); //if (!fileInfo.Exists) //{ // throw new FileNotFoundException("Geodatabase not found.", path); //} // Open instance of local geodatabase var geodatabase = await Geodatabase.OpenAsync(path); // Loop through all the feature classes / services that are in the geodatabase // and create new FeatureLayer from those foreach (var table in geodatabase.FeatureTables) { var layer = new FeatureLayer() { ID = table.Name, DisplayName = table.Name, FeatureTable = table }; layers.Add(layer); } return(layers); }
private async void Initialize() { // Create a new map to display in the map view with a streets basemap. MyMapView.Map = new Map(BasemapStyle.ArcGISStreets); // Get the path to the downloaded mobile geodatabase (.geodatabase file). string mobileGeodatabaseFilePath = GetMobileGeodatabasePath(); try { // Open the mobile geodatabase. Geodatabase mobileGeodatabase = await Geodatabase.OpenAsync(mobileGeodatabaseFilePath); // Get the 'Trailheads' geodatabase feature table from the mobile geodatabase. GeodatabaseFeatureTable trailheadsGeodatabaseFeatureTable = mobileGeodatabase.GeodatabaseFeatureTable("Trailheads"); // Asynchronously load the 'Trailheads' geodatabase feature table. await trailheadsGeodatabaseFeatureTable.LoadAsync(); // Create a feature layer based on the geodatabase feature table. FeatureLayer trailheadsFeatureLayer = new FeatureLayer(trailheadsGeodatabaseFeatureTable); // Add the feature layer to the operations layers collection of the map. MyMapView.Map.OperationalLayers.Add(trailheadsFeatureLayer); // Zoom the map to the extent of the feature layer. await MyMapView.SetViewpointGeometryAsync(trailheadsFeatureLayer.FullExtent, 50); } catch (Exception e) { await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK"); } }
private async void CreateFeatureLayers() { var gdb = await Geodatabase.OpenAsync(this.GDB); Envelope extent = null; foreach (var table in gdb.FeatureTables) { var flayer = new FeatureLayer() { ID = table.Name, DisplayName = "Parking Meters", FeatureTable = table }; if (!Geometry.IsNullOrEmpty(table.ServiceInfo.Extent)) { if (Geometry.IsNullOrEmpty(extent)) { extent = table.ServiceInfo.Extent; } else { extent = extent.Union(table.ServiceInfo.Extent); } } this.mapView.Map.Layers.Add(flayer); } await this.mapView.SetViewAsync(extent.Expand(1.10)); }
// Create feature layers from the given geodatabase file private async Task CreateFeatureLayersAsync(string gdbPath) { try { var gdb = await Geodatabase.OpenAsync(gdbPath); if (gdb.FeatureTables.Count() == 0) { throw new ApplicationException("Downloaded geodatabase has no feature tables."); } var groupLayer = MyMapView.Map.Layers["Local_Geodatabase"] as GroupLayer; if (groupLayer != null) { MyMapView.Map.Layers.Remove(groupLayer); } groupLayer = new GroupLayer() { ID = "Local_Geodatabase", DisplayName = string.Format("Local ({0})", gdbPath) }; Envelope extent = gdb.FeatureTables.First().Extent; foreach (var table in gdb.FeatureTables) { //if this call is made after FeatureTable is initialized, a call to FeatureLayer.ResetRender will be required. table.UseAdvancedSymbology = true; var flayer = new FeatureLayer() { ID = table.Name, DisplayName = string.Format("{0} ({1})", table.Name, table.RowCount), FeatureTable = table }; if (table.Extent != null) { if (extent == null) { extent = table.Extent; } else { extent = extent.Union(table.Extent); } } groupLayer.ChildLayers.Add(flayer); } MyMapView.Map.Layers.Add(groupLayer); await MyMapView.SetViewAsync(extent.Expand(1.10)); } catch (Exception ex) { MessageBox.Show("Error creating feature layer: " + ex.Message, "Sample Error"); } }
// Create feature layers from the given geodatabase file private async Task CreateFeatureLayersAsync(string gdbPath) { try { var gdb = await Geodatabase.OpenAsync(gdbPath); if (gdb.FeatureTables.Count() == 0) { throw new ApplicationException("Downloaded geodatabase has no feature tables."); } var groupLayer = mapView.Map.Layers["Local_Geodatabase"] as GroupLayer; if (groupLayer != null) { mapView.Map.Layers.Remove(groupLayer); } groupLayer = new GroupLayer() { ID = "Local_Geodatabase", DisplayName = string.Format("Local ({0})", gdbPath) }; Envelope extent = new Envelope(); foreach (var table in gdb.FeatureTables) { var flayer = new FeatureLayer() { ID = table.Name, DisplayName = string.Format("{0} ({1})", table.Name, table.RowCount), FeatureTable = table }; if (table.Extent != null) { if (extent == null) { extent = table.Extent; } else { extent = extent.Union(table.Extent); } } groupLayer.ChildLayers.Add(flayer); } mapView.Map.Layers.Add(groupLayer); await mapView.SetViewAsync(extent.Expand(1.10)); } catch (Exception ex) { MessageBox.Show("Error creating feature layer: " + ex.Message, "Sample Error"); } }
private async void Initialize() { // Create new Map with basemap Map myMap = new Map(Basemap.CreateTopographic()); // Provide Map to the MapView _myMapView.Map = myMap; // Get the path to the geodatabase string geodbFilePath = GetGeodatabasePath(); // Load the geodatabase from local storage Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath); // Get the path to the symbol dictionary string symbolFilepath = GetStyleDictionaryPath(); try { // Load the symbol dictionary from local storage // Note that the type of the symbol definition must be explicitly provided along with the file name DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.OpenAsync("mil2525d", symbolFilepath); // Add geodatabase features to the map, using the defined symbology foreach (FeatureTable table in baseGeodatabase.GeodatabaseFeatureTables) { // Load the table await table.LoadAsync(); // Create the feature layer from the table FeatureLayer myLayer = new FeatureLayer(table); // Load the layer await myLayer.LoadAsync(); // Create a Dictionary Renderer using the DictionarySymbolStyle DictionaryRenderer dictRenderer = new DictionaryRenderer(symbolStyle); // Apply the dictionary renderer to the layer myLayer.Renderer = dictRenderer; // Add the layer to the map myMap.OperationalLayers.Add(myLayer); } // Create geometry for the center of the map MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857)); // Set the map's viewpoint to highlight the desired content _myMapView.SetViewpoint(new Viewpoint(centerGeometry, 201555)); } catch (Exception e) { new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show(); } }
private async void MapsCB_SelectionChanged(object sender, SelectionChangedEventArgs e) { EngineeringMap emap = MapsCB.SelectedItem as EngineeringMap; if (emap == null) { return; } List <LayerDef> lyrsDef = emap.LocalGdbLayersDef; LayerDef lyrDef = lyrsDef.Find(x => x.Name == _lyrName); if (lyrDef == null) { return; } // load tiled layer // string file = _prjDef.LocalTilePath + "\\" + emap.LocalTileFileName1; if (File.Exists(file)) { ArcGISLocalTiledLayer newLayr = new ArcGISLocalTiledLayer(file); newLayr.ID = "TiledLayer1"; newLayr.DisplayName = "TileLayer1"; Map.Layers.Add(newLayr); //if (newLayr.FullExtent != null) //{ // MyMapView.SetView(newLayr.FullExtent); //} } // load the specified layer // file = _prjDef.LocalFilePath + "\\" + emap.LocalGeoDbFileName; if (File.Exists(file)) { // Open geodatabase Geodatabase gdb = await Geodatabase.OpenAsync(file); IEnumerable <GeodatabaseFeatureTable> featureTables = gdb.FeatureTables; foreach (var table in featureTables) { if (table.Name == _lyrName) { // Add the feature layer to the map await GdbHelper.addGeodatabaseLayer(Map, lyrDef, table); MyMapView.SetView(table.Extent); break; } } } }
// 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; } }
private async void Initialize() { // Create new Map with basemap Map myMap = new Map(Basemap.CreateTopographic()); // Provide Map to the MapView MyMapView.Map = myMap; // Get the path to the geodatabase string geodbFilePath = GetGeodatabasePath(); // Load the geodatabase from local storage Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath); // Get the path to the symbol dictionary string symbolFilepath = GetStyleDictionaryPath(); try { // Load the symbol dictionary from local storage DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.CreateFromFileAsync(symbolFilepath); // Add geodatabase features to the map, using the defined symbology foreach (FeatureTable table in baseGeodatabase.GeodatabaseFeatureTables) { // Load the table await table.LoadAsync(); // Create the feature layer from the table FeatureLayer myLayer = new FeatureLayer(table); // Load the layer await myLayer.LoadAsync(); // Create a Dictionary Renderer using the DictionarySymbolStyle DictionaryRenderer dictRenderer = new DictionaryRenderer(symbolStyle); // Apply the dictionary renderer to the layer myLayer.Renderer = dictRenderer; // Add the layer to the map myMap.OperationalLayers.Add(myLayer); } // Create geometry for the center of the map MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857)); // Set the map's viewpoint to highlight the desired content MyMapView.SetViewpoint(new Viewpoint(centerGeometry, 201555)); } catch (Exception e) { await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK"); } }
private async void Initialize() { // Create new Map with basemap. Map map = new Map(Basemap.CreateTopographic()); // Provide Map to the MapView. _myMapView.Map = map; // Get the path to the geodatabase. string geodbFilePath = DataManager.GetDataFolder("e0d41b4b409a49a5a7ba11939d8535dc", "militaryoverlay.geodatabase"); // Load the geodatabase from local storage. Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath); // Get the path to the symbol dictionary. string symbolFilepath = DataManager.GetDataFolder("e34835bf5ec5430da7cf16bb8c0b075c", "mil2525d.stylx"); try { // Load the symbol dictionary from local storage. // Note that the type of the symbol definition must be explicitly provided along with the file name. DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.OpenAsync("mil2525d", symbolFilepath); // Add geodatabase features to the map, using the defined symbology. foreach (GeodatabaseFeatureTable table in baseGeodatabase.GeodatabaseFeatureTables) { // Load the table. await table.LoadAsync(); // Create the feature layer from the table. FeatureLayer layer = new FeatureLayer(table); // Load the layer. await layer.LoadAsync(); // Create and use a Dictionary Renderer using the DictionarySymbolStyle. layer.Renderer = new DictionaryRenderer(symbolStyle); // Add the layer to the map. map.OperationalLayers.Add(layer); } // Create geometry for the center of the map. MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857)); // Set the map's viewpoint to highlight the desired content. _myMapView.SetViewpoint(new Viewpoint(centerGeometry, 201555)); } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
// Generate / download and display layers from a generated geodatabase private async Task GenerateLocalGeodatabaseAsync(Envelope extent) { try { IsBusy = true; ReportStatus("Creating GeodatabaseSyncTask..."); var syncTask = new GeodatabaseSyncTask(new Uri(BASE_URL)); var options = new GenerateGeodatabaseParameters(new int[] { 1 }, extent) { GeodatabasePrefixName = GDB_PREFIX, ReturnAttachments = false, OutSpatialReference = extent.SpatialReference, SyncModel = SyncModel.PerLayer }; var tcs = new TaskCompletionSource <GeodatabaseStatusInfo>(); Action <GeodatabaseStatusInfo, Exception> completionAction = (info, ex) => { if (ex != null) { tcs.SetException(ex); } tcs.SetResult(info); }; var generationProgress = new Progress <GeodatabaseStatusInfo>(); generationProgress.ProgressChanged += (sndr, sts) => { SecondaryStatus = sts.Status.ToString(); }; ReportStatus("Starting GenerateGeodatabase..."); var result = await syncTask.GenerateGeodatabaseAsync(options, completionAction, TimeSpan.FromSeconds(3), generationProgress, CancellationToken.None); ReportStatus("Waiting on geodatabase from server..."); var statusResult = await tcs.Task; ReportStatus("Downloading Geodatabase..."); await DownloadGeodatabaseAsync(statusResult); ReportStatus("Opening Geodatabase..."); var gdb = await Geodatabase.OpenAsync(_gdbPath); ReportStatus("Create local feature layers..."); await CreateFeatureLayers(gdb); _onlineBirdsLayer.IsVisible = false; } finally { IsBusy = false; } }
async Task addLocalGeoDbFile(string filePath) { if (File.Exists(filePath)) { Geodatabase gdb = await Geodatabase.OpenAsync(filePath); foreach (var layerDef in _eMap.LocalGdbLayersDef) { await addGeodatabaseLayer(layerDef, gdb); } } }
/// <summary> /// Adds a SQLite geodatabase to the list of layers. /// </summary> /// <param name="pathToGeodatabase">the file to be loaded</param> /// <returns>simply a marker indicating that things completed (true all good, false not all good)</returns> public async Task <bool> AddSQLiteGeodatabaseAsync(string pathToGeodatabase) { bool allGood = true; if (!this.HasLayerFileSource(pathToGeodatabase)) { LayerFileSource lfs = new LayerFileSource(); lfs.SourceFile = pathToGeodatabase; this.LayerFileSources.Add(lfs); Geodatabase gdb = await Geodatabase.OpenAsync(pathToGeodatabase); // // Store the test layers. // foreach (GeodatabaseFeatureTable gft in gdb.GeodatabaseFeatureTables) { TesterLayer testLayer = new TesterLayer(); testLayer.FeatureTable = gft; gft.PropertyChanged += GeodbFeatTab_PropertyChanged; lfs.Children.Add(testLayer); } // // Now load them all. // foreach (TesterLayer tl in lfs.Children) { GeodatabaseFeatureTable gtab = tl.FeatureTable; try { await gtab.LoadAsync(); FeatureLayer fLayer = new FeatureLayer(gtab); fLayer.PropertyChanged += FeatureLayer_PropertyChanged; await fLayer.LoadAsync(); fLayer.LabelsEnabled = true; this.Map.OperationalLayers.Add(fLayer); tl.FeatureLayer = fLayer; } catch (Exception exc) { tl.LayerLoadException = exc; allGood = false; tl.LoadDone = true; } } } return(allGood); }
private async void Initialize() { // Create new Map with basemap Map myMap = new Map(Basemap.CreateTopographic()); // Provide Map to the MapView MyMapView.Map = myMap; // Create geometry for the center of the map MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857)); // Set the map's viewpoint to highlight the desired content await MyMapView.SetViewpointCenterAsync(centerGeometry); await MyMapView.SetViewpointScaleAsync(201555.279); // Get the path to the geodatabase string geodbFilePath = await GetPreparedFilePath(_geodatabaseName, _geodatabaseId); // Load the geodatabase from local storage Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath); // Get the path to the symbol dictionary string symbolFilepath = await GetPreparedFilePath(_symbolDefName, _symbolDefId); // Load the symbol dictionary from local storage // Note that the type of the symbol definition must be explicitly provided along with the file name DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.OpenAsync("mil2525d", symbolFilepath); // Add geodatabase features to the map, using the defined symbology foreach (FeatureTable table in baseGeodatabase.GeodatabaseFeatureTables) { // Load the table await table.LoadAsync(); // Create the feature layer from the table FeatureLayer myLayer = new FeatureLayer(table); // Load the layer await myLayer.LoadAsync(); // Create a Dictionary Renderer using the DictionarySymbolStyle DictionaryRenderer dictRenderer = new DictionaryRenderer(symbolStyle); // Apply the dictionary renderer to the layer myLayer.Renderer = dictRenderer; // Add the layer to the map myMap.OperationalLayers.Add(myLayer); } }
/// <summary> /// Executes ViewModel initialization logic. Called when ViewModel is created from base view model. /// </summary> protected override async Task InitializeAsync() { // Create map with layers Map = new Map() { InitialExtent = new Envelope(-14161146.113642, 3137996.40676956, -7626168.31478212, 6574986.2928574) }; // Basemap layer from ArcGIS Online hosted service var basemap = new ArcGISLocalTiledLayer() { ID = "Basemap", DisplayName = "Basemap", Path = @"../../../../Data/TileCaches/Topographic.tpk" }; // Initialize layer in Try - Catch Exception exceptionToHandle = null; try { await basemap.InitializeAsync(); Map.Layers.Add(basemap); // Open geodatbase and find States feature table var geodatabase = await Geodatabase.OpenAsync(@"../../../../Data/Databases/usa.geodatabase"); _featureTable = geodatabase.FeatureTables.First(x => x.Name == "States"); // Create graphics layer for start and endpoints CreateGraphicsLayers(); IsInitialized = true; } catch (Exception exception) { // Exception is thrown ie if layer url is not found - ie. {"Error code '400' : 'Invalid URL'"} exceptionToHandle = exception; } if (exceptionToHandle != null) { // Initialization failed, show message and return await MessageService.Instance.ShowMessage(string.Format( "Could not create basemap. Error = {0}", exceptionToHandle.ToString()), "An error occured"); return; } }
/// <summary>Add feature tables from a local geodatabase as layers on the map</summary> private async void MyMapView_ExtentChanged(object sender, EventArgs e) { MyMapView.ExtentChanged -= MyMapView_ExtentChanged; try { var gdbFile = await ApplicationData.Current.LocalFolder.TryGetItemAsync(LOCAL_GDB_PATH); if (gdbFile == null) { throw new Exception("Local geodatabase not found. Please download sample data from 'Sample Data Settings'"); } var gdb = await Geodatabase.OpenAsync(gdbFile.Path); Envelope extent = gdb.FeatureTables.First().Extent; foreach (var table in gdb.FeatureTables) { var flayer = new FeatureLayer() { ID = table.Name, DisplayName = table.Name, FeatureTable = table }; if (table.Extent != null) { if (extent == null) { extent = table.Extent; } else { extent = extent.Union(table.Extent); } } MyMapView.Map.Layers.Add(flayer); } if (!extent.IsEmpty) { await MyMapView.SetViewAsync(extent.Expand(1.10)); } } catch (Exception ex) { var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } }
// Creates a feature layer from a local .geodatabase file private async Task CreateFeatureLayersAsync() { try { var gdb = await Geodatabase.OpenAsync(GDB_PATH); var table = gdb.FeatureTables.First(ft => ft.Name == "US-States"); _statesLayer = new FeatureLayer() { ID = table.Name, FeatureTable = table }; mapView.Map.Layers.Insert(1, _statesLayer); } catch (Exception ex) { MessageBox.Show("Error creating feature layer: " + ex.Message, "Samples"); } }
// Creates a feature layer from a local .geodatabase file private async void CreateFeatureLayers() { try { var gdb = await Geodatabase.OpenAsync(GDB_PATH); var table = gdb.FeatureTables.First(ft => ft.Name == "US-States"); _statesLayer = new FeatureLayer() { ID = table.Name, FeatureTable = table }; MyMapView.Map.Layers.Add(_statesLayer); } catch (Exception ex) { MessageBox.Show("Error creating feature layer: " + ex.Message, "Geometry Difference Sample"); } }
/// <summary> /// /// </summary> /// <returns></returns> public async Task DeleteReplicaFolderAsync() { var folderPath = GetReplicaFullPath(); try { var folders = Directory.GetDirectories(folderPath); foreach (var f in folders) { if (f.Contains("p13")) { var gdbs = Directory.GetFiles(f); foreach (var file in gdbs) { try { if (file.Contains(".geodatabase")) { var gdb = await Geodatabase.OpenAsync(file); gdb.Close(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } } if (MobileMapPackage != null) { MobileMapPackage.Close(); } Directory.Delete(folderPath, true); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public async Task <IGraphicsLayer> addGdbLayer(LayerDef eLayer, string dbFile, int start = 0, int maxFeatures = 0) { if (dbFile == null) { dbFile = _eMap.LocalGeoDbFileName; } string filePath = _prj.projDef.LocalFilePath + "\\" + dbFile; if (File.Exists(filePath)) { Geodatabase gdb = await Geodatabase.OpenAsync(filePath); IGraphicsLayer gLayer = await addGeodatabaseLayer( eLayer, gdb, start, maxFeatures); return(gLayer); } return(null); }