Exemplo n.º 1
0
        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 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);
            }
        }