private async void LoadRecursive(IList <LegendInfo> itemsList, ILayerContent content, bool recursive)
        {
            if (content == null)
            {
                return;
            }

            try
            {
#pragma warning disable ESRI1800 // Add ConfigureAwait(false) - This is UI Dependent code and must return to UI Thread
                var legendInfo = await content.GetLegendInfosAsync();

#pragma warning restore ESRI1800
                foreach (var item in legendInfo)
                {
                    itemsList.Add(item);
                }
            }
            catch
            {
                return;
            }

            if (recursive)
            {
                foreach (var item in content.SublayerContents)
                {
                    LoadRecursive(itemsList, item, recursive);
                }
            }
        }
        private void Layer_PropertyChanged(ILayerContent sender, string?propertyName)
        {
            var layer = sender as ILayerContent;

            if (layer is ILoadable loadable && propertyName == nameof(ILoadable.LoadStatus) && loadable.LoadStatus == LoadStatus.Loaded)
            {
                MarkCollectionDirty();
            }
示例#3
0
        private async Task <TreeViewItem> TraverseLayer(ILayerContent layer, TreeViewItem root)
        {
            try
            {
                Logging.LogMethodCall(MethodBase.GetCurrentMethod().DeclaringType.Name, () => new Dictionary <String, Object> {
                    { nameof(layer), layer },
                    { nameof(root), root }
                });
                root.CanDisable     = layer.CanChangeVisibility;
                root.IsChecked      = layer.IsVisible;
                root.MirrorToParent = false;
                root.Layer          = layer;
                IReadOnlyList <LegendInfo> lgnd = await layer.GetLegendInfosAsync();

                if (lgnd.Count() == 1)
                {
                    root.SetSymbol(lgnd[0].Symbol);
                }
                else
                {
                    List <String> labelsAdded = new List <String>();
                    foreach (var smbl in lgnd)
                    {
                        if (!labelsAdded.Contains(smbl.Name))
                        {
                            var item = new TreeViewItem(smbl.Name, smbl.Symbol);
                            item.CanDisable = false;
                            root.Children.Add(item);
                            labelsAdded.Add(smbl.Name);
                        }
                    }
                }
                foreach (var subLyr in layer.SublayerContents)
                {
                    var          info  = lgnd.FirstOrDefault(inf => inf.Name == subLyr.Name);
                    TreeViewItem child = null;
                    if (info == null)
                    {
                        child = await TraverseLayer(subLyr, new TreeViewItem(subLyr.Name));
                    }
                    else
                    {
                        child = await TraverseLayer(subLyr, new TreeViewItem(subLyr.Name, info.Symbol));
                    }
                    root.Children.Add(child);
                }
                return(root);
            }
            catch (Exception ex)
            {
                var message = "Error traversing layer";
                ErrorHelper.OnError(MethodBase.GetCurrentMethod().DeclaringType.Name, message, ex);
                Logging.LogMessage(Logging.LogType.Error, message, ex);
                return(root);
            }
        }
示例#4
0
        private static IEnumerable <LayerModel> CreateLayerModels(ILayerContent layer, int depth)
        {
            yield return(new LayerModel(layer, depth));

            depth++;
            foreach (var sublayerContent in layer.SublayerContents)
            {
                foreach (var flattened in CreateLayerModels(sublayerContent, depth))
                {
                    yield return(flattened);
                }
            }
        }
        public LayerContentViewModel(ILayerContent layerContent, WeakReference <GeoView> view, Symbology.Symbol symbol = null, bool generateLegend = true)
        {
            _context        = SynchronizationContext.Current ?? new SynchronizationContext();
            LayerContent    = layerContent;
            _view           = view;
            Symbol          = symbol;
            _generateLegend = generateLegend;
            if (LayerContent is INotifyPropertyChanged)
            {
                (LayerContent as INotifyPropertyChanged).PropertyChanged += LayerContentViewModel_PropertyChanged;
            }

            if (LayerContent.SublayerContents is INotifyCollectionChanged)
            {
                var incc     = LayerContent.SublayerContents as INotifyCollectionChanged;
                var listener = new Internal.WeakEventListener <INotifyCollectionChanged, object, NotifyCollectionChangedEventArgs>(incc);
                listener.OnEventAction  = (instance, source, eventArgs) => { LayerContentViewModel_CollectionChanged(source, eventArgs); };
                listener.OnDetachAction = (instance, weakEventListener) => instance.CollectionChanged -= weakEventListener.OnEvent;
                incc.CollectionChanged += listener.OnEvent;
            }

            if (layerContent is Esri.ArcGISRuntime.ILoadable)
            {
                var l = layerContent as Esri.ArcGISRuntime.ILoadable;
                UpdateLoadingStatus();
            }

            if (LayerContent is Layer)
            {
                Layer   layer = LayerContent as Layer;
                GeoView gview;
                if (layer.LoadStatus != LoadStatus.NotLoaded && _view.TryGetTarget(out gview))
                {
                    try
                    {
                        var viewState = gview.GetLayerViewState(layer);
                        UpdateLayerViewState(viewState);
                    }
                    catch (ArgumentException)
                    {
                    }
                }
                else
                {
                    UpdateLayerViewState(null);
                }
            }
        }
示例#6
0
        private TreeViewItem TraverseLayer(ILayerContent layer, TreeViewItem root)
        {
            root.CanDisable     = layer.CanChangeVisibility;
            root.IsChecked      = layer.IsVisible;
            root.MirrorToParent = false;
            Console.WriteLine(layer.SublayerContents.Count);
            root.Layer = layer;
            var lgnd = layer.GetLegendInfosAsync().Result;

            if (lgnd.Count == 1)
            {
                root.SetSymbol(lgnd[0].Symbol);
            }
            else
            {
                foreach (var smbl in lgnd)
                {
                    var item = new TreeViewItem(smbl.Name, smbl.Symbol);
                    item.CanDisable = false;
                    root.Children.Add(item);
                }
            }
            foreach (var subLyr in layer.SublayerContents)
            {
                var          info  = lgnd.FirstOrDefault(inf => inf.Name == subLyr.Name);
                TreeViewItem child = null;
                if (info == null)
                {
                    child = TraverseLayer(subLyr, new TreeViewItem(subLyr.Name));
                }
                else
                {
                    child = TraverseLayer(subLyr, new TreeViewItem(subLyr.Name, info.Symbol));
                }
                root.Children.Add(child);
            }
            return(root);
        }
示例#7
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
        {
            try
            {
                // Perform an identify across all layers, taking up to 10 results per layer.
                IReadOnlyList <IdentifyLayerResult> myIdentifyLayerResults = await MyMapView.IdentifyLayersAsync(e.Position, 15, false, 10);

                // Loop through each layer result in the collection of identify layer results.
                foreach (IdentifyLayerResult layerResult in myIdentifyLayerResults)
                {
                    // Get the layer content from the layer result.
                    ILayerContent myLayerContent = layerResult.LayerContent;

                    // Get the name of the layer content (i.e. the name of the layer).
                    string lc_Name = myLayerContent.Name;

                    // We are only interested in the identify layer results for the created feature collection layer that
                    // was generated from the NY Times articles.
                    if (lc_Name == "JoinedFCL")
                    {
                        // Get the sub layer results for the NY Times generated feature collection layer.
                        IReadOnlyList <IdentifyLayerResult> myIdentifyLayerResultsSubLayer = layerResult.SublayerResults;

                        // Get the first result found from identify operation on the NY Times generated feature collection layer.
                        IdentifyLayerResult myIdentifyLayerResultNYTimesFeatureCollectionTable = myIdentifyLayerResultsSubLayer.First();

                        // Get the geo-element collection from the first result.
                        IReadOnlyList <GeoElement> myGeoElements = myIdentifyLayerResultNYTimesFeatureCollectionTable.GeoElements;

                        // Get the first geo-element in the geo-element collection. This is the identified country (via the mouse click/tap)
                        // in the NY Times feature collection layer.
                        GeoElement myGeoElement = myGeoElements.First();

                        // Loop through key/value pair of the features attributes in the NY Times feature collection layer.
                        foreach (KeyValuePair <string, object> myKeyValuePair in myGeoElement.Attributes)
                        {
                            // Get the key (aka. field name).
                            var myKey = myKeyValuePair.Key;

                            // Get the value (aka. the text for the record of a specific field).
                            var myValue = myKeyValuePair.Value;

                            // Check is the name of the field in the NY Times feature collection layer 'AreaName'. This represents the country name.
                            if (myKey == "AreaName")
                            {
                                // Read the NY Times data from the text file and get back a list of each article.
                                // The format of each record/article will look like:
                                // [Article summary]~[Article abstract]~[Country name]~[Url to the NY times article]~[Url to an image about the NY times article]~[Date of NY Times news article]
                                // Ex:
                                // Netanyahu not happy with Cohen~A spokesman for Prime Minister Benjamin Netanyahu disagrees with Roger Cohen’s “pessimism.”~Israel~https://www.nytimes.com/2018/01/02/opinion/israel-future.html~https://www.nytimes.com/images/2017/12/29/opinion/29cohenWeb/29cohenWeb-thumbLarge.jpg~20180102
                                List <string> myNYTimesArticles = ReadTextFile3(_NEWSFILE);

                                // Create a FlowDocument to contain content for the RichTextBox.
                                FlowDocument myFlowDoc = new FlowDocument();

                                // Loop through each NY Times article.
                                foreach (var oneNYTimesArticle in myNYTimesArticles)
                                {
                                    // Char array to remove embedded double quotes from various NT Times strings.
                                    char[] charsToTrim = { '"' };

                                    // Get various sub-parts of the records for each NY Times article.
                                    string title    = oneNYTimesArticle.Split('~')[0].Trim(charsToTrim);
                                    string absrtact = oneNYTimesArticle.Split('~')[1].Trim(charsToTrim);
                                    string country  = oneNYTimesArticle.Split('~')[2].Trim(charsToTrim);
                                    string newsurl  = oneNYTimesArticle.Split('~')[3].Trim(charsToTrim);
                                    string imageurl = oneNYTimesArticle.Split('~')[4].Trim(charsToTrim);
                                    string date     = oneNYTimesArticle.Split('~')[5].Trim(charsToTrim);

                                    // Find a match from the NY Times feature collection layer feature country name and the NY
                                    // Times country name in the article.
                                    if (myValue.ToString() == country)
                                    {
                                        // Create a paragraph.
                                        Paragraph myParagraph = new Paragraph();

                                        myParagraph.FontSize = 18;

                                        // Create a run that contains the country and a new line.
                                        Run myRun = new Run(myValue.ToString() + System.Environment.NewLine);

                                        // Create a bold that contains short title (aka news headline) of the NY Times article.
                                        Bold myBold = new Bold(new Run(title));

                                        // Create a run that contains a new line.
                                        Run myRun2 = new Run(System.Environment.NewLine);

                                        // Create a new run that contains the hyperlink to the NY Times article.
                                        Run myRun7 = new Run(newsurl);

                                        // Create a new hyperlink based on the run.
                                        Hyperlink myHP = new Hyperlink(myRun7);

                                        // Set the hyperlink to the uri of the NY Times news article.
                                        myHP.NavigateUri = new Uri(newsurl);

                                        // Wire up the event handler when the user holds down the CTRL key and presses on the hyperlink for
                                        // the NY Times article shown in the rich text box.
                                        myHP.Click += MyHP_Click;

                                        // Add all of the sub components of the paragraph that make up what will be displayed for each NY
                                        // Times article in the rich text box.
                                        myParagraph.Inlines.Add(myRun);
                                        myParagraph.Inlines.Add(myBold);
                                        myParagraph.Inlines.Add(myRun2);
                                        myParagraph.Inlines.Add(myHP);

                                        // Add the paragraph to the flow document's block collection.
                                        myFlowDoc.Blocks.Add(myParagraph);
                                    }
                                }

                                // Make sure that the user is able to click on hyper links in the rick text box. Requires that the .IsDocumentEnabled be true.
                                MyRichTextBox.IsDocumentEnabled = true;

                                // Add initial content to the RichTextBox.
                                MyRichTextBox.Document = myFlowDoc;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
示例#8
0
 public LayerModel(ILayerContent layer, int ancestors)
 {
     this.Ancestors = ancestors;
     this.Layer     = layer;
 }
        public LayerContentViewModel(ILayerContent layerContent, WeakReference <GeoView> view, Symbology.Symbol symbol = null, bool generateLegend = true)
        {
            _context        = SynchronizationContext.Current ?? new SynchronizationContext();
            LayerContent    = layerContent;
            _view           = view;
            Symbol          = symbol;
            _generateLegend = generateLegend;
            if (LayerContent is INotifyPropertyChanged)
            {
                (LayerContent as INotifyPropertyChanged).PropertyChanged += LayerContentViewModel_PropertyChanged;
            }

            if (LayerContent.SublayerContents is INotifyCollectionChanged)
            {
                var incc     = LayerContent.SublayerContents as INotifyCollectionChanged;
                var listener = new Internal.WeakEventListener <INotifyCollectionChanged, object, NotifyCollectionChangedEventArgs>(incc);
                listener.OnEventAction  = (instance, source, eventArgs) => { LayerContentViewModel_CollectionChanged(source, eventArgs); };
                listener.OnDetachAction = (instance, weakEventListener) => instance.CollectionChanged -= weakEventListener.OnEvent;
                incc.CollectionChanged += listener.OnEvent;
            }

            if (layerContent is Esri.ArcGISRuntime.ILoadable)
            {
                var l = layerContent as Esri.ArcGISRuntime.ILoadable;
                ReloadCommand = _reloadCommand = new DelegateCommand(
                    (s) =>
                {
                    l.RetryLoadAsync();
                    UpdateLoadingStatus();
                },
                    (s) =>
                {
                    return(l.LoadStatus == Esri.ArcGISRuntime.LoadStatus.FailedToLoad);
                });
                UpdateLoadingStatus();
            }
            else
            {
                ReloadCommand = _reloadCommand = new DelegateCommand((s) => { }, (s) => { return(false); });
            }

            if (LayerContent is Layer)
            {
                Layer   layer = LayerContent as Layer;
                GeoView gview;
                if (layer.LoadStatus != LoadStatus.NotLoaded && _view.TryGetTarget(out gview))
                {
                    try
                    {
                        var viewState = gview.GetLayerViewState(layer);
                        UpdateLayerViewState(viewState);
                    }
                    catch (ArgumentException)
                    {
                    }
                }
                else
                {
                    UpdateLayerViewState(null);
                }
            }

            ZoomToCommand = _zoomToCommand = new DelegateCommand(
                (s) =>
            {
                GeoView gview;
                bool hasView = _view.TryGetTarget(out gview);
                if (hasView)
                {
                    var vp = GetExtent();
                    if (vp != null)
                    {
                        gview.SetViewpointAsync(vp);
                    }
                }
            }, (s) =>
            {
                GeoView gview;
                return(_view.TryGetTarget(out gview) && GetExtent() != null);
            });
        }