none
Can you building Your Own Tile Server locally and debug it ? RRS feed

  • Question

  • I would like to develop my own custom tile server locally using plain old asp.net. I've had a read of the "Building your own Tile Server" ( http://msdn.microsoft.com/en-us/library/bb545006.aspx ) and all references to the uriConstructor in the Microsoft.Maps.TileSource class are fully qualified live servers. I know it's possible as the CodePlex OnTerra DataConnector sample uses a local MVC URL to return the map tiles. I'm not however using the MVC pattern. I don't seem to be able to get the ajax map control v7 to call my WCF service what ever URI I try. My Solution has a web site and a service reference to a local WCF Service (also in the solution). What am I doing wrong?

     // Create the tile layer source
    var tileSource = new Microsoft.Maps.TileSource({ uriConstructor: 'http://localhost:1825/LicensingService.svc?GetTileLayer&quadkey={quadkey}' });
            
    
    Cheers
    
    Anthony
    


    Anthony Kay
    • Moved by Ricky_Brundritt Friday, March 9, 2012 5:39 PM (From:Bing Maps: Map Control and Web services Development)
    Sunday, May 15, 2011 12:28 AM

Answers

  • I have since worked out how to do this. There is a lack of suitable documentation. Also, the TileSource and TileLayer doesn't give suitable feedback when if can't retrieve data from a URI. Despite passing a gobeldy-gook URI to the TileSource it fails to raise exceptions of any kind. If anyone would like to create a tile server from a local WCF service, read the following:

    Onterra AJAX Map DataConnector (Code to create a tile server): http://ajaxmapdataconnector.codeplex.com/

    Building an AJAX enabled WCF Service (Host the tile server): http://msdn.microsoft.com/en-us/library/bb924552.aspx

    Help with debugging your WCF Service: http://blogs.msdn.com/b/paraswadehra/archive/2011/01/07/turn-on-includeexceptiondetailinfaults-while-connecting-to-a-wcf-service-from-a-client.aspx

     

    Once the service is built, it's very much business as normal:

     

     

    try {
      // Create the tile layer source
      var tileSource = new Microsoft.Maps.TileSource({ uriConstructor: 'http://localhost:5070/LicensingServices/LocationService.svc/GetTileLayer?quadkey={quadkey}' });
    
      // Construct the layer using the tile source
      var tilelayer = new Microsoft.Maps.TileLayer({ mercator: tileSource, opacity: 0.7 });
    
      // Push the tile layer to the map
      map.entities.push(tilelayer);
    
      }
      catch (err) {
      alert('Error Message:' + err.message);
      }
    

     

    On Alastair Aitchison's own blog there is a lovely article doing something similar using an ashx to host the file as an alternative. http://alastaira.wordpress.com/2011/01/07/accessing-a-wms-tile-server-from-bing-maps-v7/

     

    I have yet to fine tune my code. There does seem to be some delay in drawing... thats the next challenge. :) Onwards!
    

     


    Anthony Kay

    • Marked as answer by Anthony_Kay Friday, May 20, 2011 12:12 AM
    Friday, May 20, 2011 12:09 AM

