void locator_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs e)
        {
            GraphicsLayer graphicsLayer = (MyMap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer);

            if (e.Results.Count > 0)
            {
                AddressCandidate address         = e.Results[0];
                Graphic          graphicLocation = new Graphic()
                {
                    Geometry = address.Location
                };
                graphicLocation.Attributes.Add("address", address.Address);
                graphicLocation.Attributes.Add("score", address.Score);

                _stops.Add(graphicLocation);
                if ((string)e.UserState == "from")
                {
                    graphicLocation.Symbol = LayoutRoot.Resources["FromSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                    //Geocode to address
                    _locator.AddressToLocationsAsync(ParseAddress(ToTextBox.Text), "to");
                }
                else
                {
                    graphicLocation.Symbol = LayoutRoot.Resources["ToSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                    //Get route between from and to
                    _routeParams.OutSpatialReference = MyMap.SpatialReference;
                    _routeTask.SolveAsync(_routeParams);
                }

                graphicsLayer.Graphics.Add(graphicLocation);
            }
        }
Ejemplo n.º 2
0
        private void LocatorTask_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs args)
        {
            List <AddressCandidate> returnedCandidates = args.Results;

            if (returnedCandidates.Count == 1)
            {
                AddressCandidate best = returnedCandidates[0];
                Envelope         env  = new Envelope()
                {
                    XMin = double.Parse(best.Attributes["West_Lon"].ToString(), CultureInfo.InvariantCulture),
                    YMin = double.Parse(best.Attributes["South_Lat"].ToString(), CultureInfo.InvariantCulture),
                    XMax = double.Parse(best.Attributes["East_Lon"].ToString(), CultureInfo.InvariantCulture),
                    YMax = double.Parse(best.Attributes["North_Lat"].ToString(), CultureInfo.InvariantCulture)
                };

                Map.ZoomTo(env);
            }
            else if (returnedCandidates.Count > 1)
            {
                locationResults.Visibility  = Visibility.Visible;
                locationResults.ItemsSource = returnedCandidates;
                Dispatcher.BeginInvoke(() =>
                {
                    locationResults.Focus();
                });
            }
        }
Ejemplo n.º 3
0
        void locatorTask_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs e)
        {
            try
            {
                List <AddressCandidate> returnedCandidates = e.Results;
                int BuildingEvacDistance = 0;
                int OutdoorEvacDistance  = 0;

                if (bombType.Text == "Pipe bomb")
                {
                    BuildingEvacDistance = 70;
                    OutdoorEvacDistance  = 1200;
                }
                else if (bombType.Text == "Suicide vest")
                {
                    BuildingEvacDistance = 110;
                    OutdoorEvacDistance  = 1750;
                }
                else if (bombType.Text == "Briefcase/suitcase bomb")
                {
                    BuildingEvacDistance = 150;
                    OutdoorEvacDistance  = 1850;
                }
                else if (bombType.Text == "Sedan")
                {
                    BuildingEvacDistance = 320;
                    OutdoorEvacDistance  = 1900;
                }
                else if (bombType.Text == "SUV/van")
                {
                    BuildingEvacDistance = 400;
                    OutdoorEvacDistance  = 2400;
                }
                else if (bombType.Text == "Small delivery truck")
                {
                    BuildingEvacDistance = 640;
                    OutdoorEvacDistance  = 3800;
                }
                else if (bombType.Text == "Container/water truck")
                {
                    BuildingEvacDistance = 860;
                    OutdoorEvacDistance  = 5100;
                }
                else if (bombType.Text == "Semi-trailer")
                {
                    BuildingEvacDistance = 1570;
                    OutdoorEvacDistance  = 9300;
                }

                if (BuildingEvacDistance == 0 || OutdoorEvacDistance == 0)
                {
                    return;
                }

                if (e.Results.Count > 0)
                {
                    AddressCandidate candidate = returnedCandidates[0];

                    ResourceDictionary mydictionary = new ResourceDictionary();
                    mydictionary.Source = new Uri("/BombThreatAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute);
                    Graphic graphic = new ESRI.ArcGIS.Client.Graphic();
                    graphic.Geometry = candidate.Location;
                    graphic.Symbol   = mydictionary["DefaultClickSymbol"] as client.Symbols.MarkerSymbol;

                    location = candidate.Location;
                    graphic.SetZIndex(1);
                    if (_graphicsLayer == null)
                    {
                        _graphicsLayer    = new ESRI.ArcGIS.Client.GraphicsLayer();
                        _graphicsLayer.ID = "BombThreatGraphics";
                        client.AcceleratedDisplayLayers aclyrs = _mapWidget.Map.Layers.FirstOrDefault(lyr => lyr is client.AcceleratedDisplayLayers) as client.AcceleratedDisplayLayers;
                        if (aclyrs.Count() > 0)
                        {
                            aclyrs.ChildLayers.Add(_graphicsLayer);
                        }
                    }

                    _graphicsLayer.Graphics.Add(graphic);

                    GeometryService geometryTask = new GeometryService();
                    geometryTask.Url     = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"; geometryTask.BufferCompleted += GeometryService_BufferCompleted;
                    geometryTask.Failed += GeometryService_Failed;

                    // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering
                    BufferParameters bufferParams = new BufferParameters()
                    {
                        Unit = LinearUnit.SurveyFoot,
                        BufferSpatialReference = new SpatialReference(102004),
                        OutSpatialReference    = _mapWidget.Map.SpatialReference
                    };
                    bufferParams.Features.Add(graphic);
                    double[] theDistances = new double[] { BuildingEvacDistance, OutdoorEvacDistance };
                    bufferParams.Distances.AddRange(theDistances);
                    geometryTask.BufferAsync(bufferParams);
                }
                else
                {
                    MessageBox.Show("No address found.  Example schema: 380 New York Ave., Redlands, CA or click on the map");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in Address location complete: " + ex.Message);
            }
        }
        // Raised when the locator search completes
        private void AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs args)
        {
            if (args.Results == null || args.Results.Count < 1) // No results found
            {
                IsSearching = false; // Reset busy state
                OnSearchCompleted(); // Raise completed event
                return;
            }

            // check that coordinates returned by extent fields are valid
            AddressCandidate result = args.Results[0];
            double xMin, xMax, yMin, yMax;
            bool useExtentFields = UseExtentFields;
            if (UseExtentFields && getExtentFields(result, out xMin, out yMin, out xMax, out yMax)) 
            {                
                if (xMax <= xMin || yMax <= yMin)
                {
                    // Extent fields are returning invalid coordinates.  Disable use of extent fields.
                    useExtentFields = false;
                }                
            }

            // Check whether result extents will need to be reprojected using a geometry service
            SpatialReference locatorSRef = LocatorInfo.SpatialReference;
            bool needsGeometryServiceProjection = (useExtentFields &&
                ((locatorSRef != null && !locatorSRef.IsWebMercator() && !locatorSRef.IsGeographic())
                || (!_map.SpatialReference.IsWebMercator() && !_map.SpatialReference.IsGeographic())))
                || (!useExtentFields && _mapUnits == LengthUnits.UnitsDecimalDegrees);
            List<Graphic> graphicsToProject = new List<Graphic>();
            List<LocatorResultViewModel> geographicResults = new List<LocatorResultViewModel>();

            foreach (AddressCandidate candidate in args.Results)
            {
                // Create the result ViewModel from the result returned from the service
                LocatorResultViewModel resultViewModel = new LocatorResultViewModel(candidate);

                // If extent fields are being used, initialize the extent on the service
                if (useExtentFields && getExtentFields(candidate, out xMin, out yMin, out xMax, out yMax))
                {
                    Envelope extent = new Envelope(xMin, yMin, xMax, yMax);
                    if (LocatorInfo.SpatialReference != null)
                    {
                        extent.SpatialReference = locatorSRef;
                        if (!needsGeometryServiceProjection)
                        {
                            // No geometry service needed, so set extent directly

                            if (locatorSRef.IsWebMercator() && _map.SpatialReference.WKID == 4326)
                                extent = (new WebMercator()).ToGeographic(extent) as Envelope;
                            else if (locatorSRef.WKID == 4326 && _map.SpatialReference.IsWebMercator())
                                extent = (new WebMercator()).FromGeographic(extent) as Envelope;

                            resultViewModel.Extent = extent;
                        }
                        else
                        {
                            // Since results need to be reprojected, add them to collection to be projected
                            // once they've all been gone through
                            graphicsToProject.Add(new Graphic() { Geometry = extent });
                            _queuedResults.Enqueue(resultViewModel);
                        }
                    }
                    else
                    {
                        resultViewModel.Extent = extent;
                    }

                }

                if (resultViewModel.Extent == null && !useExtentFields) 
                {
                    // Initialize the result extent based on the specified extent width

                    if (_gotMapUnits) // check whether map units have been retrieved for the current search
                    {
                        if (!needsGeometryServiceProjection)
                        {
                            initializeResultExtent(resultViewModel);
                            _results.Add(resultViewModel);
                        }
                        else if (_mapUnits != LengthUnits.UnitsDecimalDegrees)
                        {
                            initializeResultExtent(resultViewModel);
                            graphicsToProject.Add(new Graphic() { Geometry = resultViewModel.Extent });
                            _queuedResults.Enqueue(resultViewModel);
                        }
                        else
                        {
                            // results in a geographic coordinate system (units of decimal degrees) require
                            // special handling because an envelope around the result cannot be calculated
                            // in the result's spatial reference.

                            geographicResults.Add(resultViewModel);
                        }
                    }
                    else
                    {
                        // map units are not yet known, so queue up the result to be added after map units are
                        // determined.
                        _queuedResults.Enqueue(resultViewModel);
                    }
                }
                else if (!needsGeometryServiceProjection)
                {
                    // No projection needed, so the result can be added now
                    _results.Add(resultViewModel);
                }
            }

            if (!needsGeometryServiceProjection) // Check whether result extents need to be reprojected
            {
                // No projection needed, so the operation is complete. 

                // Refresh paged collection to update pagination
                PagedResults.Refresh();

                IsSearching = false; // Reset busy state
                OnSearchCompleted(); // Raise completed event
            }
            else if (graphicsToProject.Count > 0)
            {
                // result extents need to be reprojected
                if (_geometryService == null)
                {
                    _geometryService = new GeometryService(GeometryServiceUrl);
                    _geometryService.ProjectCompleted += GeometryService_ProjectCompleted;
                }

                _geometryService.ProjectAsync(graphicsToProject, _map.SpatialReference, _queuedResults);
            }
            else
            {
                // result extents need to be created in a spatial reference that uses linear units (i.e.
                // projected coordinate system), then projected back into the current spatial reference.
                handleGeographicResults(geographicResults);
            }
        }
Ejemplo n.º 5
0
        void locatorTask_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs e)
        {
            try
            {
                locatorTask.AddressToLocationsCompleted -=
                locatorTask_AddressToLocationsCompleted;
                IList<GeoLocatorDetail> result = new List<GeoLocatorDetail>();
                WebMercator webMercator = new WebMercator();
                if (e.Results.Count > 0)
                {
                    foreach (var item in e.Results)
                    {
                        result.Add(new GeoLocatorDetail()
                        {
                            Location = webMercator.FromGeographic(item.Location) as MapPoint,
                            Match = System.Convert.ToDouble(item.Score),
                            Title = item.Address
                        });
                    }
                }
                else
                {
                }
                ResultsGeoLocatorEventArgs resultEventArgs = new ResultsGeoLocatorEventArgs(result);
                OnGeoLocatorSearchComplete(resultEventArgs);

            }
            catch (Exception ex)
            {
                messageBoxCustom.Show(String.Format("locatorTask_AddressToLocationsCompleted /{0}", ex.Message),
                    GisTexts.SevereError,
                    MessageBoxCustomEnum.MessageBoxButtonCustom.Ok);
            }
        }
        void locatorTask_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs e)
        {
            try
            {
                List<AddressCandidate> returnedCandidates = e.Results;
                int BuildingEvacDistance = 0;
                int OutdoorEvacDistance = 0;

                if (bombType.Text == "Pipe bomb")
                {
                    BuildingEvacDistance = 70;
                    OutdoorEvacDistance = 1200;
                }
                else if (bombType.Text == "Suicide vest")
                {
                    BuildingEvacDistance = 110;
                    OutdoorEvacDistance = 1750;
                }
                else if (bombType.Text == "Briefcase/suitcase bomb")
                {
                    BuildingEvacDistance = 150;
                    OutdoorEvacDistance = 1850;
                }
                else if (bombType.Text == "Sedan")
                {
                    BuildingEvacDistance = 320;
                    OutdoorEvacDistance = 1900;
                }
                else if (bombType.Text == "SUV/van")
                {
                    BuildingEvacDistance = 400;
                    OutdoorEvacDistance = 2400;
                }
                else if (bombType.Text == "Small delivery truck")
                {
                    BuildingEvacDistance = 640;
                    OutdoorEvacDistance = 3800;
                }
                else if (bombType.Text == "Container/water truck")
                {
                    BuildingEvacDistance = 860;
                    OutdoorEvacDistance = 5100;
                }
                else if (bombType.Text == "Semi-trailer")
                {
                    BuildingEvacDistance = 1570;
                    OutdoorEvacDistance = 9300;
                }

                if (BuildingEvacDistance == 0 || OutdoorEvacDistance == 0)
                    return;

                if (e.Results.Count > 0)
                {
                    AddressCandidate candidate = returnedCandidates[0];

                    ResourceDictionary mydictionary = new ResourceDictionary();
                    mydictionary.Source = new Uri("/BombThreatAddin;component/SymbolDictionary.xaml", UriKind.RelativeOrAbsolute);
                    Graphic graphic = new ESRI.ArcGIS.Client.Graphic();
                    graphic.Geometry = candidate.Location;
                    graphic.Symbol = mydictionary["DefaultClickSymbol"] as client.Symbols.MarkerSymbol;

                    location = candidate.Location;
                    graphic.SetZIndex(1);
                    if (_graphicsLayer == null)
                    {
                        _graphicsLayer = new ESRI.ArcGIS.Client.GraphicsLayer();
                        _graphicsLayer.ID = "BombThreatGraphics";
                        client.AcceleratedDisplayLayers aclyrs = _mapWidget.Map.Layers.FirstOrDefault(lyr => lyr is client.AcceleratedDisplayLayers) as client.AcceleratedDisplayLayers;
                        if (aclyrs.Count() > 0)
                        {
                            aclyrs.ChildLayers.Add(_graphicsLayer);
                        }
                    }

                    _graphicsLayer.Graphics.Add(graphic);

                    GeometryService geometryTask = new GeometryService();
                    geometryTask.Url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"; geometryTask.BufferCompleted += GeometryService_BufferCompleted;
                    geometryTask.Failed += GeometryService_Failed;

                    // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering
                    BufferParameters bufferParams = new BufferParameters()
                    {
                        Unit = LinearUnit.SurveyFoot,
                        BufferSpatialReference = new SpatialReference(102004),
                        OutSpatialReference = _mapWidget.Map.SpatialReference
                    };
                    bufferParams.Features.Add(graphic);
                    double[] theDistances = new double[] { BuildingEvacDistance, OutdoorEvacDistance };
                    bufferParams.Distances.AddRange(theDistances);
                    geometryTask.BufferAsync(bufferParams);

                }
                else
                {
                    MessageBox.Show("No address found.  Example schema: 380 New York Ave., Redlands, CA or click on the map");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in Address location complete: " + ex.Message);
            }
        }
        void locator_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs e)
        {
            GraphicsLayer graphicsLayer = (MyMap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer);
            if (e.Results.Count > 0)
            {
                AddressCandidate address = e.Results[0];
                Graphic graphicLocation = new Graphic() { Geometry = address.Location };
                graphicLocation.Attributes.Add("address", address.Address);
                graphicLocation.Attributes.Add("score", address.Score);

                _stops.Add(graphicLocation);
                if ((string)e.UserState == "from")
                {
                    graphicLocation.Symbol = LayoutRoot.Resources["FromSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                    //Geocode to address
                    _locator.AddressToLocationsAsync(ParseAddress(ToTextBox.Text), "to");
                }
                else
                {
                    graphicLocation.Symbol = LayoutRoot.Resources["ToSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                    //Get route between from and to
                    _routeParams.OutSpatialReference = MyMap.SpatialReference;
                    _routeTask.SolveAsync(_routeParams);
                }

                graphicsLayer.Graphics.Add(graphicLocation);
            }
        }