// Continually accepts user-entered points // - Buffered polygons are created from the points and added to the graphics layer private async Task AcceptClassPointsAsync() { // Get current viewpoints extent from the MapView var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry); var viewpointExtent = currentViewpoint.TargetGeometry.Extent; try { while (true) { var point = await MyMapView.Editor.RequestPointAsync(); var polygon = GeometryEngine.Buffer(point, viewpointExtent.Width * .01); var attr = new Dictionary <string, object>() { { "ID", _graphicsOverlay.Graphics.Count + 1 } }; _graphicsOverlay.Graphics.Add(new Graphic(polygon, attr)); } } catch (TaskCanceledException) { } catch (Exception ex) { var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } }
private void OnView_Tapped(object sender, Esri.ArcGISRuntime.UI.GeoViewInputEventArgs e) { MapPoint geoPoint = getGeoPoint(e); geoPoint = (MapPoint)GeometryEngine.Project(geoPoint, SpatialReference.Create(3857)); Polygon buffer = (Polygon)GeometryEngine.Buffer(geoPoint, 1000.0); GraphicCollection graphics = (threeD ? bufferAndQuerySceneGraphics : bufferAndQueryMapGraphics).Graphics; graphics.Clear(); graphics.Add(new Graphic(buffer, BUFFER_SYMBOL)); graphics.Add(new Graphic(geoPoint, CLICK_SYMBOL)); Esri.ArcGISRuntime.Data.QueryParameters query = new Esri.ArcGISRuntime.Data.QueryParameters(); query.Geometry = buffer; LayerCollection operationalLayers; if (threeD) { operationalLayers = sceneView.Scene.OperationalLayers; } else { operationalLayers = mapView.Map.OperationalLayers; } foreach (Layer layer in operationalLayers) { ((FeatureLayer)layer).SelectFeaturesAsync(query, SelectionMode.New); } }
private void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e) { try { // get the map overlay element by name var mapOverlay = this.FindName("mapTip") as FrameworkElement; // verify that the overlay was found if (mapOverlay == null) { return; } mapOverlay.Visibility = System.Windows.Visibility.Collapsed; // get the location tapped on the map var mapPoint = e.Location; // get a buffer that is about 8 pixels in equivalent map distance var mapUnitsPerPixel = this.MyMapView.Extent.Width / this.MyMapView.ActualWidth; var bufferDist = mapUnitsPerPixel * 8; var searchBuffer = GeometryEngine.Buffer(mapPoint, bufferDist); if (UseOnlineDataOption.IsChecked == true) { this.QueryOnline(mapOverlay, searchBuffer); } else { this.QueryOffline(mapOverlay, searchBuffer); } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
void mapView1_MapViewTapped(object sender, MapViewInputEventArgs e) { graphicsLayer.Graphics.Clear(); try { var pointGeom = e.Location; var bufferGeom = GeometryEngine.Buffer(pointGeom, 5 * milesToMetersConversion); //show geometries on map if (graphicsLayer != null) { var pointGraphic = new Graphic { Geometry = pointGeom, Symbol = pms }; graphicsLayer.Graphics.Add(pointGraphic); var bufferGraphic = new Graphic { Geometry = bufferGeom, Symbol = sfs }; graphicsLayer.Graphics.Add(bufferGraphic); } } catch (Exception ex) { var dlg = new MessageDialog(ex.Message, "Geometry Engine Failed!"); var _ = dlg.ShowAsync(); } }
private GraphicsLayer CreateBuffer(int layerIndex, Color color, double radius) { if (MyMapView.Map.Layers[layerIndex] is FeatureLayer fLayer) { var fTable = fLayer.FeatureTable; var filter = new QueryFilter { WhereClause = "1=1" }; var features = fTable.QueryAsync(filter).Result; var bufferGrLayer = new GraphicsLayer() { ID = fLayer.ID + "Buffer", DisplayName = fLayer.DisplayName + "Buffer" }; MyMapView.Map.Layers.Add(bufferGrLayer); AddItemToListBox(bufferGrLayer.DisplayName); var geometries = features.Select(feature => feature.Geometry); double metersToDegrees = 1d / 111.325 / 1000; foreach (var geometry in geometries) { Esri.ArcGISRuntime.Geometry.Geometry geometryBuffer = GeometryEngine.Buffer(geometry, radius * metersToDegrees); Symbol bufferSymbol = GetGraphicStyle(color); bufferGrLayer.Graphics.Add(new Graphic(geometryBuffer, bufferSymbol)); } return(bufferGrLayer); } else { throw new Exception("Fail"); } }
void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e) { try { _graphicsOverlay.Graphics.Clear(); var pointGeom = e.Location; var bufferGeom = GeometryEngine.Buffer(pointGeom, 5 * milesToMetersConversion); //show geometries on map if (_graphicsOverlay != null) { var pointGraphic = new Graphic { Geometry = pointGeom, Symbol = _pms }; _graphicsOverlay.Graphics.Add(pointGraphic); var bufferGraphic = new Graphic { Geometry = bufferGeom, Symbol = _sfs }; _graphicsOverlay.Graphics.Add(bufferGraphic); } } catch (Exception ex) { var _x = new MessageDialog(ex.Message, "Geometry Engine Failed!").ShowAsync(); } }
// buffer the click point, query the map service with the buffer geometry as the filter and add graphics to the map private async void mapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e) { try { graphicsLayer.Graphics.Add(new Graphic(e.Location)); var bufferResult = GeometryEngine.Buffer(e.Location, 100); bufferLayer.Graphics.Add(new Graphic(bufferResult)); var queryTask = new QueryTask( new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2")); var query = new Query("1=1") { ReturnGeometry = true, OutSpatialReference = mapView.SpatialReference, Geometry = bufferResult }; query.OutFields.Add("OWNERNME1"); var queryResult = await queryTask.ExecuteAsync(query); if (queryResult != null && queryResult.FeatureSet != null) { parcelLayer.Graphics.AddRange(queryResult.FeatureSet.Features); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Spatial Query Sample"); } }
//create point at click private void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { MyOverlay.Graphics.Clear(); //get clicked point var point = e.Location; var graphic = new Graphic(point, m_pmsYAH); int mile = 4; //create 1 mile (radius) buffer around point var buffer = GeometryEngine.Buffer(point, 1609.34 / mile); //create symbol for buffer var buffSym = new SimpleLineSymbol(); buffSym.Color = Colors.Purple; buffSym.Style = SimpleLineSymbolStyle.Dash; buffSym.Width = 2; //create buffer graphic var buffer_graphic = new Graphic(buffer, buffSym); //add graphics to map MyOverlay.Graphics.Add(graphic); MyOverlay.Graphics.Add(buffer_graphic); //query nearest bars QueryFeatures(buffer, point); }
private void mapView_MouseDown(object sender, MouseButtonEventArgs e) { try { graphicsLayer.Graphics.Clear(); // Convert screen point to map point var point = mapView.ScreenToLocation(e.GetPosition(mapView)); var buffer = GeometryEngine.Buffer(point, 5 * MILES_TO_METERS); //show geometries on map if (graphicsLayer != null) { var pointGraphic = new Graphic { Geometry = point, Symbol = _pinSymbol }; graphicsLayer.Graphics.Add(pointGraphic); var bufferGraphic = new Graphic { Geometry = buffer, Symbol = _bufferSymbol }; graphicsLayer.Graphics.Add(bufferGraphic); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Geometry Engine Failed!"); } }
private void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e) { try { _graphicOverlay.Graphics.Clear(); // Convert screen point to map point var point = e.Location; var buffer = GeometryEngine.Buffer(point, 5 * MILES_TO_METERS); var bufferGraphic = new Graphic { Geometry = buffer, Symbol = _bufferSymbol }; _graphicOverlay.Graphics.Add(bufferGraphic); var pointGraphic = new Graphic { Geometry = point, Symbol = _pinSymbol }; _graphicOverlay.Graphics.Add(pointGraphic); } catch (Exception ex) { MessageBox.Show(ex.Message, "Geometry Engine Failed!"); } }
public static int GetContainedCount(List <Esri.ArcGISRuntime.Geometry.Geometry> countableGeometries, Esri.ArcGISRuntime.Geometry.Geometry containingPolygon, int bufferInMeters = 0) { var count = 0; if (countableGeometries == null) { return(count); } var polyCorrected = GeometryEngine.RemoveZAndM(containingPolygon); polyCorrected = Esri.ArcGISRuntime.Geometry.Geometry.FromJson(polyCorrected.ToJson()); polyCorrected = GeometryEngine.Buffer(polyCorrected, bufferInMeters); foreach (var geom in countableGeometries) { if (polyCorrected.SpatialReference != geom.SpatialReference) { polyCorrected = GeometryEngine.Project(polyCorrected, geom.SpatialReference); } var geomCorrected = GeometryEngine.RemoveZAndM(geom); geomCorrected = Esri.ArcGISRuntime.Geometry.Geometry.FromJson(geomCorrected.ToJson()); var isContained = Esri.ArcGISRuntime.Geometry.GeometryEngine.Contains(polyCorrected, geomCorrected); count += isContained ? 1 : 0; } return(count); }
public async void SearchByMeterID(string searchString) { SimpleLineSymbol sls = new SimpleLineSymbol() { Color = System.Windows.Media.Colors.Red, Style = SimpleLineStyle.Solid, Width = 2 }; // get the layer and table FeatureLayer featureLayer = this.mapView.Map.Layers[1] as FeatureLayer; GeodatabaseFeatureTable table = featureLayer.FeatureTable as GeodatabaseFeatureTable; // Define an attribute query var filter = new Esri.ArcGISRuntime.Data.QueryFilter(); filter.WhereClause = "POST_ID = '" + searchString + "'"; // 666-13080 // Execute the query and await results IEnumerable <Feature> features = await table.QueryAsync(filter); // iterate the feature. Should be one in this case. foreach (Feature feature in features) { // Get the MapPoint, Project to Mercator so that we are working in meters MapPoint mapPoint = feature.Geometry as MapPoint; MapPoint pointMercator = GeometryEngine.Project(mapPoint, SpatialReferences.WebMercator) as MapPoint; Geometry polygon = GeometryEngine.Buffer(pointMercator, 200); // Re-project the polygon to WGS84 so that we can query against the layer which is in WGS84 Polygon polygonWgs84 = GeometryEngine.Project(polygon, SpatialReferences.Wgs84) as Polygon; // add the circle (buffer) Graphic graphic = new Graphic(); graphic.Symbol = sls; graphic.Geometry = polygonWgs84; this.graphicsLayer.Graphics.Add(graphic); // Make sure the table supports querying if (table.SupportsQuery) { // setup the query to use the polygon that's in WGS84 var query = new Esri.ArcGISRuntime.Data.SpatialQueryFilter(); query.Geometry = polygonWgs84 as Geometry; query.SpatialRelationship = SpatialRelationship.Intersects; var result = await table.QueryAsync(query); int i = 1; // Loop through query results foreach (Esri.ArcGISRuntime.Data.Feature f in result) { // do something with results System.Diagnostics.Debug.WriteLine(i.ToString()); i++; } } } }
private async void OnMapViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { try { Console.WriteLine("タップしました"); // 2回目以降の検索時でフィーチャが選択されている場合は、選択を解除 if (myFeatures != null && myFeatures.Count() != 0) { myFeatureLayer.UnselectFeatures(myFeatures); } // グラフィック オーバレイに追加したグラフィックを削除 myGraphicsOverlay.Graphics.Clear(); // タップした地点から1000メートルのバッファーの円を作成し、グラフィックとして表示する var buffer = GeometryEngine.Buffer(e.Location, 1000); var outLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.DashDot, System.Drawing.Color.Yellow, 5); var fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Null, System.Drawing.Color.White, outLineSymbol); var graphic = new Graphic(buffer, null, fillSymbol); myGraphicsOverlay.Graphics.Add(graphic); // フィーチャの検索用のパラメーターを作成 var queryParams = new QueryParameters(); // 検索範囲を作成したバファーの円に指定 queryParams.Geometry = buffer; // 検索範囲とフィーチャの空間的な関係性を指定(バファーの円の中にフィーチャが含まれる) queryParams.SpatialRelationship = SpatialRelationship.Contains; // フィーチャの検索を実行 FeatureQueryResult queryResult = await myFeatureLayer.FeatureTable.QueryFeaturesAsync(queryParams); var alertString = ""; // 検索結果のフィーチャのリストを取得 myFeatures = queryResult.ToList(); // 検索結果のフィーチャを選択(ハイライト表示) myFeatureLayer.SelectFeatures(myFeatures); for (int i = 0; i < myFeatures.Count; ++i) { Feature feature = myFeatures[i]; // フィーチャの"Name"フィールドの属性値を取得 var nameStr = feature.GetAttributeValue("物件名"); alertString = alertString + Environment.NewLine + nameStr; Console.WriteLine(nameStr); } // 取得した属性値をアラート表示 await DisplayAlert("検索結果", alertString, "OK"); } catch (Exception ex) { await DisplayAlert("検索のエラー", ex.ToString(), "OK"); } }
// buffer the click point, query the map service with the buffer geometry as the filter and add graphics to the map private async void MyMapView_Tapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e) { try { var graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"]; if (!(graphicsOverlay.Graphics.Count == 0)) { graphicsOverlay.Graphics.Clear(); } graphicsOverlay.Graphics.Add(new Graphic() { Geometry = e.Location }); var bufferOverlay = MyMapView.GraphicsOverlays["bufferOverlay"]; if (!(bufferOverlay.Graphics.Count == 0)) { bufferOverlay.Graphics.Clear(); } var bufferResult = GeometryEngine.Buffer(e.Location, 100); bufferOverlay.Graphics.Add(new Graphic() { Geometry = bufferResult }); var queryTask = new QueryTask( new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2")); var query = new Query("1=1") { ReturnGeometry = true, OutSpatialReference = MyMapView.SpatialReference, Geometry = bufferResult }; query.OutFields.Add("OWNERNME1"); var queryResult = await queryTask.ExecuteAsync(query); if (queryResult != null && queryResult.FeatureSet != null) { var resultOverlay = MyMapView.GraphicsOverlays["parcelOverlay"]; if (!(resultOverlay.Graphics.Count == 0)) { resultOverlay.Graphics.Clear(); } resultOverlay.Graphics.AddRange(queryResult.FeatureSet.Features.OfType <Graphic>()); } } catch (Exception ex) { var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { DataContext = this; // search var tapPoint = e.Location; var buffer = GeometryEngine.Buffer(tapPoint, 10); QueryParameters query = new QueryParameters(); query.Geometry = buffer; var results = await fLayer.FeatureTable.QueryFeaturesAsync(query); if (results.Count() > 0) { chartValues = new ChartValues <ObservableChartMapPoint>(); var firstResult = results.First(); var randoGeom = firstResult.Geometry as Esri.ArcGISRuntime.Geometry.Polyline; randoTitle = firstResult.Attributes["NOM"].ToString(); Camera cam = new Camera(firstResult.Geometry.Extent.GetCenter(), 4200, myMapView.MapRotation, 55, 0); var viewPoint = new Viewpoint(firstResult.Geometry, cam); //scen myMapView.SetViewpointAsync(viewPoint, System.TimeSpan.FromMilliseconds(4000)); mySceneView.SetViewpointAsync(viewPoint, System.TimeSpan.FromMilliseconds(4000)); var i = 0; double distance = 0; MapPoint lastPoint = null; foreach (var part in randoGeom.Parts) { foreach (var point in part.Points) { // si on est pas sur le premier point if (i > 0) { distance += GeometryEngine.DistanceGeodetic(lastPoint, point, LinearUnits.Kilometers, AngularUnits.Degrees, GeodeticCurveType.Geodesic).Distance; } // sauvegrde du point pour distance. lastPoint = point; // on ne prend pas tous les points. if (i % 2 == 0) { double elevation = await sceneSurface.GetElevationAsync(point); chartValues.Add(new ObservableChartMapPoint(Math.Round(distance, 4), elevation, point)); } i++; } } // charts } // zoom on both scene+mapview }
private Geometry ToLightningBufferGeometry(List <Geometry> lineGeometry) { const double BufferMiles = 5.0D; List <double> distances = lineGeometry .Select(geometry => geometry.SpatialReference.Unit as LinearUnit) .Select(unit => (unit != null) ? LinearUnits.Miles.ConvertTo(unit, BufferMiles) : BufferMiles) .ToList(); return(GeometryEngine.Buffer(lineGeometry, distances, true).SingleOrDefault()); }
private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { try { // Create a map point (in the WebMercator projected coordinate system) from the GUI screen coordinate. MapPoint userTappedMapPoint = _myMapView.ScreenToLocation(e.Position); // Get the buffer size from the UITextField. double bufferInMiles = System.Convert.ToDouble(_bufferDistanceMilesUITextField.Text); // Create a variable to be the buffer size in meters. There are 1609.34 meters in one mile. double bufferInMeters = bufferInMiles * 1609.34; // Get a buffered polygon from the GeometryEngine Buffer operation centered on the map point. // Note: The input distance to the Buffer operation is in meters. This matches the backdrop // basemap units which is also meters. Geometry bufferGeometry = GeometryEngine.Buffer(userTappedMapPoint, bufferInMeters); // Create the outline (a simple line symbol) for the buffered polygon. It will be a solid, thick, green line. SimpleLineSymbol bufferSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Green, 5); // Create the color that will be used for the fill of the buffered polygon. It will be a semi-transparent, green color. System.Drawing.Color bufferFillColor = System.Drawing.Color.FromArgb(125, 0, 255, 0); // Create simple fill symbol for the buffered polygon. It will be solid, semi-transparent, green fill with a solid, // thick, green outline. SimpleFillSymbol bufferSimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, bufferFillColor, bufferSimpleLineSymbol); // Create a new graphic for the buffered polygon using the defined simple fill symbol. Graphic bufferGraphic = new Graphic(bufferGeometry, bufferSimpleFillSymbol); // Add the buffered polygon graphic to the graphic overlay. _graphicsOverlay.Graphics.Add(bufferGraphic); // Create a simple marker symbol to display where the user tapped/clicked on the map. The marker symbol will be a // solid, red circle. SimpleMarkerSymbol userTappedSimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Red, 5); // Create a new graphic for the spot where the user clicked on the map using the simple marker symbol. Graphic userTappedGraphic = new Graphic(userTappedMapPoint, userTappedSimpleMarkerSymbol); // Add the user tapped/clicked map point graphic to the graphic overlay. _graphicsOverlay.Graphics.Add(userTappedGraphic); } catch (System.Exception ex) { // Display an error message if there is a problem generating the buffer polygon. UIAlertController alertController = UIAlertController.Create("Geometry Engine Failed!", ex.Message, UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alertController, true, null); return; } }
private void OnMakeUnionBufferClicked(object sender, EventArgs e) { try { // Get the boolean value whether to create a single unioned buffer (true) or independent buffer around each map point (false). bool unionBufferBool = _unionBufferSwitch.Checked; // Create an IEnumerable that contains buffered polygon(s) from the GeometryEngine Buffer operation based on a list of map // points and list of buffered distances. The input distances used in the Buffer operation are in meters; this matches the // backdrop basemap units which are also meters. If the unionResult parameter is true create a single unioned buffer, else // independent buffers will be created around each map point. IEnumerable <Geometry> theIEnumerableOfGeometryBuffer = GeometryEngine.Buffer(_bufferPointsList, _bufferDistancesList, unionBufferBool); // Create the outline (a simple line symbol) for the buffered polygon. It will be a solid, thick, green line. SimpleLineSymbol bufferPolygonSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Green, 5); // Create the color that will be used for the fill of the buffered polygon. It will be a semi-transparent, yellow color. System.Drawing.Color bufferPolygonFillColor = System.Drawing.Color.FromArgb(155, 255, 255, 0); // Create simple fill symbol for the buffered polygon. It will be solid, semi-transparent, yellow fill with a solid, // thick, green outline. SimpleFillSymbol bufferPolygonSimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, bufferPolygonFillColor, bufferPolygonSimpleLineSymbol); // Loop through all the geometries in the IEnumerable from the GeometryEngine Buffer operation. There should only be one buffered // polygon returned from the IEnumerable collection if the bool unionResult parameter was set to true in the GeometryEngine.Buffer // operation. If the bool unionResult parameter was set to false there will be one buffer per input geometry. foreach (Geometry oneGeometry in theIEnumerableOfGeometryBuffer) { // Create a new graphic for the buffered polygon using the defined simple fill symbol. Graphic bufferPolygonGraphic = new Graphic(oneGeometry, bufferPolygonSimpleFillSymbol) { // Specify a ZIndex value on the buffered polygon graphic to assist with the drawing order of mixed geometry types being added // to a single GraphicCollection. The lower the ZIndex value, the lower in the visual stack the graphic is drawn. Typically, // Polygons would have the lowest ZIndex value (ex: 0), then Polylines (ex: 1), and finally MapPoints (ex: 2). ZIndex = 0 }; // Add the buffered polygon graphic to the graphic overlay. // NOTE: While you can control the positional placement of a graphic within the GraphicCollection of a GraphicsOverlay, // it does not impact the drawing order in the GUI. If you have mixed geometries (i.e. Polygon, Polyline, MapPoint) within // a single GraphicsCollection, the way to control the drawing order is to specify the Graphic.ZIndex. _graphicsOverlay.Graphics.Insert(0, bufferPolygonGraphic); } } catch (Exception ex) { // Display an error message if there is a problem generating the buffer polygon. var alertBuilder = new AlertDialog.Builder(this); alertBuilder.SetTitle("There was a problem generating buffers."); alertBuilder.SetMessage(ex.ToString()); alertBuilder.Show(); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { try { // Create a map point (in the WebMercator projected coordinate system) from the GUI screen coordinate. MapPoint userTappedMapPoint = MyMapView.ScreenToLocation(e.Position); // Get the buffer size from the textbox. double bufferInMiles = System.Convert.ToDouble(BufferDistanceMilesTextBox.Text); // Create a variable to be the buffer size in meters. There are 1609.34 meters in one mile. double bufferInMeters = bufferInMiles * 1609.34; // Get a buffered polygon from the GeometryEngine Buffer operation centered on the map point. // Note: The input distance to the Buffer operation is in meters. This matches the backdrop // basemap units which is also meters. Geometry bufferGeometry = GeometryEngine.Buffer(userTappedMapPoint, bufferInMeters); // Create the outline (a simple line symbol) for the buffered polygon. It will be a solid, thick, green line. SimpleLineSymbol bufferSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Windows.UI.Colors.Green, 5); // Create the color that will be used for the fill of the buffered polygon. It will be a semi-transparent, green color. Windows.UI.Color bufferFillColor = Windows.UI.Color.FromArgb(125, 0, 255, 0); // Create simple fill symbol for the buffered polygon. It will be solid, semi-transparent, green fill with a solid, // thick, green outline. SimpleFillSymbol bufferSimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, bufferFillColor, bufferSimpleLineSymbol); // Create a new graphic for the buffered polygon using the defined simple fill symbol. Graphic bufferGraphic = new Graphic(bufferGeometry, bufferSimpleFillSymbol); // Add the buffered polygon graphic to the graphic overlay. _graphicsOverlay.Graphics.Add(bufferGraphic); // Create a simple marker symbol to display where the user tapped/clicked on the map. The marker symbol will be a // solid, red circle. SimpleMarkerSymbol userTappedSimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Windows.UI.Colors.Red, 5); // Create a new graphic for the spot where the user clicked on the map using the simple marker symbol. Graphic userTappedGraphic = new Graphic(userTappedMapPoint, userTappedSimpleMarkerSymbol); // Add the user tapped/clicked map point graphic to the graphic overlay. _graphicsOverlay.Graphics.Add(userTappedGraphic); } catch (System.Exception ex) { // Display an error message if there is a problem generating the buffer polygon. MessageDialog theMessageDialog = new MessageDialog("Geometry Engine Failed: " + ex.Message); await theMessageDialog.ShowAsync(); } }
private async void MyMapView_MapViewTapped(object sender, MapViewInputEventArgs e) { try { // get the map overlay element by name var mapOverlay = this.FindName("mapTip") as FrameworkElement; // verify that the overlay was found if (mapOverlay == null) { return; } mapOverlay.Visibility = System.Windows.Visibility.Collapsed; // get the location tapped on the map var mapPoint = e.Location; // get a buffer that is about 8 pixels in equivalent map distance var mapUnitsPerPixel = this.MyMapView.Extent.Width / this.MyMapView.ActualWidth; var bufferDist = mapUnitsPerPixel * 8; var searchBuffer = GeometryEngine.Buffer(mapPoint, bufferDist); var searchBufferWgs = GeometryEngine.Project(searchBuffer, SpatialReferences.Wgs84); // create a task to query a layer with the map point var uri = new Uri("http://services2.arcgis.com/zLGtbpFgxhQlMMAY/arcgis/rest/services/CelebrityHotspots/FeatureServer/0"); var queryTask = new QueryTask(uri); var query = new Query(searchBuffer); query.OutFields.Add("name"); query.OutFields.Add("city"); query.OutFields.Add("pic"); query.ReturnGeometry = true; // execute the query and check for a result var result = await queryTask.ExecuteAsync(query); if (result.FeatureSet.Features.Count > 0) { // get the first feature in the results var feature = result.FeatureSet.Features[0]; // set the overlay's data context with the feature; show the overlay mapOverlay.DataContext = feature; mapOverlay.Visibility = System.Windows.Visibility.Visible; } } catch (Exception exp) { MessageBox.Show(exp.Message); } }
private void AddRandomGraphics() { var random = new Random(); var overlay = mapView.GraphicsOverlays.FirstOrDefault(); if (overlay != null) { for (int i = 0; i < 10; i++) { var mp = new MapPoint(random.Next(-180, 180), random.Next(-90, 90), SpatialReferences.Wgs84); var geometry = GeometryEngine.Buffer(mp, random.Next(1, 10)); overlay.Graphics.Add(new Graphic(geometry)); } } }
public MainWindow() { // Set the extent of the AOI Meters = 100; // Set the number of columns Columns = 4; // Set the Field name FieldName = "sidc"; // Create relative paths to included data StylePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"symbols\mil2525c_b2.stylx"); SidcPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"symbols\SIDC.json"); // Create the AOI and zoom to it MapPoint pnt = GeometryEngine.Project(new MapPoint(-117.1825, 34.0556, SpatialReferences.Wgs84), SpatialReferences.WebMercator) as MapPoint; AOI = GeometryEngine.Buffer(pnt, Meters).Extent; InitializeComponent(); MyMapView.Loaded += async(sender, args) => { // Create a map using the navigationVector Basemap MyMapView.Map = new Map(Basemap.CreateNavigationVector()); // Create a graphics overlay to display the symbol codes MyMapView.GraphicsOverlays.Add(new GraphicsOverlay()); // Zoom to the aoi await MyMapView.SetViewpointGeometryAsync(AOI, 250); // Read the symbol identification codes from the json file using (System.IO.StreamReader reader = new System.IO.StreamReader(SidcPath)) { var json = reader.ReadToEnd(); Pages = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, object>[]>(json); } Page = 0; RenderSymbols(Pages.First(), true); btnPrevious.IsEnabled = false; }; }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { var geometry = GeometryEngine.Buffer(e.Location, 150); var hydrantsLayer = myMapView.Map.AllLayers.FirstOrDefault(layer => layer.Name == "Fire Hydrants") as FeatureLayer; // Reset graphics _overlay.Graphics.Clear(); // Perform the query var queryParams = new QueryParameters() { Geometry = geometry, WhereClause = "1=1" }; var table = hydrantsLayer.FeatureTable as ServiceFeatureTable; var results = await table.QueryFeaturesAsync(queryParams, QueryFeatureFields.LoadAll, CancellationToken.None); // Create new visuals and add to graphics overlay var resultsGraphics = results.Select(r => new Graphic(r.Geometry, new SimpleMarkerSymbol() { Color = Color.LimeGreen, Size = 12, Outline = new SimpleLineSymbol() { Color = Color.Green } }) { ZIndex = 2 }); var buffer = new Graphic(geometry, new SimpleFillSymbol() { Color = Color.Blue.MultiplyAlpha(0.5), }) { ZIndex = 1 }; _overlay.Graphics.Add(buffer); _overlay.Graphics.AddRange(resultsGraphics); // Update label with more details ResultsLabel.Text = $"Found {results.Count()} hydrants: "; ResultsLabel.Text += string.Join(", ", results.Select(r => r.Attributes["HYDRANT_NUM"])); }
private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { // Hide keyboard if present. _bufferDistanceMilesTextField.ResignFirstResponder(); try { // Get the location tapped by the user (a map point in the WebMercator projected coordinate system). MapPoint userTapPoint = e.Location; // Get the buffer distance (miles) entered in the text box. double bufferInMiles = Convert.ToDouble(_bufferDistanceMilesTextField.Text); // Call a helper method to convert the input distance to meters. double bufferInMeters = LinearUnits.Miles.ToMeters(bufferInMiles); // Create a planar buffer graphic around the input location at the specified distance. Geometry bufferGeometryPlanar = GeometryEngine.Buffer(userTapPoint, bufferInMeters); Graphic planarBufferGraphic = new Graphic(bufferGeometryPlanar); // Create a geodesic buffer graphic using the same location and distance. Geometry bufferGeometryGeodesic = GeometryEngine.BufferGeodetic(userTapPoint, bufferInMeters, LinearUnits.Meters, double.NaN, GeodeticCurveType.Geodesic); Graphic geodesicBufferGraphic = new Graphic(bufferGeometryGeodesic); // Create a graphic for the user tap location. Graphic locationGraphic = new Graphic(userTapPoint); // Get the graphics overlays. GraphicsOverlay planarBufferGraphicsOverlay = _myMapView.GraphicsOverlays["PlanarPolys"]; GraphicsOverlay geodesicBufferGraphicsOverlay = _myMapView.GraphicsOverlays["GeodesicPolys"]; GraphicsOverlay tapPointGraphicsOverlay = _myMapView.GraphicsOverlays["TapPoints"]; // Add the buffer polygons and tap location graphics to the appropriate graphic overlays. planarBufferGraphicsOverlay.Graphics.Add(planarBufferGraphic); geodesicBufferGraphicsOverlay.Graphics.Add(geodesicBufferGraphic); tapPointGraphicsOverlay.Graphics.Add(locationGraphic); } catch (Exception ex) { // Display an error message if there is a problem generating the buffers. UIAlertController alertController = UIAlertController.Create("Error creating buffers", ex.Message, UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alertController, true, null); } }
private async void mapView1_Tapped_1(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e) { var mp = e.Location; Graphic g = new Graphic() { Geometry = mp }; var graphicsLayer = mapView1.Map.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.Graphics.Add(g); var bufferResult = GeometryEngine.Buffer(mp, 100); var bufferLayer = mapView1.Map.Layers["BufferLayer"] as GraphicsLayer; bufferLayer.Graphics.Add(new Graphic() { Geometry = bufferResult }); var queryTask = new QueryTask(new Uri("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer/2")); var query = new Query("1=1") { ReturnGeometry = true, OutSpatialReference = mapView1.SpatialReference, Geometry = bufferResult }; query.OutFields.Add("OWNERNME1"); try { var queryResult = await queryTask.ExecuteAsync(query); if (queryResult != null && queryResult.FeatureSet != null) { var resultLayer = mapView1.Map.Layers["MyResultsGraphicsLayer"] as GraphicsLayer; resultLayer.Graphics.AddRange(queryResult.FeatureSet.Features.OfType <Graphic>()); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { try { // Get the location tapped by the user (a map point in the WebMercator projected coordinate system). MapPoint userTapPoint = e.Location; // Get the buffer distance (miles) entered in the text box. double bufferInMiles = System.Convert.ToDouble(_bufferDistanceMilesEditText.Text); // Call a helper method to convert the input distance to meters. double bufferInMeters = LinearUnits.Miles.ToMeters(bufferInMiles); // Create a planar buffer graphic around the input location at the specified distance. Geometry bufferGeometryPlanar = GeometryEngine.Buffer(userTapPoint, bufferInMeters); Graphic planarBufferGraphic = new Graphic(bufferGeometryPlanar); // Create a geodesic buffer graphic using the same location and distance. Geometry bufferGeometryGeodesic = GeometryEngine.BufferGeodetic(userTapPoint, bufferInMeters, LinearUnits.Meters, double.NaN, GeodeticCurveType.Geodesic); Graphic geodesicBufferGraphic = new Graphic(bufferGeometryGeodesic); // Create a graphic for the user tap location. Graphic locationGraphic = new Graphic(userTapPoint); // Get the graphics overlays. GraphicsOverlay planarBufferGraphicsOverlay = _myMapView.GraphicsOverlays["PlanarPolys"]; GraphicsOverlay geodesicBufferGraphicsOverlay = _myMapView.GraphicsOverlays["GeodesicPolys"]; GraphicsOverlay tapPointGraphicsOverlay = _myMapView.GraphicsOverlays["TapPoints"]; // Add the buffer polygons and tap location graphics to the appropriate graphic overlays. planarBufferGraphicsOverlay.Graphics.Add(planarBufferGraphic); geodesicBufferGraphicsOverlay.Graphics.Add(geodesicBufferGraphic); tapPointGraphicsOverlay.Graphics.Add(locationGraphic); } catch (System.Exception ex) { // Display an error message if there is a problem generating the buffer polygon. AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); alertBuilder.SetTitle("There was a problem generating buffers."); alertBuilder.SetMessage(ex.ToString()); alertBuilder.Show(); } }
// On tap, either get related records for the tapped well or find nearby wells if no well was tapped private async void mapView1_Tap(object sender, MapViewInputEventArgs e) { // Show busy UI BusyVisibility = Visibility.Visible; // Get the map if (m_mapView == null) { m_mapView = (MapView)sender; } // Create graphic and add to tap points var g = new Graphic() { Geometry = e.Location }; TapPoints.Add(g); // Buffer graphic by 100 meters, create graphic with buffer, add to buffers var buffer = GeometryEngine.Buffer(g.Geometry, 100); Buffers.Add(new Graphic() { Geometry = buffer }); // Find intersecting parcels and show them on the map var result = await doQuery(buffer); if (result != null && result.FeatureSet != null && result.FeatureSet.Features.Count > 0) { // Instead of adding parcels one-by-one, update the Parcels collection all at once to // allow the map to render the new features in one rendering pass. Parcels = new ObservableCollection <Graphic>(Parcels.Union(result.FeatureSet.Features)); } // Hide busy UI BusyVisibility = Visibility.Collapsed; }
private void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { try { // Get the location tapped by the user (a map point in the WebMercator projected coordinate system). MapPoint userTapPoint = e.Location; // Get the buffer distance (miles) entered in the text box. double bufferInMiles = System.Convert.ToDouble(BufferDistanceMilesEntry.Text); // Call a helper method to convert the input distance to meters. double bufferInMeters = LinearUnits.Miles.ToMeters(bufferInMiles); // Create a planar buffer graphic around the input location at the specified distance. Geometry bufferGeometryPlanar = GeometryEngine.Buffer(userTapPoint, bufferInMeters); Graphic planarBufferGraphic = new Graphic(bufferGeometryPlanar); // Create a geodesic buffer graphic using the same location and distance. Geometry bufferGeometryGeodesic = GeometryEngine.BufferGeodetic(userTapPoint, bufferInMeters, LinearUnits.Meters, double.NaN, GeodeticCurveType.Geodesic); Graphic geodesicBufferGraphic = new Graphic(bufferGeometryGeodesic); // Create a graphic for the user tap location. Graphic locationGraphic = new Graphic(userTapPoint); // Get the graphics overlays. GraphicsOverlay planarBufferGraphicsOverlay = MyMapView.GraphicsOverlays["PlanarPolys"]; GraphicsOverlay geodesicBufferGraphicsOverlay = MyMapView.GraphicsOverlays["GeodesicPolys"]; GraphicsOverlay tapPointGraphicsOverlay = MyMapView.GraphicsOverlays["TapPoints"]; // Add the buffer polygons and tap location graphics to the appropriate graphic overlays. planarBufferGraphicsOverlay.Graphics.Add(planarBufferGraphic); geodesicBufferGraphicsOverlay.Graphics.Add(geodesicBufferGraphic); tapPointGraphicsOverlay.Graphics.Add(locationGraphic); } catch (System.Exception ex) { // Display an error message if there is a problem generating the buffers. Page currentPage = (App.Current.MainPage as NavigationPage).CurrentPage; currentPage.DisplayAlert(ex.Message, "Error creating buffers", "OK"); } }
private void DrawCircle(string id, MapPoint point, double radius, SimpleFillSymbol circleFillSymbol, int ZIndex, LayerTypeEnum layerType, Color color) { var layerCol = GetLayerObservable(LayerTypeEnum.Notifications); var bufferGraphic = layerCol.Where(x => x.Attributes.Count > 0 && x.Attributes.ContainsKey("Id") && x.Attributes["Id"].ToString() == (id + "_Circle_" + ZIndex).ToString()).FirstOrDefault(); if (bufferGraphic != null) { layerCol.Remove(bufferGraphic); } var buffer = GeometryEngine.Buffer(point, radius * 0.0175); bufferGraphic = new Graphic { Geometry = buffer, Symbol = circleFillSymbol, ZIndex = ZIndex }; //bufferGraphic = DrawCircle(point, radius * 0.0175, color); bufferGraphic.Attributes.Add("Id", id + "_Circle_" + ZIndex); bufferGraphic.Attributes.Add("LayerType", layerType.ToString()); layerCol.Add(bufferGraphic); }
private async void MainMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { Reset(); var layer = MainMapView.Map.OperationalLayers.OfType <FeatureLayer>().FirstOrDefault(X => X.Id == "Victoria_Buildings_4805"); if (layer == null) { return; } var queryResults = await layer.FeatureTable.QueryFeaturesAsync(new Esri.ArcGISRuntime.Data.QueryParameters() { Geometry = GeometryEngine.Buffer(e.Location, 20 * MainMapView.UnitsPerPixel) }); foreach (var result in queryResults.ToArray()) { _overlay.Graphics.Add(new Graphic(result.Geometry, _querySymbol)); } }