All replies

  • It's fine to create a tile layer from a local or relatively-referenced URL. However, in the code snippet you posted you're only defining the tile source - to actually create a tile layer and add it to the map you need the following lines as well:

    var myTilelayer = new Microsoft.Maps.TileLayer({ mercator: tileSource, opacity: 0.9 });
    map.entities.push(myTilelayer);


    twitter: @alastaira blog: http://alastaira.wordpress.com/
    • Marked as answer by Ricky_Brundritt Wednesday, May 18, 2011 6:45 PM
    • Unmarked as answer by Anthony_Kay Friday, May 20, 2011 12:12 AM
    Sunday, May 15, 2011 4:50 PM
    Moderator
  • :) I ommited those lines for clarity but I do have them in already thanks.

    I was debugging this by attaching my process to the WCF Service and then running the website with the code above. I was expecting the breakpoint to attach either when the TileLayer was created or when it was added to the map.entities collection. Neither of these seemed to drop into the WCF service, hence I thought it was a problem with resolving the URI? The code steps over both lines without failing and also definately doesn't get into the WCF service. Is there a way to debug what is happening inbetween?

    Thanks for the help


    Anthony Kay
    Sunday, May 15, 2011 8:52 PM
  • I have since worked out how to do this. There is a lack of suitable documentation. Also, the TileSource and TileLayer doesn't give suitable feedback when if can't retrieve data from a URI. Despite passing a gobeldy-gook URI to the TileSource it fails to raise exceptions of any kind. If anyone would like to create a tile server from a local WCF service, read the following:

    Onterra AJAX Map DataConnector (Code to create a tile server): http://ajaxmapdataconnector.codeplex.com/

    Building an AJAX enabled WCF Service (Host the tile server): http://msdn.microsoft.com/en-us/library/bb924552.aspx

    Help with debugging your WCF Service: http://blogs.msdn.com/b/paraswadehra/archive/2011/01/07/turn-on-includeexceptiondetailinfaults-while-connecting-to-a-wcf-service-from-a-client.aspx

     

    Once the service is built, it's very much business as normal:

     

     

    try {
      // Create the tile layer source
      var tileSource = new Microsoft.Maps.TileSource({ uriConstructor: 'http://localhost:5070/LicensingServices/LocationService.svc/GetTileLayer?quadkey={quadkey}' });
    
      // Construct the layer using the tile source
      var tilelayer = new Microsoft.Maps.TileLayer({ mercator: tileSource, opacity: 0.7 });
    
      // Push the tile layer to the map
      map.entities.push(tilelayer);
    
      }
      catch (err) {
      alert('Error Message:' + err.message);
      }
    

     

    On Alastair Aitchison's own blog there is a lovely article doing something similar using an ashx to host the file as an alternative. http://alastaira.wordpress.com/2011/01/07/accessing-a-wms-tile-server-from-bing-maps-v7/

     

    I have yet to fine tune my code. There does seem to be some delay in drawing... thats the next challenge. :) Onwards!
    

     


    Anthony Kay

    • Marked as answer by Anthony_Kay Friday, May 20, 2011 12:12 AM
    Friday, May 20, 2011 12:09 AM
  • Glad you liked my article ;)

    I couldn't quite work out what was different between the way you were specifying the tilesource URL in your working code example from that in your broken code example (other than, obviously, you've changed the name of your own service). Or was it a problem in the service itself, but just that it was hard to debug from within Bing Maps?


    twitter: @alastaira blog: http://alastaira.wordpress.com/
    Friday, May 20, 2011 6:23 AM
    Moderator
  • Didn't realise I was replying to you! The Pseudonim threw me.

    Well, after you said that the URI could be local, I thought it had to be a problem communicating with my WCF service. Given that I'm not quite as hot with WCF as I should be it seemed a logical place to start. Low-and-behold if you are trying to call a WCF service from AJAX there are special configurations... I read the above, broke it into pieces getting the WCF Service to work first. Once I had confirmed the Tiles were being returned it was just a case of putting the URI in...

    The service code is simple in the articles but it's from the perspective of using an existing tile server on the internet. Only your article and OnTerra seem to be doing anything like explaining how to connect to your own. The msdn docs don't go into any detail about this. Also the service doesn't give any feedback if it can't resolve the URI or if there is any sort of response error. That would have helped enormously to know that it could resolve and connect to my WCF service, even though it wasn't returning anything, or even that it could see the WCF service however ran into problems after encountering an exception. At the moment exceptions seem to be ignored and there is no feedback. 

     

    Is there any benefit of using ashx over a WCF service?

     


    Anthony Kay

    Friday, May 20, 2011 11:12 PM