Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Map > OpenStreetMap Provider forcing http

Not answered OpenStreetMap Provider forcing http

Feed from this thread
  • Stunty avatar

    Posted on Apr 18, 2011 (permalink)

    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 ?

    Reply

  • Andrey Andrey admin's avatar

    Posted on Apr 20, 2011 (permalink)

    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

    Reply

  • Andrew avatar

    Posted on Jun 28, 2011 (permalink)

    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?

    Reply

  • Andrey Andrey admin's avatar

    Posted on Jul 1, 2011 (permalink)

    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

    Reply

  • Posted on Dec 20, 2011 (permalink)

    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?

    Reply

  • Andrey Andrey admin's avatar

    Posted on Dec 23, 2011 (permalink)

    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 >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > Map > OpenStreetMap Provider forcing http