// *********************************************************************************** // * 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); }