From 9956e78028216733a00e1e3abceba1b4bd18efa2 Mon Sep 17 00:00:00 2001 From: ClemensF Date: Thu, 16 Jul 2020 16:32:22 +0200 Subject: [PATCH] Update WmsImageLayer.cs --- MapControl/Shared/WmsImageLayer.cs | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/MapControl/Shared/WmsImageLayer.cs b/MapControl/Shared/WmsImageLayer.cs index e2529213..4e953981 100644 --- a/MapControl/Shared/WmsImageLayer.cs +++ b/MapControl/Shared/WmsImageLayer.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Threading.Tasks; using System.Xml.Linq; @@ -120,6 +121,30 @@ namespace MapControl return element; } + /// + /// Gets a response string from the URL returned by GetFeatureInfoRequestUri(). + /// + public async Task GetFeatureInfoTextAsync(Point position, string format = "text/plain") + { + string response = null; + + if (ServiceUri != null) + { + var uri = GetFeatureInfoRequestUri(position, format); + + try + { + response = await ImageLoader.HttpClient.GetStringAsync(uri); + } + catch (Exception ex) + { + Debug.WriteLine("WmsImageLayer: {0}: {1}", uri, ex.Message); + } + } + + return response; + } + /// /// Loads an XElement from the URL returned by GetFeatureInfoRequestUri(). /// @@ -129,7 +154,7 @@ namespace MapControl if (ServiceUri != null) { - var uri = GetFeatureInfoRequestUri(position); + var uri = GetFeatureInfoRequestUri(position, "text/xml"); try { @@ -223,7 +248,7 @@ namespace MapControl /// /// Returns a GetFeatureInfo request URL string. /// - protected virtual string GetFeatureInfoRequestUri(Point position) + protected virtual string GetFeatureInfoRequestUri(Point position, string format) { string uri = null; var projection = ParentMap?.MapProjection; @@ -263,7 +288,7 @@ namespace MapControl uri += "&HEIGHT=" + (int)Math.Round(viewRect.Height); uri += "&I=" + (int)Math.Round(imagePos.X); uri += "&J=" + (int)Math.Round(imagePos.Y); - uri += "&INFO_FORMAT=text/xml"; + uri += "&INFO_FORMAT=" + format; } return uri.Replace(" ", "%20");