private async void btnRefresh_Click(object sender, RoutedEventArgs e) { // UserSession.ClientSideObject.Capabilities = await WMSProviderBase.WMSCapabilitiesRetrieve(UserSession.strWMSGeoserverUrl); string strWMSGeoserverUrl = ConfigurationManager.AppSettings["WMSGeoserver"]; if (string.IsNullOrEmpty(strWMSGeoserverUrl)) { return; } WMSCapabilities Capabilities = await WMSProviderBase.WMSCapabilitiesRetrieve(strWMSGeoserverUrl); //if (UserSession.ClientSideObject.Capabilities.Error != null) //{ // string Msg = "WMS Server:" + "\n"; // Msg = Msg + UserSession.ClientSideObject.Capabilities.Error; // ComponentsUtility.KGMsgBox.ShowCustomMsgOk(System.Windows.Application.Current.MainWindow, // Msg, 5000, true); //} //else //{ // SetData(); //} SetData(); }
protected static AVList wmsGetParamsFromCapsDoc(WMSCapabilities caps, AVList parameters) { if (caps == null) { String message = Logging.getMessage("nullValue.WMSCapabilities"); Logging.logger().severe(message); throw new ArgumentException(message); } if (parameters == null) { String message = Logging.getMessage("nullValue.ElevationModelConfigParams"); Logging.logger().severe(message); throw new ArgumentException(message); } String wmsVersion; try { wmsVersion = caps.getVersion(); getWMSElevationModelConfigParams(caps, formatOrderPreference, parameters); } catch (ArgumentException e) { String message = Logging.getMessage("WMS.MissingLayerParameters"); Logging.logger().severe(message, e); throw new ArgumentException(message, e); } catch (WWRuntimeException e) { String message = Logging.getMessage("WMS.MissingCapabilityValues"); Logging.logger().severe(message, e); throw new ArgumentException(message, e); } wmsSetFallbacks(parameters); parameters.setValue(AVKey.TILE_URL_BUILDER, new URLBuilder(wmsVersion, parameters)); return(parameters); }
/** * Extracts parameters necessary to configure the layer from a WMS capabilities document. * * @param caps the capabilities document. * @param parameters an attribute-value list in which to place the extracted parameters. May be null, in which case a * new attribute-value list is created and returned. * * @return the attribute-value list passed as the second parameter, or the list created if the second parameter is * null. * * @throws ArgumentException if the capabilities document reference is null. */ public static AVList wmsGetParamsFromCapsDoc(WMSCapabilities caps, AVList parameters) { if (caps == null) { String message = Logging.getMessage("nullValue.WMSCapabilities"); Logging.logger().severe(message); throw new ArgumentException(message); } if (parameters == null) { parameters = new AVListImpl(); } try { DataConfigurationUtils.getWMSLayerConfigParams(caps, formatOrderPreference, parameters); } catch (ArgumentException e) { String message = Logging.getMessage("WMS.MissingLayerParameters"); Logging.logger().log(java.util.logging.Level.SEVERE, message, e); throw new ArgumentException(message, e); } catch (WWRuntimeException e) { String message = Logging.getMessage("WMS.MissingCapabilityValues"); Logging.logger().log(java.util.logging.Level.SEVERE, message, e); throw new ArgumentException(message, e); } setFallbacks(parameters); // Setup WMS URL builder. parameters.setValue(AVKey.WMS_VERSION, caps.getVersion()); parameters.setValue(AVKey.TILE_URL_BUILDER, new URLBuilder(params)); // Setup default WMS tiled image layer behaviors. parameters.setValue(AVKey.USE_TRANSPARENT_TEXTURES, true); return(parameters); }
/** * Checks a session cache for a specified key, and if present attempts to interpret the cache entry as a {@link * WMSCapabilities} document. If the key does not map to a Capabilities document for any reason, this attempts to * asynchronously retrieve the Capabilities from a specified URL, and returns null. * * @param url the URL contents to retrieve. * @param cache the session cache. * @param cacheKey the key to identify the object in the session cache. * @param absentResourceList the absent resource list to update. * @param resourceID the resource ID to use in the absent resource list. * @param propertyListener the property change listener which is fired when the retrieved data is available. * @param propertyName the property name to fire when retrieved data is available. * * @return the Capabilities document in the session cache, or null if the document is not in the cache. * * @throws ArgumentException if either the url, retrieval service, cache or cache key are null. */ public static WMSCapabilities getOrRetrieveSessionCapabilities(java.net.URL url, SessionCache cache, Object cacheKey, AbsentResourceList absentResourceList, long resourceID, PropertyChangeListener propertyListener, String propertyName) { if (url == null) { String message = Logging.getMessage("nullValue.URLIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (cache == null) { String message = Logging.getMessage("nullValue.CacheIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (cacheKey == null) { String message = Logging.getMessage("nullValue.CacheKeyIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } WMSCapabilities caps = getSessionCapabilities(cache, cacheKey, url.ToString()); if (caps != null) { return(caps); } retrieveSessionData(url, cache, cacheKey, absentResourceList, resourceID, propertyListener, propertyName); // Try to get the caps after the retrieval attempt. return(getSessionCapabilities(cache, cacheKey, url.ToString())); }
/** * Create an object such as a layer or elevation model given a local OGC capabilities document containing named * layer descriptions. * * @param capsFileName the path to the capabilities file. The file must be either an absolute path or a relative * path available on the classpath. The file contents must be a valid OGC capabilities * document. * @param parameters a list of configuration properties. These properties override any specified in the * capabilities document. The list should contain the {@link AVKey#LAYER_NAMES} property for * services that define layer, indicating which named layers described in the capabilities * document to create. If this argumet is null or contains no layers, the first named layer is * used. * * @return the requested object. * * @throws ArgumentException if the file name is null or empty. * @throws IllegalStateException if the capabilites document contains no named layer definitions. * @throws WWRuntimeException if an error occurs while opening, reading or parsing the capabilities document. * The exception indicating the source of the failure is included as the {@link * Exception#initCause(Throwable)}. */ public object createFromCapabilities(string capsFileName, AVList parameters) { if (WWUtil.isEmpty(capsFileName)) { string message = Logging.getMessage("nullValue.FilePathIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } WMSCapabilities caps = new WMSCapabilities(capsFileName); try { caps.parse(); } catch (javax.xml.stream.XMLStreamException e) { string message = Logging.getMessage("generic.CannotParseCapabilities", capsFileName); Logging.logger().log(Level.SEVERE, message, e); throw new WWRuntimeException(message, e); } return(this.doCreateFromCapabilities(caps, parameters)); }
public WMSTiledImageLayer(WMSCapabilities caps, AVList parameters) { this(wmsGetParamsFromCapsDoc(caps, parameters)); }
public async static Task <WMSCapabilities> WMSCapabilitiesRetrieve(string WMSGeoserverUrl) { WMSCapabilities Capabilities = new WMSCapabilities(); Capabilities.Layers = new List <CustomImageInfo>(); if (string.IsNullOrEmpty(WMSGeoserverUrl)) { return(null); } string result = string.Empty; string BaseUrlFormat = "{0}://{1}:{2}/"; using (var client = new HttpClient()) { client.Timeout = new TimeSpan(0, 0, 15); HttpResponseMessage response = null; try { Uri u = new Uri(WMSGeoserverUrl); string BaseUrl = string.Format(CultureInfo.InvariantCulture, BaseUrlFormat, u.Scheme, u.Host, u.Port); string ReqUrl = u.PathAndQuery + "?request=getCapabilities"; client.BaseAddress = new Uri(BaseUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); response = await client.GetAsync(ReqUrl); if (response.IsSuccessStatusCode == false) { return(null); } using (HttpContent content = response.Content) { result = await content.ReadAsStringAsync(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(result); XmlNodeList CapabilitiesNodes = doc.GetElementsByTagName("WMS_Capabilities"); XmlNode CapabilitiesNode = CapabilitiesNodes[0]; Capabilities.Version = CapabilitiesNode.Attributes["version"].Value; XmlNodeList Layers = doc.GetElementsByTagName("Layer"); foreach (XmlNode layer in Layers) { foreach (XmlNode ch in layer.ChildNodes) { if (ch.Name == "Layer") { CustomImageInfo ImageInfo = new CustomImageInfo(); foreach (XmlNode l in ch.ChildNodes) { if (l.Name == "Name") { ImageInfo.MapName = l.InnerText; } if (l.Name == "EX_GeographicBoundingBox") { foreach (XmlNode b in l.ChildNodes) { if (b.Name == "westBoundLongitude") { double.TryParse(b.InnerText, out ImageInfo.MinX); } else if (b.Name == "eastBoundLongitude") { double.TryParse(b.InnerText, out ImageInfo.MaxX); } else if (b.Name == "southBoundLatitude") { double.TryParse(b.InnerText, out ImageInfo.MinY); } else if (b.Name == "northBoundLatitude") { double.TryParse(b.InnerText, out ImageInfo.MaxY); } } } } Capabilities.Layers.Add(ImageInfo); } } } return(Capabilities); } catch (Exception ex) { Capabilities.Error = ex; return(Capabilities); } } }
public WMSBasicElevationModel(WMSCapabilities caps, AVList parameters) : this(wmsGetParamsFromCapsDoc(caps, parameters)) { }
//**************************************************************// //******************** Configuration *************************// //**************************************************************// /** * Parses WMSBasicElevationModel configuration parameters from a specified WMS Capabilities source. This writes * output as key-value pairs to parameters. Supported key and parameter names are: <table> * <th><td>Parameter</td><td>Value</td><td>Type</td></th> <tr><td>{@link AVKey#ELEVATION_MAX}</td><td>WMS layer's * maximum extreme elevation</td><td>Double</td></tr> <tr><td>{@link AVKey#ELEVATION_MIN}</td><td>WMS layer's * minimum extreme elevation</td><td>Double</td></tr> <tr><td>{@link AVKey#DATA_TYPE}</td><td>Translate WMS layer's * image format to a matching data type</td><td>String</td></tr> </table> This also parses common WMS layer * parameters by invoking {@link DataConfigurationUtils#getWMSLayerConfigParams(gov.nasa.worldwind.ogc.wms.WMSCapabilities, * String[], SharpEarth.avlist.AVList)}. * * @param caps the WMS Capabilities source to parse for WMSBasicElevationModel configuration * parameters. * @param formatOrderPreference an ordered array of preferred image formats, or null to use the default format. * @param parameters the output key-value pairs which recieve the WMSBasicElevationModel configuration * parameters. * * @return a reference to parameters. * * @throws ArgumentException if either the document or parameters are null, or if parameters does not contain the * required key-value pairs. * @throws SharpEarth.exception.WWRuntimeException * if the Capabilities document does not contain any of the required information. */ public static AVList getWMSElevationModelConfigParams(WMSCapabilities caps, String[] formatOrderPreference, AVList parameters) { if (caps == null) { String message = Logging.getMessage("nullValue.WMSCapabilities"); Logging.logger().severe(message); throw new ArgumentException(message); } if (parameters == null) { String message = Logging.getMessage("nullValue.ElevationModelConfigParams"); Logging.logger().severe(message); throw new ArgumentException(message); } // Get common WMS layer parameters. DataConfigurationUtils.getWMSLayerConfigParams(caps, formatOrderPreference, parameters); // Attempt to extract the WMS layer names from the specified parameters. String layerNames = parameters.getStringValue(AVKey.LAYER_NAMES); if (layerNames == null || layerNames.Length == 0) { String message = Logging.getMessage("nullValue.WMSLayerNames"); Logging.logger().severe(message); throw new ArgumentException(message); } String[] names = layerNames.Split(','); if (names == null || names.Length == 0) { String message = Logging.getMessage("nullValue.WMSLayerNames"); Logging.logger().severe(message); throw new ArgumentException(message); } // Get the layer's extreme elevations. Double[] extremes = caps.getLayerExtremeElevations(names); Double d = (Double)parameters.getValue(AVKey.ELEVATION_MIN); if (d == null && extremes != null && extremes[0] != null) { parameters.setValue(AVKey.ELEVATION_MIN, extremes[0]); } d = (Double)parameters.getValue(AVKey.ELEVATION_MAX); if (d == null && extremes != null && extremes[1] != null) { parameters.setValue(AVKey.ELEVATION_MAX, extremes[1]); } // Compute the internal pixel type from the image format. if (parameters.getValue(AVKey.DATA_TYPE) == null && parameters.getValue(AVKey.IMAGE_FORMAT) != null) { String s = WWIO.makeDataTypeForMimeType(parameters.getValue(AVKey.IMAGE_FORMAT).ToString()); if (s != null) { parameters.setValue(AVKey.DATA_TYPE, s); } } // Use the default data type. if (parameters.getValue(AVKey.DATA_TYPE) == null) { parameters.setValue(AVKey.DATA_TYPE, AVKey.INT16); } // Use the default byte order. if (parameters.getValue(AVKey.BYTE_ORDER) == null) { parameters.setValue(AVKey.BYTE_ORDER, AVKey.LITTLE_ENDIAN); } return(parameters); }
public async Task <Exception> InitMapsAsync() { try { UserMaps usermaps = null; this.strWMSGeoserverUrl = ConfigurationManager.AppSettings["WMSGeoserver"]; string strMapCache_Path = ConfigurationManager.AppSettings["MapCache_Path"]; string strMapCacheEnable = ConfigurationManager.AppSettings["MapCacheEnable"]; bool MapCacheEnable = false; if (string.IsNullOrEmpty(strMapCacheEnable) == false) { if (strMapCacheEnable.ToLower() == "false") { MapCacheEnable = false; } else { MapCacheEnable = true; } } // string strWMSGeoserverUrl = ConfigurationManager.AppSettings["WMSGeoserver"]; if (string.IsNullOrEmpty(strWMSGeoserverUrl)) { return(null); } WMSCapabilities Capabilities = await WMSProviderBase.WMSCapabilitiesRetrieve(strWMSGeoserverUrl); if (Capabilities != null && Capabilities.Error == null) { List <WMSProviderBase> overlays = new List <WMSProviderBase>(); WMSProviderBase MapProvider = null; if (VMMainViewModel.Instance.SimulationHubProxy != null) { usermaps = await SAGSignalR.GetUserMaps(VMMainViewModel.Instance.SimulationHubProxy, UserName); UserParameters userParameters = await SAGSignalR.GetUserParameters(VMMainViewModel.Instance.SimulationHubProxy, UserName); if (usermaps != null) { foreach (UserMapPreference info in usermaps.maps) { if (overlays.Exists(t => t.Name == info.MapName)) { continue; } bool isExist = Capabilities.Layers.Exists(t => t.MapName == info.MapName); if (isExist) { WMSProviderBase provider = new WMSProviderBase(info.MapName); provider.Init(strWMSGeoserverUrl, info.MapName, "png"); provider.MinZoom = info.MinZoom; provider.MaxZoom = info.MaxZoom; overlays.Add(provider); if (MapProvider == null) { MapProvider = provider; } } } } if (MapProvider != null) { MapProvider.overlays = overlays.ToArray(); p_objMap.MapProvider = MapProvider; if (MapCacheEnable && string.IsNullOrEmpty(strMapCache_Path) == false) { p_objMap.Manager.Mode = AccessMode.ServerAndCache; p_objMap.CacheLocation = strMapCache_Path; } // p_objMap.Manager.Mode = AccessMode.ServerOnly; //TEMP // p_objMap.Manager.Mode = AccessMode.ServerAndCache; p_objMap.Manager.MemoryCache.Capacity = 44; p_objMap.Zoom = 10; if (userParameters != null) { p_objMap.Position = new PointLatLng(userParameters.MapHomeCenterY, userParameters.MapHomeCenterX); p_objMap.Zoom = userParameters.MapHomeZoom; } p_objMap.ShowTileGridLines = false; p_objMap.InvalidateVisual(true); } // p_objMap.enGMapProvider = enGMapProviders.WMSCustomProvider; } } return(Capabilities.Error); } catch (Exception ex) { return(ex); } return(null); }
public async void SetData() { string strWMSGeoserverUrl = ConfigurationManager.AppSettings["WMSGeoserver"]; if (string.IsNullOrEmpty(strWMSGeoserverUrl)) { return; } WMSCapabilities Capabilities = await WMSProviderBase.WMSCapabilitiesRetrieve(strWMSGeoserverUrl); List <WMSProviderSelectedMaps> HelperList = new List <WMSProviderSelectedMaps>(); if (Capabilities != null) { //List<GMap.NET.MapProviders.GMapProvider> Layers = null; // Layers = UserSession.ClientSideObject.GetGMapLayers(); UserMaps Layers = await SAGSignalR.GetUserMaps(VMMainViewModel.Instance.SimulationHubProxy, VMMainViewModel.Instance.UserName); int n = 1000; foreach (CustomImageInfo Info in Capabilities.Layers) { n++; WMSProviderSelectedMaps map = new WMSProviderSelectedMaps(); map.MapName = Info.MapName; map.isSelected = false; map.SeqNumber = n; map.UserMinZoom = 0; map.UserMaxZoom = 24; HelperList.Add(map); } if (Layers != null) { for (int i = 0; i < Layers.maps.Length; i++) { UserMapPreference layer = Layers.maps[i]; WMSProviderSelectedMaps map = HelperList.Where(l => l.MapName == layer.MapName).SingleOrDefault(); if (map != null) { map.SeqNumber = i; map.isSelected = true; map.UserMinZoom = layer.MinZoom; map.UserMaxZoom = (int)layer.MaxZoom; } } } HelperList.Sort(delegate(WMSProviderSelectedMaps Struct1, WMSProviderSelectedMaps Struct2) { int Compare = 0; if (Struct2.SeqNumber < Struct1.SeqNumber) { Compare = 1; } else if (Struct2.SeqNumber == Struct1.SeqNumber) { Compare = 0; } else { Compare = -1; } return(Compare); }); } dataGridLayerName.ItemsSource = null; dataGridLayerName.ItemsSource = HelperList; }