OpenStreetMap Provider forcing http

11 posts, 0 answers
  1. Stunty
    Stunty avatar
    1 posts
    Member since:
    Apr 2011

    Posted 18 Apr 2011 Link to this post

    I am using RadMap in a https site with OpenStreetMap as a provider. Unfortunately the OpenStreetMap servers do not provide https data and refuse the connection (i.e. no map data shown). I do not know how to allow/configure/force the RadMap control to request and accept the data from their http servers as http traffic, while still serving the majority of my site/controls over https - is this possible and if so how ?
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 20 Apr 2011 Link to this post

    Hi Stunty,

    By default Silverlight security system blocks cross-scheme requests. Actually, it is possible to use OpenStreet map tiles through the HTTPS, but using custom provider. There are a couple ways to do it:

    1. You can host your own OpenStreet tile server which will return tiles using HTTPS protocol. In this case you will need to have whole bundle of the OS map images locally and then configure your web server to return this tiles using HTTPS. Then you should create custom map source and map provider which will use this tile server. With this approach you will not need to deal with the Silverlight security.

    2. If you don't like to create your own tile server, then you have to take a deal with Silverlight security. The default OpenStreet map provider always uses the same protocol as major application use. So the first thing you have to do is to create the custom map tile source and tile provider which will always use HTTP protocol regardless of the protocol used. The second thing you have to do is to configure the Silverlight security to allow using the HTTP from the application which is run using HTTPS. You can find more information here:

    http://msdn.microsoft.com/en-us/library/cc645032(v=vs.95).aspx

    Kind regards,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Andrew
    Andrew avatar
    20 posts
    Member since:
    Mar 2010

    Posted 28 Jun 2011 Link to this post

    Using example from
    http://www.telerik.com/community/forums/silverlight/map/2011-q1-custom-map-provider-example.aspx
    as a starting point I tried to apply second solution.

    My clientaccesspolicy.xml file:
    <?xml version="1.0" encoding="utf-8"?>
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="*">      
        <domain uri="http://*"/>
        <domain uri="https://*"/>
          </allow-from>      
          <grant-to>      
            <resource path="/" include-subpaths="true"/>
          </grant-to>      
        </policy>
      </cross-domain-access>
    </access-policy>

    It doesn’t work. Can you post working example with the second solution or maybe you know what I am doing wrong?
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 01 Jul 2011 Link to this post

    Hello Andrew,

    I'm sorry for misleading you. After a detailed research into the problem of the using of the cross-schema (HTTPS-HTTP) call in Silverlight I found that cross-schema access is not allowed for image classes (MultiScaleImage is one of them). Since RadMap is based on the MultiScaleImage you can't show OpenStreet map tiles directly from the HTTPS Silverlight application. So the only way to show OpenStreet map tiles from the HTTPS-based Silverlight application is creation of your own tile server. This server can store OpenStreet tiles locally or be a proxy to the OpenStreet real server.

    All the best,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Tree
    Tree avatar
    111 posts
    Member since:
    Nov 2005

    Posted 20 Dec 2011 Link to this post

    Andrey,

    Can you provide some help on getting started in developing a proxy tile server and custom provider that would be required to use RadMap using HTTPS with OpenStreetMap data?
  7. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 23 Dec 2011 Link to this post

    Hi,

    It is quite simple to create tile server on localhost or another web server when you have images which can be identified by the zoom level and (x,y) position of the tile. All that you need to do is put your tiles in a separate directory in the C:\inetpub\wwwroot folder. So if you have the OpenStreet map tiles organized in a way similar to the structure on the OpenStreet servers (zoom\x_pos\y_pos.png) then you can create tile server on localhost in a couple of steps:

    1. Create new folder like "os_images" in the "C:\inetpub\wwwroot" folder.
    2. Copy whole structure of the OpenStreet images to this new folder.

    Now you can create new map tile source and map provider which will access images from this folder:

    /// <summary>
    /// Tile source which read map tiles from the given URI.
    /// </summary>
    public class LocalhostTileSource : TiledMapSource
    {
        private string tileUriFormat;
       
        /// <summary>
        /// Initializes a new instance of the LocalhostTileSource class.
        /// </summary>
        /// <param name="tileUriFormat">Format string to access tiles on the localhost.</param>
        public LocalhostTileSource(string tileUriFormat)
            : base(1, 20, 256, 256)
        {
            this.tileUriFormat = tileUriFormat;
        }
       
        /// <summary>
        /// Initialize provider.
        /// </summary>
        public override void Initialize()
        {
            // Raise provider intialized event.
            this.RaiseIntializeCompleted();
        }
       
        /// <summary>
        /// Gets the image URI.
        /// </summary>
        /// <param name="tileLevel">Tile level.</param>
        /// <param name="tilePositionX">Tile X.</param>
        /// <param name="tilePositionY">Tile Y.</param>
        /// <returns>URI of image.</returns>
        protected override Uri GetTile(int tileLevel, int tilePositionX, int tilePositionY)
        {
            int zoomLevel = ConvertTileToZoomLevel(tileLevel);
       
            string url = this.tileUriFormat.Replace("{zoom}", zoomLevel.ToString(CultureInfo.InvariantCulture));
            url = url.Replace("{x}", tilePositionX.ToString(CultureInfo.InvariantCulture));
            url = url.Replace("{y}", tilePositionY.ToString(CultureInfo.InvariantCulture));
            return new Uri(url);
        }
    }
     
    /// <summary>
    /// Map provider which read map tiles from the file system.
    /// </summary>
    public class LocalhostProvider : TiledProvider
    {
        /// <summary>
        /// Initializes a new instance of the LocalhostProvider class.
        /// </summary>
        /// <param name="tileUriFormat">Format string to access tiles on the localhost.</param>
        public LocalhostProvider(string tileUriFormat)
            : base()
        {
            LocalhostTileSource source = new LocalhostTileSource(tileUriFormat);
            this.MapSources.Add(source.UniqueId, source);
        }
       
        /// <summary>
        /// Returns the SpatialReference for the map provider.
        /// </summary>
        public override ISpatialReference SpatialReference
        {
            get
            {
                return new MercatorProjection();
            }
        }
    }

    Now you can use new map provider in your application:

    <UserControl x:Class="LocalhostMapProvider.MainPage"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 mc:Ignorable="d"
                 d:DesignHeight="300" d:DesignWidth="400">
       
        <Grid x:Name="LayoutRoot" Background="White">
            <telerik:RadMap x:Name="radMap"
                            Center="48.95,2.3"
                            ZoomLevel="13">
            </telerik:RadMap>
        </Grid>
    </UserControl>


    using System;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
       
    namespace LocalhostMapProvider
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
       
                this.radMap.Provider = new LocalhostProvider("http://localhost/os_images/{zoom}/{x}/{y}.png");
            }
        }
    }

    The ConvertTileToZoomLevel method is inherited from TiledMapSource class so you need not bother about its implementation.

    The proxy tile server can be created in the same way. In this case you should create in addition simple page on your web site which will get image requests from your application, transfer it to the OpenStreet server and then return response. The code for the custom tile provider will be the same.

    All the best,

    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Gabe
    Gabe avatar
    7 posts
    Member since:
    Oct 2010

    Posted 14 Nov 2012 Link to this post

    Hi - This is a very helpful post and I think it has gotten me most of the way there.  Our application uses https and Bing looks too expensive, so we probably would not be able to use that.  However when looking at this example - I could not find where to download all the map tiles from OpenStreet and there were some direct warnings saying you could not download all the tiles from them.  Also saw some other info that this was a huge amount of data.  Any insight on this?

    Second I saw that MapQuest open provider uses Openstreet and does not have data limits and does support HTTPS.  All good, except when the query is run from within the app I never am able to get the map to load in HTTPS, only from HTTP.

    The only change I have made to your code is this one line:
    change this (from localhost):
    this.radMap.Provider = new LocalhostProvider("http://localhost/os_images/{zoom}/{x}/{y}.png");

    to this (mapquest host):

     

     

     

    this.radMap.Provider = new LocalhostProvider("https://otile1.mqcdn.com/tiles/1.0.0/osm/{zoom}/{x}/{y}.png");

    The only way it will load the map is if both my app and the url above are both HTTP, but if you just navigate to the url directly with valid substitutions, HTTPS works fine and you see the requested tile.

    Ideally I would like to be able to get both of these solutions working as many of our customers are not running the app with internet access so an offline solution is appealing for that case, but otherwise HTTPS is minimally required.

    Thanks!

     

  9. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 19 Nov 2012 Link to this post

    Hello Gabe,

    The cross-schema (HTTPS-HTTP or HTTP-HTTPS) call in Silverlight is not allowed for image classes (MultiScaleImage is one of them). You can find more information here:

    http://msdn.microsoft.com/en-us/library/cc189008(v=vs.95).aspx

    So when you use HTTPS to access MapQuest open provider you should be sure that your Silverlight application is running using HTTPS as well.

    Greetings,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Gabe
    Gabe avatar
    7 posts
    Member since:
    Oct 2010

    Posted 05 Dec 2012 Link to this post

    Sorry I was mistaken.  Mapquest does not support SSL on their open tile server, only through a java or flash api.  I have not been able to find any direct tile provider that does.  Bing is the only direct tile provider that does support SSL that I could find, but is way too expensive.

    I was able to create an offline tile server running on my website, but only to zoom level 7, as the space requirements for the images get too large beyond this (over 500 TB for the full map).

    At present, I am without a solution to retrieve the fully detailed map over SSL.  Trying to setup and host our own tile server looks like a huge can of worms, so that would be a last resort. 

    Any suggestions on alternative options?
  11. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 07 Dec 2012 Link to this post

    Hello Gabe,

    You can try to create your own tile server which will be a HTTPS proxy for the OpenStreet real server. I.e. your tile server will handle request sent via HTTPS from your Silverlight application and request tile from OpenStreet using HTTP. When tile is obtained your server will return it to the Silverlight application.

    Regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  12. Chad
    Chad avatar
    2 posts
    Member since:
    Sep 2008

    Posted 15 Dec 2013 Link to this post

    I recently made a proxy server so I could get open street maps working with https Silverlight maps.

    Here is how to do it:

    make a webForms page, do not put anything in the markup.  Just add this to the code behind.

    then you can call the service with: https://server/mapImageProxy.aspx?zoom=12&x=4000&y=4000

    use the documentation on how to build a custom map provider, and use your new proxy server URL instead of the open street maps one.

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Security.Permissions;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    namespace WCFServiceWebRole1.MapTileDownloader
    {
        public partial class MapTileDownload : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                string x = Context.Request.QueryString["x"];
                string y = Context.Request.QueryString["y"];
                string zoom = Context.Request.QueryString["zoom"];
     
                string url = @"http://Map Tile Server Of Your Choice/" + zoom + "/" + x + "/" + y + ".png";
     
                WebRequest theRequest = WebRequest.Create(url);
                WebResponse theResponse = theRequest.GetResponse();
                Stream theStream = theResponse.GetResponseStream();
                System.Drawing.Image theImage = System.Drawing.Image.FromStream(theStream);
     
                MemoryStream stream = new MemoryStream();
     
                Response.ContentType = "image/jpeg";
                theImage.Save(stream, ImageFormat.Png);
     
                stream.Position = 0;
     
                byte[] imageArray = stream.ToArray();
     
                Response.OutputStream.Write(imageArray, 0, imageArray.Length);
            }
        }
    }

Back to Top
DevCraft banner