} // end SelectedItem /// Build the layer OC recursively public static void BuildLayerInfoList(LayerInfoVM root, IList <LayerInfoVM> result) { // Add the root node to the result list. result.Add(root); // Initialize the child collection for the root. root.Children = new List <LayerInfoVM>(); // Recursively add sublayers. foreach (WmsLayerInfo layer in root.Info.LayerInfos) { if (!layer.Title.Contains("OrbitTracks")) { // Create the view model for the sublayer. LayerInfoVM layerVM = new LayerInfoVM(layer, root, false); // Add the sublayer to the root's sublayer collection. root.Children.Add(layerVM); // Recursively add children. BuildLayerInfoList(layerVM, result); } } // end foreach } // end BuildLayerInfoList
/// Layer Info View Model public LayerInfoVM(WmsLayerInfo info, LayerInfoVM parent, bool selected) { Info = info; Parent = parent; Selected = selected; Title = info.Title; } // end LayerInfoClass
} // end MainWindow /// <summary> /// Open WMS service and store the list of imagery /// preserving hierarchy, if any /// Source: Runtime wms Service catalog /// MOD - pass in serviceurl /// </summary> private async void InitializeWMSLayer_VM() { // Initialize the display with a basemap // Reset Map projection if applicable Map myMap = new Map(SpatialReference.Create(4326)); baseImageLayer = new ArcGISMapImageLayer(new Uri( "https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer")); // Add baseImageLayer to the Map myMap.OperationalLayers.Add(baseImageLayer); // Assign the map to the MapView BasemapView.Map = myMap; // Create the WMS Service Load data from the URI // Create WMS Service service with default uri serviceURI = new Uri(wmsUriStartup.capableUri); serviceWMS = new WmsService(serviceURI); // If service can load, initialize the app try { // Load the WMS Service. await serviceWMS.LoadAsync(); // Get the service info (metadata) from the service. WmsServiceInfo info = serviceWMS.ServiceInfo; // Process info to get information for all the layers // for the given serviceUri // LayerInfos gets a list of sublayers for a given layer IList <LayerInfoVM> temp = new List <LayerInfoVM>(); foreach (WmsLayerInfo layerInfo in info.LayerInfos) { LayerInfoVM.BuildLayerInfoList(new LayerInfoVM(layerInfo, null, false), _layerInfoOC); } // NASA GIBS Specific #region NASA string epsg = wmsUriStartup.EPSG.Substring(0, 4) + ":" + wmsUriStartup.EPSG.Substring(4, 4); ProductLabel.Content = "NASA GIBS for EODIS: " + wmsUriStartup.latency.ToUpper() + " - " + epsg.ToUpper(); Sort_NASA_GIBS(_layerInfoOC, out temp); _layerInfoOC.Clear(); foreach (LayerInfoVM layerInfo in temp) { _layerInfoOC.Add(layerInfo); } #endregion NASA // Update the map display based on the viewModel. UpdateViewModel(_layerInfoOC); // Update Product List //ProductTreeView.ItemsSource = _layerInfoOC; ProductList.ItemsSource = _layerInfoOC; } // end try catch (Exception e) { MessageBox.Show(e.ToString(), "WMS SERVER LOAD ERROR"); } } // end InitializeWMSLayer_VM
} // end MainWindow /// <summary> /// Open WMS service and store the list of imagery /// perserving heirarchy, if any /// Source: Runtime wms Service catalog /// MOD - pass in serviceurl /// </summary> private async void InitializeWMSLayer_VM() { // Initialize the display with a basemap // BasemapView is UI esri mapview name in XAML // Reset Map projection if applicable Map myMap = new Map(SpatialReference.Create(4326)); baseImageLayer = new ArcGISMapImageLayer(new Uri( "https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer")); // Add baseImageLayer to the Map myMap.OperationalLayers.Add(baseImageLayer); // Assign the map to the MapView BasemapView.Map = myMap; // Create the WMS Service Load data from the URI // Create WMS Service service with default uri serviceURI = new Uri(wmsUriStartup.capableUri); serviceWMS = new WmsService(serviceURI); // If service can load, initialize the app try { // Load the WMS Service. await serviceWMS.LoadAsync(); // Get the service info (metadata) from the service. WmsServiceInfo info = serviceWMS.ServiceInfo; // Process info to get information for all the layers // for the given serviceUri // LayerInfos gets a list of sublayers for a given layer foreach (var layerInfo in info.LayerInfos) { LayerInfoVM.BuildLayerInfoList(new LayerInfoVM(layerInfo, null, false), _layerInfoOC); } // Sort Layers // This sorts list but list does not get passed to Itemsource /* * List<WmsLayerInfo> sortedWmsInfo = new List<WmsLayerInfo>(); * ObservableCollection<LayerInfoVM> SortedList = new ObservableCollection<LayerInfoVM>( _layerInfoOC.OrderBy(o => o.Info.Title).ToList()) * _layerInfoOC = new ObservableCollection<LayerInfoVM>(SortedList); * foreach (LayerInfoVM layerInfo in _layerInfoOC) * Debug.WriteLine(layerInfo.Info.Title + " " + layerInfo.Info.Name); * Debug.WriteLine("Counts: " + _layerInfoOC.Count + " " + SortedList.Count); */ // Update the map display based on the viewModel. UpdateViewModel(_layerInfoOC); // Update UI element ProductLabel.Content = "NASA GIBS - " + wmsUriStartup.EPSG + " - " + wmsUriStartup.latency; ProductTreeView.ItemsSource = _layerInfoOC.Take(1); } // end try catch (Exception e) { MessageBox.Show(e.ToString(), "WMS SERVER LOAD ERROR"); } } // end InitializeWMSLayer_VM