OpenStreetMapProvider through https

5 posts, 0 answers
  1. Andi
    Andi avatar
    14 posts
    Member since:
    Dec 2012

    Posted 27 Dec 2017 Link to this post

    Hi there,

    we are using RadMap with the OpenStreetMapProvider.

    Is it possible to get the maps through a secured connection (https).

    Our client is not allowed to open http to OpenStreetMap.

    I have read that tile serving is possible though ssl.

    Thank you,

    Andi

  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    3058 posts

    Posted 02 Jan Link to this post

    Hi Andi,

    To download map tiles via https connection, you need to override the URI string which are used for accessing the openstreet maps. You can create custom map provider with custom map sources. Please check out the article and the following code which actually overrides the 4 connection strings used by the OpenStreetProvider:

    RadMap Implement Custom Map Provider

      public partial class MainWindow : Window
        {
            public MainWindow()
            {
                this.InitializeComponent();
                this.map.Provider = new HttpsOpenStreetProvider();
            }           
        }
     
        public class HttpsOpenStreetProvider : TiledProvider
        {
            /// <summary>
            /// Initializes a new instance of the MyMapProvider class.
            /// </summary>
            public HttpsOpenStreetProvider()
                  : base()
            {
                OsmTileMapSource source = new HttpsOpenStreetMapnikSource();
                this.MapSources.Add(source.UniqueId, source);
     
                source = new HttpsOpenStreetCycleSource();
                this.MapSources.Add(source.UniqueId, source);
     
                source = new HttpsOpenStreetCycleTransportSource();
                this.MapSources.Add(source.UniqueId, source);
     
                source = new HttpsOpenStreetHumanitarianSource();
                this.MapSources.Add(source.UniqueId, source);
     
                this.SetupCommands();
            }
            /// <summary>
            /// Returns the SpatialReference for the map provider.
            /// </summary>
            public override ISpatialReference SpatialReference
            {
                get
                {
                    return new MercatorProjection();
                }
            }
     
            private void SetupCommands()
            {
                this.CommandBindingCollection.Clear();
     
                string uriString = "/Telerik.Windows.Controls.DataVisualization;component/themes/road.png";
     
                this.RegisterSetSourceCommand(
                    typeof(HttpsOpenStreetMapnikSource),
                    LocalizationManager.GetString("MapOsmStandardCommand"),
                    null,
                    new Uri(uriString, UriKind.RelativeOrAbsolute),
                    null,
                    null);
     
                this.RegisterSetSourceCommand(
                    typeof(HttpsOpenStreetCycleSource),
                    LocalizationManager.GetString("MapOsmCycleCommand"),
                    null,
                    new Uri(uriString, UriKind.RelativeOrAbsolute),
                    null,
                    null);
     
                this.RegisterSetSourceCommand(
                    typeof(HttpsOpenStreetCycleTransportSource),
                    LocalizationManager.GetString("MapOsmTransportCommand"),
                    null,
                    new Uri(uriString, UriKind.RelativeOrAbsolute),
                    null,
                    null);
     
                this.RegisterSetSourceCommand(
                    typeof(HttpsOpenStreetHumanitarianSource),
                    LocalizationManager.GetString("MapOsmHumanitarianCommand"),
                    null,
                    new Uri(uriString, UriKind.RelativeOrAbsolute),
                    null,
                    null);
            }
        }
        public class HttpsOpenStreetMapnikSource : OsmTileMapSource
        {
            public HttpsOpenStreetMapnikSource() : base(@"https://{prefix}.tile.openstreetmap.org/{zoom}/{x}/{y}.png")
            {
            }
        }
     
        public class HttpsOpenStreetCycleSource : OsmTileMapSource
        {
            public HttpsOpenStreetCycleSource() : base(@"http://{prefix}.tile.opencyclemap.org/cycle/{zoom}/{x}/{y}.png")
            {
            }
        }
     
        public class HttpsOpenStreetCycleTransportSource : OsmTileMapSource
        {
            public HttpsOpenStreetCycleTransportSource() : base(@"https://{prefix}.tile2.opencyclemap.org/transport/{zoom}/{x}/{y}.png")
            {
            }
        }
     
        public class HttpsOpenStreetHumanitarianSource : OsmTileMapSource
        {
            public HttpsOpenStreetHumanitarianSource() : base(@"https://{prefix}.tile.openstreetmap.fr/hot/{zoom}/{x}/{y}.png")
            {
            }
        }
    }


    Regards,
    Petar Mladenov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Andi
    Andi avatar
    14 posts
    Member since:
    Dec 2012

    Posted 12 Jan in reply to Petar Mladenov Link to this post

    Hi Petar,

    I tried your implementation. Unfortunately it does not work!

    All map tiles are still coming through HTTP.

    See attached my Fiddler log

    Any ideas?

    TIA, Andi

  4. Petar Mladenov
    Admin
    Petar Mladenov avatar
    3058 posts

    Posted 17 Jan Link to this post

    Hello Andi,

    It appears the HTTPS prefix from the URI string is replaced in later stage (when building the URI for download). We changed the solution to replace "http" wiith "https" at the final stage before downloading a specific tile:

    public class HttpsOpenStreetCycleSource : OpenStreetCycleSource
       {
           protected override Uri GetTile(int tileLevel, int tilePositionX, int tilePositionY)
           {
               Uri baseURI = base.GetTile(tileLevel, tilePositionX, tilePositionY);
               string uriString = baseURI.AbsoluteUri.Replace("http", "https");
               return new Uri(uriString);
           }
       }

    Please give it a try and let us know how it goes on your side.

    Regards,
    Petar Mladenov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Andi
    Andi avatar
    14 posts
    Member since:
    Dec 2012

    Posted 18 Jan in reply to Petar Mladenov Link to this post

    Thank you Petar this solution worked for us! 

    I also had to change our web app - where we also used RadMap:

    string urlTemplate;
    urlTemplate = "https://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png";
     
    var mapLayer = new MapLayer { Type = LayerType.Tile, UrlTemplate = urlTemplate };
    WebControl.LayersCollection.Add(mapLayer);
     
    var bubbleLayer = new MapLayer { Type = LayerType.Bubble, LocationField = "Location", ValueField = "Value" };
    radMap.LayersCollection.Add(bubbleLayer);
Back to Top