private WmsProvider(Client wmsClient, Func <string, Task <Stream> > getStreamAsync = null) { InitialiseGetStreamAsyncMethod(getStreamAsync); _wmsClient = wmsClient; TimeOut = 10000; ContinueOnError = true; if (OutputFormats.Contains("image/png")) { _mimeType = "image/png"; } else if (OutputFormats.Contains("image/gif")) { _mimeType = "image/gif"; } else if (OutputFormats.Contains("image/jpeg")) { _mimeType = "image/jpeg"; } else //None of the default formats supported - Look for the first supported output format { throw new ArgumentException( "None of the formates provided by the WMS service are supported"); } LayerList = new Collection <string>(); StylesList = new Collection <string>(); }
/// <summary> /// Sets the image type to use when requesting images from the WMS server /// </summary> /// <remarks> /// <para>See the <see cref="OutputFormats"/> property for a list of available mime types supported by the WMS server</para> /// </remarks> /// <exception cref="ArgumentException">Throws an exception if either the mime type isn't offered by the WMS /// or GDI+ doesn't support this mime type.</exception> /// <param name="mimeType">Mime type of image format</param> public void SetImageFormat(string mimeType) { if (!OutputFormats.Contains(mimeType)) { throw new ArgumentException("WMS service doesn't not offer mimetype '" + mimeType + "'"); } _mimeType = mimeType; }
/// <summary> /// Initializes a new layer, and downloads and parses the service description /// </summary> /// <param name="layername">Layername</param> /// <param name="url">Url of WMS server</param> /// <param name="cachetime">Time for caching Service Description (ASP.NET only)</param> /// <param name="proxy">Proxy</param> /// <param name="credentials"></param> public WmsLayer(string layername, string url, TimeSpan cachetime, WebProxy proxy, ICredentials credentials) { _Proxy = proxy; _TimeOut = 10000; LayerName = layername; _ContinueOnError = true; _Credentials = credentials; if (HttpContext.Current != null && HttpContext.Current.Cache["SharpMap_WmsClient_" + url] != null) { wmsClient = (Client)HttpContext.Current.Cache["SharpMap_WmsClient_" + url]; } else { wmsClient = new Client(url, _Proxy, _Credentials); if (HttpContext.Current != null) { HttpContext.Current.Cache.Insert("SharpMap_WmsClient_" + url, wmsClient, null, Cache.NoAbsoluteExpiration, cachetime); } } //Set default mimetype - We prefer compressed formats if (OutputFormats.Contains("image/jpeg")) { _MimeType = "image/jpeg"; } else if (OutputFormats.Contains("image/png")) { _MimeType = "image/png"; } else if (OutputFormats.Contains("image/gif")) { _MimeType = "image/gif"; } else //None of the default formats supported - Look for the first supported output format { bool formatSupported = false; foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders()) { if (OutputFormats.Contains(encoder.MimeType.ToLower())) { formatSupported = true; _MimeType = encoder.MimeType; break; } } if (!formatSupported) { throw new ArgumentException( "GDI+ doesn't not support any of the mimetypes supported by this WMS service"); } } _LayerList = new Collection <string>(); _StylesList = new Collection <string>(); }
private void Initialize() { continueOnError = true; if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Cache["SharpMap_WmsClient_" + url] != null) { wmsClient = (SharpMap.Web.Wms.Client)System.Web.HttpContext.Current.Cache["SharpMap_WmsClient_" + url]; } else { wmsClient = new SharpMap.Web.Wms.Client(url, proxy); if (System.Web.HttpContext.Current != null) { System.Web.HttpContext.Current.Cache.Insert("SharpMap_WmsClient_" + url, wmsClient, null, System.Web.Caching.Cache.NoAbsoluteExpiration, cachetime); } } //Set default mimetype - We prefer compressed formats if (OutputFormats.Contains("image/jpeg")) { mimeType = "image/jpeg"; } else if (OutputFormats.Contains("image/png")) { mimeType = "image/png"; } else if (OutputFormats.Contains("image/gif")) { mimeType = "image/gif"; } else //None of the default formats supported - Look for the first supported output format { bool formatSupported = false; foreach (System.Drawing.Imaging.ImageCodecInfo encoder in System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()) { if (OutputFormats.Contains(encoder.MimeType.ToLower())) { formatSupported = true; mimeType = encoder.MimeType; break; } } if (!formatSupported) { throw new ArgumentException("GDI+ doesn't not support any of the mimetypes supported by this WMS service"); } } layerList = new Collection <string>(); stylesList = new Collection <string>(); }
private WmsProvider(Client wmsClient) { this.wmsClient = wmsClient; TimeOut = 10000; ContinueOnError = true; if (OutputFormats.Contains("image/png")) mimeType = "image/png"; else if (OutputFormats.Contains("image/gif")) mimeType = "image/gif"; else if (OutputFormats.Contains("image/jpeg")) mimeType = "image/jpeg"; else //None of the default formats supported - Look for the first supported output format { throw new ArgumentException( "None of the formates provided by the WMS service are supported"); } LayerList = new Collection<string>(); StylesList = new Collection<string>(); }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="layername"></param> /// <param name="wmsClient"></param> public WmsLayer(string layername, Client wmsClient) : base(new Style(), new NullRenderer()) { _wmsClient = wmsClient; _continueOnError = true; LayerName = layername; //Set default mimetype - We prefer compressed formats if (OutputFormats.Contains("image/jpeg")) { _mimeType = "image/jpeg"; } else if (OutputFormats.Contains("image/png")) { _mimeType = "image/png"; } else if (OutputFormats.Contains("image/gif")) { _mimeType = "image/gif"; } else //None of the default formats supported - Look for the first supported output format { bool formatSupported = false; foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders()) { if (OutputFormats.Contains(encoder.MimeType.ToLower())) { formatSupported = true; _mimeType = encoder.MimeType; break; } } if (!formatSupported) { throw new ArgumentException( "GDI+ doesn't not support any of the mimetypes supported by this WMS service"); } } _layerList = new Collection <string>(); _stylesList = new Collection <string>(); }
/// <summary> /// Sets the image type to use when requesting images from the WMS server /// </summary> /// <remarks> /// <para>See the <see cref="OutputFormats"/> property for a list of available mime types supported by the WMS server</para> /// </remarks> /// <exception cref="ArgumentException">Throws an exception if either the mime type isn't offered by the WMS /// or GDI+ doesn't support this mime type.</exception> /// <param name="mimeType">Mime type of image format</param> public void SetImageFormat(string mimeType) { if (!OutputFormats.Contains(mimeType)) { throw new ArgumentException("WMS service doesn't not offer mimetype '" + mimeType + "'"); } //Check whether SharpMap supports the specified mimetype bool formatSupported = false; foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.MimeType.ToLower() == mimeType.ToLower()) { formatSupported = true; break; } } if (!formatSupported) { throw new ArgumentException("GDI+ doesn't not support mimetype '" + mimeType + "'"); } _MimeType = mimeType; }
/// <summary> /// Sets the image type to use when requesting images from the WMS server /// </summary> /// <remarks> /// <para>See the <see cref="OutputFormats"/> property for a list of available mime types supported by the WMS server</para> /// </remarks> /// <exception cref="ArgumentException">Throws an exception if either the mime type isn't offered by the WMS /// or GDI+ doesn't support this mime type.</exception> /// <param name="mimeType">Mime type of image format</param> public void SetImageFormat(string mimeType) { if (!OutputFormats.Contains(mimeType)) { throw new ArgumentException("WMS service doesn't not offer mimetype '" + mimeType + "'"); } //Check whether SharpMap supports the specified mimetype var formatSupported = false; foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (string.Equals(encoder.MimeType, mimeType, StringComparison.CurrentCultureIgnoreCase)) { formatSupported = true; break; } } if (!formatSupported) { throw new ArgumentException("GDI+ doesn't not support mimetype '" + mimeType + "'"); } _mimeType = mimeType; }
/// <summary> /// Initializes a new layer, and downloads and parses the service description /// </summary> /// <param name="layername">Layername</param> /// <param name="url">Url of WMS server</param> /// <param name="cachetime">Time for caching Service Description (ASP.NET only)</param> /// <param name="proxy">Proxy</param> /// <param name="credentials"></param> public WmsLayer(string layername, string url, TimeSpan cachetime, IWebProxy proxy, ICredentials credentials) { _capabilitiesUrl = url; _proxy = proxy; _timeOut = 10000; LayerName = layername; _continueOnError = true; _credentials = credentials; if (!Web.HttpCacheUtility.TryGetValue("SharpMap_WmsClient_" + url, out _wmsClient)) { if (logger.IsDebugEnabled) { logger.Debug("Creating new client for url " + url); } _wmsClient = new Client(url, _proxy, _credentials); if (!Web.HttpCacheUtility.TryAddValue("SharpMap_WmsClient_" + url, _wmsClient)) { if (logger.IsDebugEnabled) { logger.Debug("Adding client to Cache for url " + url + " failed"); } } } else { if (logger.IsDebugEnabled) { logger.Debug("Created client from Cache for url " + url); } } /* * if (HttpContext.Current != null && HttpContext.Current.Cache["SharpMap_WmsClient_" + url] != null) * { * if (logger.IsDebugEnabled) * logger.Debug("Creating client from Cache for url " + url); * * wmsClient = (Client)HttpContext.Current.Cache["SharpMap_WmsClient_" + url]; * } * else * { * if (logger.IsDebugEnabled) * logger.Debug("Creating new client for url " + url); * wmsClient = new Client(url, _Proxy, _Credentials); * if (HttpContext.Current != null) * HttpContext.Current.Cache.Insert("SharpMap_WmsClient_" + url, wmsClient, null, * Cache.NoAbsoluteExpiration, cachetime); * } */ //Set default mimetype - We prefer compressed formats if (OutputFormats.Contains("image/jpeg")) { _mimeType = "image/jpeg"; } else if (OutputFormats.Contains("image/png")) { _mimeType = "image/png"; } else if (OutputFormats.Contains("image/gif")) { _mimeType = "image/gif"; } else //None of the default formats supported - Look for the first supported output format { bool formatSupported = false; foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders()) { if (OutputFormats.Contains(encoder.MimeType.ToLower())) { formatSupported = true; _mimeType = encoder.MimeType; break; } } if (!formatSupported) { throw new ArgumentException( "GDI+ doesn't not support any of the mimetypes supported by this WMS service"); } } _layerList = new Collection <string>(); _stylesList = new Collection <string>(); }