private async void Initialize() { try { // Create a new Map with a streets basemap. Map myMap = new Map(Basemap.CreateStreets()); // Create the URI to the Service Requests map service. Uri serviceRequestUri = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/MapServer"); // Create a new ArcGISMapImageLayer that uses the service URI. ArcGISMapImageLayer serviceRequestsMapImageLayer = new ArcGISMapImageLayer(serviceRequestUri); // Load all sublayers and tables contained by the map image layer. await serviceRequestsMapImageLayer.LoadTablesAndLayersAsync(); // Set the initial map extent to the extent of all service request features. Envelope requestsExtent = serviceRequestsMapImageLayer.FullExtent; myMap.InitialViewpoint = new Viewpoint(requestsExtent); // Add the layer to the map. myMap.OperationalLayers.Add(serviceRequestsMapImageLayer); // Get the service request comments table from the map image layer. ServiceFeatureTable commentsTable = serviceRequestsMapImageLayer.Tables[0]; // Create query parameters to get all non-null service request comment records (features) from the table. QueryParameters queryToGetNonNullComments = new QueryParameters { WhereClause = "requestid <> '' AND comments <> ''" }; // Query the comments table to get the non-null records. FeatureQueryResult commentQueryResult = await commentsTable.QueryFeaturesAsync(queryToGetNonNullComments, QueryFeatureFields.LoadAll); // Show the records from the service request comments table in the list view control. CommentsListBox.ItemsSource = commentQueryResult.ToList(); // Create a graphics overlay to show selected features and add it to the map view. _selectedFeaturesOverlay = new GraphicsOverlay(); MyMapView.GraphicsOverlays.Add(_selectedFeaturesOverlay); // Assign the map to the MapView. MyMapView.Map = myMap; } catch (Exception e) { Debug.WriteLine(e); } ; }
private async Task Initialize() { // Create a new Map with a streets basemap. Map myMap = new Map(Basemap.CreateStreets()); // Create the URI to the Service Requests map service. Uri serviceRequestUri = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/MapServer"); // Create a new ArcGISMapImageLayer that uses the service URI. ArcGISMapImageLayer serviceRequestsMapImageLayer = new ArcGISMapImageLayer(serviceRequestUri); // Load all sublayers and tables contained by the map image layer. await serviceRequestsMapImageLayer.LoadTablesAndLayersAsync(); // Set the initial map extent to the extent of all service request features. Envelope requestsExtent = serviceRequestsMapImageLayer.FullExtent; myMap.InitialViewpoint = new Viewpoint(requestsExtent); // Add the layer to the map. myMap.OperationalLayers.Add(serviceRequestsMapImageLayer); // Get the service request comments table from the map image layer. ServiceFeatureTable commentsTable = serviceRequestsMapImageLayer.Tables[0]; // Create query parameters to get all non-null service request comment records (features) from the table. QueryParameters queryToGetNonNullComments = new QueryParameters { WhereClause = "requestid <> '' AND comments <> ''" }; // Query the comments table to get the non-null records. FeatureQueryResult commentQueryResult = await commentsTable.QueryFeaturesAsync(queryToGetNonNullComments, QueryFeatureFields.LoadAll); // Store the comments in a list. _commentFeatures = commentQueryResult.ToList(); // Show the comment text from the service request comments records in the list view control. var comments = _commentFeatures.Select(c => c.Attributes["comments"]); ArrayAdapter commentsAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerItem, comments.ToArray()); _commentsListBox.Adapter = commentsAdapter; // Create a graphics overlay to show selected features and add it to the map view. _selectedFeaturesOverlay = new GraphicsOverlay(); _myMapView.GraphicsOverlays.Add(_selectedFeaturesOverlay); // Assign the map to the MapView. _myMapView.Map = myMap; }
private async void Initialize() { // Create a new Map with a vector streets basemap. Map myMap = new Map(Basemap.CreateStreetsVector()); // Create the URI to the Service Requests map service. Uri serviceRequestUri = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/MapServer"); // Create a new ArcGISMapImageLayer that uses the service URI. ArcGISMapImageLayer serviceRequestsMapImageLayer = new ArcGISMapImageLayer(serviceRequestUri); try { // Load all sublayers and tables contained by the map image layer. await serviceRequestsMapImageLayer.LoadTablesAndLayersAsync(); // Set the initial map extent to the extent of all service request features. Envelope requestsExtent = serviceRequestsMapImageLayer.FullExtent; myMap.InitialViewpoint = new Viewpoint(requestsExtent); // Add the layer to the map. myMap.OperationalLayers.Add(serviceRequestsMapImageLayer); // Get the service request comments table from the map image layer. ServiceFeatureTable commentsTable = serviceRequestsMapImageLayer.Tables[0]; // Create query parameters to get all non-null service request comment records (features) from the table. QueryParameters queryToGetNonNullComments = new QueryParameters { WhereClause = "requestid <> '' AND comments <> ''" }; // Query the comments table to get the non-null records. FeatureQueryResult commentQueryResult = await commentsTable.QueryFeaturesAsync(queryToGetNonNullComments, QueryFeatureFields.LoadAll); // Show the records from the service request comments table in the UITableView control. foreach (ArcGISFeature commentFeature in commentQueryResult) { _serviceRequestComments.Add(commentFeature); } // Create the table view source that uses the list of features. _commentsTableSource = new ServiceRequestCommentsTableSource(_serviceRequestComments); // Assign the table view source to the table view control. _tableView.Source = _commentsTableSource; // Subscribe to event. _commentsTableSource.ServiceRequestCommentSelected += CommentsTableSource_ServiceRequestCommentSelected; // Create a graphics overlay to show selected features and add it to the map view. _selectedFeaturesOverlay = new GraphicsOverlay(); _myMapView.GraphicsOverlays.Add(_selectedFeaturesOverlay); // Assign the map to the MapView. _myMapView.Map = myMap; // Reload the table view data to refresh the display. _tableView.ReloadData(); } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private async void submitQuery(UIAlertAction obj) { // If the population value entered is not numeric, warn the user and exit. double populationNumber; if (!double.TryParse(_queryEntry.Text.Trim(), out populationNumber)) { UIAlertController alert = UIAlertController.Create("Invalid number", "Population value must be numeric.", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); return; } // Get the USA map image layer (the first and only operational layer in the map). ArcGISMapImageLayer usaMapImageLayer = (ArcGISMapImageLayer)_myMapView.Map.OperationalLayers[0]; try { // Use a utility method on the map image layer to load all the sublayers and tables. await usaMapImageLayer.LoadTablesAndLayersAsync(); // Get the sublayers of interest (skip 'Highways' since it doesn't have the POP2000 field). ArcGISMapImageSublayer citiesSublayer = (ArcGISMapImageSublayer)usaMapImageLayer.Sublayers[0]; ArcGISMapImageSublayer statesSublayer = (ArcGISMapImageSublayer)usaMapImageLayer.Sublayers[2]; ArcGISMapImageSublayer countiesSublayer = (ArcGISMapImageSublayer)usaMapImageLayer.Sublayers[3]; // Get the service feature table for each of the sublayers. ServiceFeatureTable citiesTable = citiesSublayer.Table; ServiceFeatureTable statesTable = statesSublayer.Table; ServiceFeatureTable countiesTable = countiesSublayer.Table; // Create the query parameters that will find features in the current extent with a population greater than the value entered. QueryParameters populationQuery = new QueryParameters { WhereClause = "POP2000 > " + populationNumber, Geometry = _myMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry }; // Query each of the sublayers with the query parameters. FeatureQueryResult citiesQueryResult = await citiesTable.QueryFeaturesAsync(populationQuery); FeatureQueryResult statesQueryResult = await statesTable.QueryFeaturesAsync(populationQuery); FeatureQueryResult countiesQueryResult = await countiesTable.QueryFeaturesAsync(populationQuery); // Display the selected cities in the graphics overlay. SimpleMarkerSymbol citySymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 16); foreach (Feature city in citiesQueryResult) { Graphic cityGraphic = new Graphic(city.Geometry, citySymbol); _selectedFeaturesOverlay.Graphics.Add(cityGraphic); } // Display the selected counties in the graphics overlay. SimpleLineSymbol countyLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.Cyan, 2); SimpleFillSymbol countySymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.DiagonalCross, Color.Cyan, countyLineSymbol); foreach (Feature county in countiesQueryResult) { Graphic countyGraphic = new Graphic(county.Geometry, countySymbol); _selectedFeaturesOverlay.Graphics.Add(countyGraphic); } // Display the selected states in the graphics overlay. SimpleLineSymbol stateLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.DarkCyan, 6); SimpleFillSymbol stateSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Null, Color.Cyan, stateLineSymbol); foreach (Feature state in statesQueryResult) { Graphic stateGraphic = new Graphic(state.Geometry, stateSymbol); _selectedFeaturesOverlay.Graphics.Add(stateGraphic); } } catch (Exception e) { new UIAlertView("Error", e.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private async void QuerySublayers_Click(object sender, System.Windows.RoutedEventArgs e) { // Clear selected features from the graphics overlay. _selectedFeaturesOverlay.Graphics.Clear(); // If the population value entered is not numeric, warn the user and exit. double populationNumber = 0.0; if (!double.TryParse(PopulationTextBox.Text.Trim(), out populationNumber)) { MessageBox.Show("The population value must be numeric.", "Query error"); return; } // Get the USA map image layer (the first and only operational layer in the map). ArcGISMapImageLayer usaMapImageLayer = (ArcGISMapImageLayer)MyMapView.Map.OperationalLayers[0]; try { // Use a utility method on the map image layer to load all the sublayers and tables. await usaMapImageLayer.LoadTablesAndLayersAsync(); // Get the sublayers of interest (skip 'Highways' since it doesn't have the POP2000 field). ArcGISMapImageSublayer citiesSublayer = (ArcGISMapImageSublayer)usaMapImageLayer.Sublayers[0]; ArcGISMapImageSublayer statesSublayer = (ArcGISMapImageSublayer)usaMapImageLayer.Sublayers[2]; ArcGISMapImageSublayer countiesSublayer = (ArcGISMapImageSublayer)usaMapImageLayer.Sublayers[3]; // Get the service feature table for each of the sublayers. ServiceFeatureTable citiesTable = citiesSublayer.Table; ServiceFeatureTable statesTable = statesSublayer.Table; ServiceFeatureTable countiesTable = countiesSublayer.Table; // Create the query parameters that will find features in the current extent with a population greater than the value entered. QueryParameters populationQuery = new QueryParameters { WhereClause = "POP2000 > " + PopulationTextBox.Text, Geometry = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry }; // Query each of the sublayers with the query parameters. FeatureQueryResult citiesQueryResult = await citiesTable.QueryFeaturesAsync(populationQuery); FeatureQueryResult statesQueryResult = await statesTable.QueryFeaturesAsync(populationQuery); FeatureQueryResult countiesQueryResult = await countiesTable.QueryFeaturesAsync(populationQuery); // Display the selected cities in the graphics overlay. SimpleMarkerSymbol citySymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 16); foreach (Feature city in citiesQueryResult) { Graphic cityGraphic = new Graphic(city.Geometry, citySymbol); _selectedFeaturesOverlay.Graphics.Add(cityGraphic); } // Display the selected counties in the graphics overlay. SimpleLineSymbol countyLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.Cyan, 2); SimpleFillSymbol countySymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.DiagonalCross, Color.Cyan, countyLineSymbol); foreach (Feature county in countiesQueryResult) { Graphic countyGraphic = new Graphic(county.Geometry, countySymbol); _selectedFeaturesOverlay.Graphics.Add(countyGraphic); } // Display the selected states in the graphics overlay. SimpleLineSymbol stateLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.DarkCyan, 6); SimpleFillSymbol stateSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Null, Color.Cyan, stateLineSymbol); foreach (Feature state in statesQueryResult) { Graphic stateGraphic = new Graphic(state.Geometry, stateSymbol); _selectedFeaturesOverlay.Graphics.Add(stateGraphic); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error"); } }