<esri:Map x:Name="MyMap" MouseClick="MyMap_MouseClick" <!-- SNIP --> <!-- DOWN HERE A BUTTON --> <Button HorizontalAlignment="Center" Click="CalculateViewshed_Click" Tag="0" Margin="5,5,0,0" VerticalAlignment="Center" Width="50" Height="20" Content="ViewShed" Foreground="#FFFFFFFF" Style="{StaticResource GlassButton}"/>
Private Sub MyMap_MouseClick(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Client.Map.MouseEventArgs) If Not calculateViewshed Then Return End If ' BUFFER _geometryService = New GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer") AddHandler _geometryService.BufferCompleted, AddressOf GeometryService_BufferCompleted AddHandler _geometryService.Failed, AddressOf GeometryService_Failed _queryTask = New QueryTask("http://gis/arcgis/rest/services/MapServer/1") AddHandler _queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompletedBuffer AddHandler _queryTask.Failed, AddressOf QueryTask_Failed _pointAndBufferGraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerBuffer"), GraphicsLayer) _resultsGraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerBufferResults"), GraphicsLayer) Dim clickGraphic As New Graphic() clickGraphic.Symbol = TryCast(LayoutRoot.Resources("DefaultMarkerSymbol2"), ESRI.ArcGIS.Client.Symbols.Symbol) clickGraphic.Geometry = e.MapPoint ' Input spatial reference for buffer operation defined by first feature of input geometry array clickGraphic.Geometry.SpatialReference = MyMap.SpatialReference _pointAndBufferGraphicsLayer.ClearGraphics() _resultsGraphicsLayer.ClearGraphics() clickGraphic.SetZIndex(2) _pointAndBufferGraphicsLayer.Graphics.Add(clickGraphic) ' If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering Dim bufferParams As New ESRI.ArcGIS.Client.Tasks.BufferParameters() With { .BufferSpatialReference = New SpatialReference(4326), .OutSpatialReference = MyMap.SpatialReference, .Unit = LinearUnit.Meter } bufferParams.Distances.Add(4000) bufferParams.Features.Add(clickGraphic) _geometryService.BufferAsync(bufferParams) End Sub Private calculateViewshed As Boolean = False Private Sub CalculateViewshed_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) calculateViewshed = Not calculateViewshed End Sub '======================================================================================== ' CALCULATE VIEWSHED VIEWER '======================================================================================== Private Sub GetViewShed(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Client.Map.MouseEventArgs) _geoprocessorTask.CancelAsync() Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerViewShed"), GraphicsLayer) graphicsLayer.ClearGraphics() Dim mapPoint As MapPoint = e.MapPoint mapPoint.SpatialReference = New SpatialReference(3857) Dim graphic As New Graphic() With {.Symbol = TryCast(LayoutRoot.Resources("StartMarkerSymbol"), Symbol), .Geometry = mapPoint} graphicsLayer.Graphics.Add(graphic) MyMap.Cursor = System.Windows.Input.Cursors.Wait Dim parameters As New List(Of GPParameter)() parameters.Add(New GPFeatureRecordSetLayer("Input_Observation_Point", mapPoint)) parameters.Add(New GPLinearUnit("Viewshed_Distance", esriUnits.esriMiles, Convert.ToDouble(MilesTextBox.Text))) _geoprocessorTask.OutputSpatialReference = New SpatialReference(3857) _geoprocessorTask.ExecuteAsync(parameters) End Sub Private Sub GeoprocessorTask_ExecuteCompletedViewShed(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.GPExecuteCompleteEventArgs) MyMap.Cursor = System.Windows.Input.Cursors.Hand Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerViewShed"), GraphicsLayer) For Each gpParameter As GPParameter In args.Results.OutParameters If TypeOf gpParameter Is GPFeatureRecordSetLayer Then Dim layer As GPFeatureRecordSetLayer = TryCast(gpParameter, GPFeatureRecordSetLayer) For Each graphic As Graphic In layer.FeatureSet.Features graphic.Symbol = TryCast(LayoutRoot.Resources("DefaultFillSymbol"), Symbol) graphicsLayer.Graphics.Add(graphic) Next graphic End If Next gpParameter End Sub
bool calculateViewshed = false; private void CalculateViewshed_Click(object sender, RoutedEventArgs e) { calculateViewshed = !calculateViewshed; } private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { if (!calculateViewshed) return; //TODO: code to execute GeoprocessorTask. }
You can use your Button click to enable/disable calculation of viewshed by keeping a boolean. If false, you can return from the MouseClick event, otherwise, you can continue executing the GeoprocressorTask in the MouseClick event handler.
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.