Пример #1
0
        /// <summary>
        /// Raised when the asynchronous call to search the web has completed.
        /// </summary>
        private void WebSearchCompleted(object sender, OpenReadEventArgs e)
        {
            // Received another response, so increment the counter
            _numberWebResults++;

            if (e.Error == null && !_cancelled) // No error, no cancellation - handle result as normal
            {
                GoogleResponse result = WebUtil.ReadObject <GoogleResponse>(e.Result);
                if (result != null && result.ResponseData != null && result.ResponseData.Items.Length > 0)
                {
                    // before services from the web get added we need to check if they are accessible
                    foreach (WebSearchResultItem item in result.ResponseData.Items)
                    {
                        Uri url = new Uri(item.Url);
                        ArcGISService.GetServiceInfoAsync(item.Url, item, CheckServiceAccessCompleted);
                    }
                    return;
                }
            }

            // There was an error, the response was empty, or the operation was cancelled.  Check whether this is the last response.
            if (_numberWebResults == _NUMREQUESTS)
            {
                // All requests have returned.  Go through completeion routine.

                if (!_cancelled)
                {
                    IsSearching = false; // Reset busy state
                    OnSearchCompleted(); // Raise completed event
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Raised when the asynchronous call to check if the map service is accessible has completed.
        /// </summary>
        private void CheckServiceAccessCompleted(object sender, ServiceEventArgs e)
        {
            if (e.Service == null)
            {
                return; //the map service is not accessible
            }
            // Check the current result against the ones already received.  Duplicates are often found.
            bool alreadyAdded = false;

            foreach (SearchResultViewModel result in _checkedResults)
            {
                ArcGISService webSearchRes = (ArcGISService)result.Result;
                if (webSearchRes.Title.Equals(e.Service.Title) && webSearchRes.Url.Equals(e.Service.Url))
                {
                    alreadyAdded = true; //add search results only once
                    break;
                }
            }

            // If it's a new service, initialize the result viewModel and add it to the collection of
            // results that have had their service access checked
            if (!alreadyAdded && !_cancelled)
            {
                SearchResultViewModel viewModel = new SearchResultViewModel(e.Service)
                {
                    ProxyUrl = this.UseProxy ? this.ProxyUrl : null
                };
                _checkedResults.Add(viewModel);

                viewModel.Initialized += resultViewModel_Initialized;
                viewModel.Initialize();
            }
        }
Пример #3
0
 // Initializes the Service property
 private void initializeService(Action callback)
 {
     if (Result is ArcGISService)
     {
         Service = Result as ArcGISService; // Assume service reference is valid
         callback();
     }
     else if (Result is ArcGISPortalItem)
     {
         ArcGISService.GetServiceInfoAsync((string)Result.Url, null, (o, e) =>
         {
             Service = e.Service;
             callback();
         });
     }
 }
        /// <summary>
        /// Determines the map units for the map
        /// </summary>
        /// <param name="map">The map to find map units for</param>
        /// <param name="onComplete">The method to invoke once map units have been retrieved</param>
        /// <param name="onFailed">The method to invoke when map unit retrieval fails</param>
        public static void GetMapUnitsAsync(this Map Map, Action <LengthUnits> onComplete,
                                            Action onFailed = null)
        {
            if (Map != null)
            {
                Layer layer = Map.Layers.FirstOrDefault();
                if (layer != null)
                {
                    TileLayer tiledLayer = layer as TileLayer;
                    if (tiledLayer != null)
                    {
                        // Bing is web mercator
                        onComplete(LengthUnits.UnitsMeters);
                    }
                    else
                    {
                        OpenStreetMapLayer osmLayer = layer as OpenStreetMapLayer;
                        if (osmLayer != null)
                        {
                            // Open Streem map is web mercator
                            onComplete(LengthUnits.UnitsMeters);
                        }
                        else
                        {
                            // ArcGIS Server Base Map
                            string units    = null;
                            string layerUrl = null;
                            ArcGISTiledMapServiceLayer agsTiledlayer = layer as ArcGISTiledMapServiceLayer;
                            if (agsTiledlayer != null)
                            {
                                units    = agsTiledlayer.Units;
                                layerUrl = agsTiledlayer.Url;
                            }
                            else
                            {
                                ArcGISDynamicMapServiceLayer agsDynamicLayer = layer as ArcGISDynamicMapServiceLayer;
                                if (agsDynamicLayer != null)
                                {
                                    units    = agsDynamicLayer.Units;
                                    layerUrl = agsDynamicLayer.Url;
                                }
                                else
                                {
                                    ArcGISImageServiceLayer agsImageLayer = layer as ArcGISImageServiceLayer;
                                    if (agsImageLayer != null)
                                    {
                                        layerUrl = agsImageLayer.Url;
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(units))
                            {
                                units = units.Replace("esri", "Units"); // replace esri prefix
                                if (Enum.IsDefined(typeof(LengthUnits), units))
                                {
                                    onComplete((LengthUnits)Enum.Parse(typeof(LengthUnits), units, true));
                                }
                                else if (onFailed != null)
                                {
                                    onFailed();
                                }
                            }
                            else if (!string.IsNullOrEmpty(layerUrl))
                            {
                                ArcGISService.GetServiceInfoAsync(layerUrl, null, (o, e) =>
                                {
                                    if (e.Service != null && !string.IsNullOrEmpty(e.Service.Units))
                                    {
                                        string serviceUnits = e.Service.Units;
                                        serviceUnits        = serviceUnits.Replace("esri", "Units"); // replace esri prefix
                                        if (Enum.IsDefined(typeof(LengthUnits), serviceUnits))
                                        {
                                            onComplete((LengthUnits)Enum.Parse(typeof(LengthUnits), serviceUnits, true));
                                        }
                                        else if (onFailed != null)
                                        {
                                            onFailed();
                                        }
                                    }
                                });
                                return;
                            }
                        }
                    }
                }
            }
        }