private void MyDrawObject_DrawComplete(object sender, ESRI.ArcGIS.Client.DrawEventArgs e) { GraphicsLayer stopsGraphicsLayer = MyMap.Layers["MyStopsGraphicsLayer"] as GraphicsLayer; Graphic stop = new Graphic() { Geometry = e.Geometry, Symbol = LayoutRoot.Resources["StopSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; stopsGraphicsLayer.Graphics.Add(stop); if (stopsGraphicsLayer.Graphics.Count > 1) { RouteTask routeTask = LayoutRoot.Resources["MyRouteTask"] as RouteTask; if (routeTask.IsBusy) { routeTask.CancelAsync(); stopsGraphicsLayer.Graphics.RemoveAt(stopsGraphicsLayer.Graphics.Count - 1); } routeTask.SolveAsync(new RouteParameters() { Stops = stopsGraphicsLayer, UseTimeWindows = false, OutSpatialReference = MyMap.SpatialReference }); } }
void myDrawObject_DrawComplete(object sender, DrawEventArgs e) { if (StopsRadioButton.IsChecked.Value) { Graphic stop = new Graphic() { Geometry = e.Geometry, Symbol = LayoutRoot.Resources["StopSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; stop.Attributes.Add("StopNumber", stopsLayer.Graphics.Count + 1); stopsLayer.Graphics.Add(stop); _stops.Add(stop); } else if (BarriersRadioButton.IsChecked.Value) { Graphic barrier = new Graphic() { Geometry = e.Geometry, Symbol = LayoutRoot.Resources["BarrierSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol }; barriersLayer.Graphics.Add(barrier); _barriers.Add(barrier); } if (_stops.Count > 1) { if (_routeTask.IsBusy) { _routeTask.CancelAsync(); } _routeParams.OutSpatialReference = MyMap.SpatialReference; _routeTask.SolveAsync(_routeParams); } }
// *********************************************************************************** // * Solve button is clicked. Send the closest facility request to NA Service // *********************************************************************************** private void btnSolve_Click(object sender, RoutedEventArgs e) { List <AttributeParameter> aps = new List <AttributeParameter>(); if (_incidentsGraphicsLayer.Graphics.Count == 0 || _facilitiesGraphicsLayer.Graphics.Count == 0) { System.Windows.MessageBox.Show("Please add incident points or select facility type!", "ERROR"); return; } RouteClosestFacilityParameters routeParams = new RouteClosestFacilityParameters() { Incidents = _incidentsGraphicsLayer.Graphics, Barriers = _pointBarriersGraphicsLayer.Graphics.Count > 0 ? _pointBarriersGraphicsLayer.Graphics : null, PolylineBarriers = _polylineBarriersGraphicLayer.Graphics.Count > 0 ? _polylineBarriersGraphicLayer.Graphics : null, //_polylineBarriers : null, PolygonBarriers = _polygonBarriersGraphicsLayer.Graphics.Count > 0 ? _polygonBarriersGraphicsLayer.Graphics : null, Facilities = _facilitiesGraphicsLayer.Graphics, //MUST GET THIS FROM THE DATASOURCE ... RESOURCES LAYER??? ReturnDirections = true, //ReturnDirections2.IsChecked.HasValue ? ReturnDirections2.IsChecked.Value : false, DirectionsLengthUnits = esriUnits.esriMiles, //GetDirectionsLengthUnits(DirectionsLengthUnits2.SelectionBoxItem.ToString().Trim()), DirectionsTimeAttribute = "", //"Time", ReturnRoutes = true, ReturnFacilities = true, ReturnIncidents = true, ReturnBarriers = true, ReturnPolylineBarriers = true, //ReturnPolylineBarriers2.IsChecked.HasValue ? ReturnPolylineBarriers2.IsChecked.Value : false, ReturnPolygonBarriers = true, //ReturnPolygonBarriers2.IsChecked.HasValue ? ReturnPolygonBarriers2.IsChecked.Value : false, FacilityReturnType = FacilityReturnType.ServerFacilityReturnAll, OutputLines = "esriNAOutputLineTrueShape", //GetOutputLines(OutputLines2.SelectionBoxItem.ToString().Trim()), DefaultTargetFacilityCount = (int)numFacilities.Value, TravelDirection = FacilityTravelDirection.TravelDirectionToFacility, DefaultCutoff = 1000, //AttributeParameterValues = aps, OutSpatialReference = _mapWidget.Map.SpatialReference, //string.IsNullOrEmpty(OutputSpatialReference2.Text) ? null : new SpatialReference(int.Parse(OutputSpatialReference2.Text)), //AccumulateAttributes = AccumulateAttributeNames2.Text.Split(','), //ImpedanceAttribute = ImpedanceAttributeName2.Text, //RestrictionAttributes = RestrictionAttributeNames2.Text.Split(','), //RestrictUTurns = GetRestrictUTurns(RestrictUTurns2.SelectionBoxItem.ToString().Trim()), UseHierarchy = false, //OutputGeometryPrecision = string.IsNullOrEmpty(OutputGeometryPrecision2.Text) ? 0 : double.Parse(OutputGeometryPrecision2.Text), //OutputGeometryPrecisionUnits = GetGeometryPrecisionUnits(OutputGeometryPrecisionUnits2.SelectionBoxItem.ToString().Trim()), }; if (_mapWidget != null) { _mapWidget.Map.MouseClick -= Map_MouseClick; } if (_routeTask.IsBusy) { _routeTask.CancelAsync(); } _routeTask.SolveClosestFacilityAsync(routeParams); }
private void SolveButton_Click(object sender, RoutedEventArgs e) { List <AttributeParameter> aps = new List <AttributeParameter>(); AttributeParameter ap = GetAttributeParameterValue(AttributeParameter2.SelectionBoxItem.ToString()); if (ap != null) { aps.Add(ap); } GenerateBarriers(); RouteClosestFacilityParameters routeParams = new RouteClosestFacilityParameters() { Incidents = IncidentsGraphicsLayer.Graphics, Barriers = pointBarriers.Count > 0 ? pointBarriers : null, PolylineBarriers = polylineBarriers.Count > 0 ? polylineBarriers : null, PolygonBarriers = polygonBarriers.Count > 0 ? polygonBarriers : null, Facilities = facilitiesGraphicsLayer.Graphics, AttributeParameterValues = aps, ReturnDirections = ReturnDirections2.IsChecked.HasValue ? ReturnDirections2.IsChecked.Value : false, DirectionsLanguage = String.IsNullOrEmpty(DirectionsLanguage2.Text) ? new System.Globalization.CultureInfo("en-US") : new System.Globalization.CultureInfo(DirectionsLanguage2.Text), DirectionsLengthUnits = GetDirectionsLengthUnits(DirectionsLengthUnits2.SelectionBoxItem.ToString().Trim()), DirectionsTimeAttribute = DirectionsTimeAttributeName2.Text, ReturnRoutes = ReturnRoutes2.IsChecked.HasValue ? ReturnRoutes2.IsChecked.Value : false, ReturnFacilities = ReturnFacilities2.IsChecked.HasValue ? ReturnFacilities2.IsChecked.Value : false, ReturnIncidents = ReturnIncidents2.IsChecked.HasValue ? ReturnIncidents2.IsChecked.Value : false, ReturnBarriers = ReturnBarriers2.IsChecked.HasValue ? ReturnBarriers2.IsChecked.Value : false, ReturnPolylineBarriers = ReturnPolylineBarriers2.IsChecked.HasValue ? ReturnPolylineBarriers2.IsChecked.Value : false, ReturnPolygonBarriers = ReturnPolygonBarriers2.IsChecked.HasValue ? ReturnPolygonBarriers2.IsChecked.Value : false, FacilityReturnType = FacilityReturnType.ServerFacilityReturnAll, OutputLines = GetOutputLines(OutputLines2.SelectionBoxItem.ToString().Trim()), DefaultCutoff = string.IsNullOrEmpty(DefaultCutoff2.Text) ? 100 : double.Parse(DefaultCutoff2.Text), DefaultTargetFacilityCount = string.IsNullOrEmpty(DefaultTargetFacilityCount2.Text) ? 1 : int.Parse(DefaultTargetFacilityCount2.Text), TravelDirection = GetFacilityTravelDirections(TravelDirection2.SelectionBoxItem.ToString()), OutSpatialReference = string.IsNullOrEmpty(OutputSpatialReference2.Text) ? MyMap.SpatialReference : new SpatialReference(int.Parse(OutputSpatialReference2.Text)), AccumulateAttributes = AccumulateAttributeNames2.Text.Split(','), ImpedanceAttribute = ImpedanceAttributeName2.Text, RestrictionAttributes = RestrictionAttributeNames2.Text.Split(','), RestrictUTurns = GetRestrictUTurns(RestrictUTurns2.SelectionBoxItem.ToString().Trim()), UseHierarchy = UseHierarchy2.IsChecked.HasValue ? UseHierarchy2.IsChecked.Value : false, OutputGeometryPrecision = string.IsNullOrEmpty(OutputGeometryPrecision2.Text) ? 0 : double.Parse(OutputGeometryPrecision2.Text), OutputGeometryPrecisionUnits = GetGeometryPrecisionUnits(OutputGeometryPrecisionUnits2.SelectionBoxItem.ToString().Trim()), }; if (myRouteTask.IsBusy) { myRouteTask.CancelAsync(); } myRouteTask.SolveClosestFacilityAsync(routeParams); }
private void SolveButton_Click(object sender, RoutedEventArgs e) { List <AttributeParameter> aps = new List <AttributeParameter>(); AttributeParameter ap = GetAttributeParameterValue(AttributeParameterValues3.SelectionBoxItem.ToString()); if (ap != null) { aps.Add(ap); } GenerateBarriers(); RouteServiceAreaParameters routeParams = new RouteServiceAreaParameters() { Barriers = pointBarriers.Count > 0 ? pointBarriers : null, PolylineBarriers = polylineBarriers.Count > 0 ? polylineBarriers : null, PolygonBarriers = polygonBarriers.Count > 0 ? polygonBarriers : null, Facilities = facilitiesGraphicsLayer.Graphics, //AttributeParameterValues = aps, DefaultBreaks = DefaultBreaks.Text, ExcludeSourcesFromPolygons = ExculdeSourcesFromPolygons.Text, MergeSimilarPolygonRanges = MergeSimilarPolygonRanges.IsChecked.HasValue ? MergeSimilarPolygonRanges.IsChecked.Value : false, OutputLines = GetOutputLines(OutputLines3.SelectionBoxItem.ToString()), OutputPolygons = GetOutputPolygons(OutputPolygons.SelectionBoxItem.ToString()), OverlapLines = OverlapLines3.IsChecked.HasValue ? OverlapLines3.IsChecked.Value : false, OverlapPolygons = OverlapPolygons3.IsChecked.HasValue ? OverlapPolygons3.IsChecked.Value : false, SplitLineAtBreaks = SplitLinesAtBreaks.IsChecked.HasValue ? SplitLinesAtBreaks.IsChecked.Value : false, SplitPolygonsAtBreaks = SplitPolygonsAtBreaks.IsChecked.HasValue ? SplitPolygonsAtBreaks.IsChecked.Value : false, TravelDirection = GetFacilityTravelDirections(TravelDirections3.SelectionBoxItem.ToString()), TrimOuterPolygon = TrimOuterPolygons.IsChecked.HasValue ? TrimOuterPolygons.IsChecked.Value : false, TrimPolygonDistance = string.IsNullOrEmpty(TrimPolygonDistance.Text) ? 0 : double.Parse(TrimPolygonDistance.Text), TrimPolygonDistanceUnits = GetUnits(TrimPolygonDistanceUnits.SelectionBoxItem.ToString()), ReturnFacilities = ReturnFacilities3.IsChecked.HasValue ? ReturnFacilities3.IsChecked.Value : false, ReturnBarriers = ReturnBarriers3.IsChecked.HasValue ? ReturnBarriers3.IsChecked.Value : false, ReturnPolylineBarriers = ReturnPolylineBarriers3.IsChecked.HasValue ? ReturnPolylineBarriers3.IsChecked.Value : false, ReturnPolygonBarriers = ReturnPolygonBarriers3.IsChecked.HasValue ? ReturnPolygonBarriers3.IsChecked.Value : false, OutSpatialReference = string.IsNullOrEmpty(OutputSpatialReference3.Text) ? MyMap.SpatialReference : new SpatialReference(int.Parse(OutputSpatialReference3.Text)), AccumulateAttributes = string.IsNullOrEmpty(AccumulateAttributeNames3.Text) ? null : AccumulateAttributeNames3.Text.Split(','), ImpedanceAttribute = string.IsNullOrEmpty(ImpedanceAttributeName3.Text) ? string.Empty : ImpedanceAttributeName3.Text, RestrictionAttributes = string.IsNullOrEmpty(RestrictionAttributeNames3.Text) ? null : RestrictionAttributeNames3.Text.Split(','), RestrictUTurns = GetRestrictUTurns(RestrictUTurns3.SelectionBoxItem.ToString()), OutputGeometryPrecision = string.IsNullOrEmpty(OutputGeometryPrecision3.Text) ? 0 : double.Parse(OutputGeometryPrecision3.Text), OutputGeometryPrecisionUnits = GetUnits(OutputGeometryPrecisionUnits3.SelectionBoxItem.ToString()) }; if (myRouteTask.IsBusy) { myRouteTask.CancelAsync(); } myRouteTask.SolveServiceAreaAsync(routeParams); }
private void GetDirections_Click(object sender, RoutedEventArgs e) { //Reset DirectionsStackPanel.Children.Clear(); _stops.Clear(); (MyMap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer).Graphics.Clear(); _locator.CancelAsync(); _routeTask.CancelAsync(); //Geocode from address _locator.FindAsync(ParseSearchText(FromTextBox.Text), "from"); }
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { Graphic stop = new Graphic() { Geometry = e.MapPoint }; stopsGraphicsLayer.Graphics.Add(stop); if (stopsGraphicsLayer.Graphics.Count > 1) { if (routeTask.IsBusy) { routeTask.CancelAsync(); stopsGraphicsLayer.Graphics.RemoveAt(stopsGraphicsLayer.Graphics.Count - 1); } routeTask.SolveAsync(new RouteParameters() { Stops = stopsGraphicsLayer, UseTimeWindows = false, OutSpatialReference = MyMap.SpatialReference }); } }
private void CalculateDriveTime(MapPoint mapPoint) { double dDriveTime = 0; if (Double.TryParse(tbDriveTimeValue.Text, out dDriveTime) == false) { return; } if (dDriveTime <= 0) { return; } // make sure the facilities graphic layer has the only one new graphic, based on the mapPoint click location Graphic clickGraphic = new Graphic(); //clickGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; clickGraphic.Geometry = mapPoint; int facilityNumber = 1; clickGraphic.Attributes.Add("FacilityNumber", facilityNumber); _facilitiesGraphicsLayer.Graphics.Clear(); _facilitiesGraphicsLayer.Graphics.Add(clickGraphic); GenerateBarriers(); try { RouteServiceAreaParameters routeParams = new RouteServiceAreaParameters() { Facilities = _facilitiesGraphicsLayer.Graphics, DefaultBreaks = tbDriveTimeValue.Text, TravelDirection = EncodeFacilityTravelDirections(comboFacilityTravelDirection.SelectionBoxItem.ToString()), //Barriers = _pointBarriers.Count > 0 ? _pointBarriers : null, //PolylineBarriers = _polylineBarriers.Count > 0 ? _polylineBarriers : null, //PolygonBarriers = _polygonBarriers.Count > 0 ? _polygonBarriers : null, //ExcludeSourcesFromPolygons = null, //MergeSimilarPolygonRanges = false, //OutputLines = EncodeOutputLines("None"), //"esriNAOutputLineNone" //OverlapLines = true, //OverlapPolygons = true, //SplitLineAtBreaks = false, //SplitPolygonsAtBreaks = true, OutputPolygons = EncodeOutputPolygons("Simplified"), //"esriNAOutputPolygonSimplified", TrimOuterPolygon = true, TrimPolygonDistance = 100.0, TrimPolygonDistanceUnits = esriUnits.esriMeters, ReturnFacilities = false, ReturnBarriers = false, ReturnPolylineBarriers = false, ReturnPolygonBarriers = false, OutSpatialReference = Map.SpatialReference, AccumulateAttributes = null, //ImpedanceAttribute = "TravelTime" //RestrictionAttributes = "Non-routeable segments,Avoid passenger ferries,TurnRestriction,OneWay".Split(','), //RestrictUTurns = EncodeRestrictUTurns("Allow Backtrack"), //"esriNFSBAllowBacktrack" OutputGeometryPrecision = 100.0, OutputGeometryPrecisionUnits = esriUnits.esriMeters }; if (_routeTask.IsBusy) { _routeTask.CancelAsync(); } _routeTask.SolveServiceAreaAsync(routeParams); } catch (Exception ex) { MessageBox.Show(ex.Message + '\n' + ex.StackTrace); } }