none
Adding shapes to Bing Maps V8 RRS feed

  • Question

  • Hi,

    we loaded a shape file of government areas into our SQL Server and I want to display the coloured areas
    as a layer inside the Bing web control.

    I read to use the MapCruncher to create tiles per each zoom level. But how to use MapCruncher with
    content from the SQL Server?

    It seems that my way is wrong and I should not use the SQL Server. But how to create tiles?

    And: MapCruncher seems to Need much Manual interaction with many possibilities for Errors. Are there no better

    programs out to create tile maps?

    Thanks

    Calle

    Wednesday, September 7, 2016 2:24 PM

Answers

  • SQL server is a great place to store your data, especially if you want added security and the ability to perform complex spatial queries. I'm not sure how big your data set is (i.e. how many shapes and how many coordinates per shape) but I would guess that if you where to send the raw data to the browser it likely would be fairly large (ten or hundreds of megabytes). If this is the case, then rendering the data server side as a tile layer would make sense. MapCruncher creates tile layers out of images which isn't what you are doing. For vector data you can create a simple web service. We have a white paper and code samples on how to do this here:

    White Paper: https://1drv.ms/b/s!AgFqp4QkIjUNloYCwQmwpbyH8dRs6A

    Code Samples: https://1drv.ms/u/s!AgFqp4QkIjUNk9xph3TWsn4k8M9kzA

    If the shapefile is only a couple megabytes and you only want to perform a few different spatial queries and want to render the data on the map, another solution that would be to host the data in the Bing Spatial Data Services instead of SQL. the white paper shows how to do this. You could then either render the data server side using a web service, or keep things simple and load the data directly into the browser. The Bing Maps V8 map control can easily render several megabytes worth of data. If you use this approach the only server side component you would need is a place to host your webpage as a database and web service wouldn't be needed.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, September 7, 2016 6:17 PM
    • Marked as answer by Calle.M Thursday, September 8, 2016 9:27 AM
    Wednesday, September 7, 2016 6:17 PM
  • Actually, you can interact with data that is rendered as a tile layer... with a little trick. Add a click event to the map. When triggered, take the coordinate where the click event occurred and call a web service that can query your database. Then do an intersection query against your spatial data. This will tell you which shape was clicked. Not sure if the whitepaper included details on how to do this, if not, here are some useful blog posts:

    http://blogs.bing.com/maps/2013/07/31/how-to-create-a-spatial-web-service-that-connects-a-database-to-bing-maps-using-ef5

    http://blogs.bing.com/maps/2013/08/05/advance-spatial-queries-using-entity-framework-5

    I've used this technique many times to interact with big data sets. I've seen some solutions that did this with data sets that had 0.5 billion rows of data. Here is a demo I built that does this: http://onsbingmapsdemo.cloudapp.net/ However, to try something different, rather than using a click event I added a draggable pushpin that when you drag and drop it somewhere it then grabs the metadata for the shape it is on from the database.


    [Blog] [twitter] [LinkedIn]

    Friday, September 9, 2016 1:10 AM
  • If you store the data in the Bing Spatial Data Services instead, it already exposes a spatial REST service that has tall these queries built in. Bing Maps V8 also has a module that makes it easy to access this service.

    [Blog] [twitter] [LinkedIn]

    Friday, September 9, 2016 5:02 PM

All replies

  • SQL server is a great place to store your data, especially if you want added security and the ability to perform complex spatial queries. I'm not sure how big your data set is (i.e. how many shapes and how many coordinates per shape) but I would guess that if you where to send the raw data to the browser it likely would be fairly large (ten or hundreds of megabytes). If this is the case, then rendering the data server side as a tile layer would make sense. MapCruncher creates tile layers out of images which isn't what you are doing. For vector data you can create a simple web service. We have a white paper and code samples on how to do this here:

    White Paper: https://1drv.ms/b/s!AgFqp4QkIjUNloYCwQmwpbyH8dRs6A

    Code Samples: https://1drv.ms/u/s!AgFqp4QkIjUNk9xph3TWsn4k8M9kzA

    If the shapefile is only a couple megabytes and you only want to perform a few different spatial queries and want to render the data on the map, another solution that would be to host the data in the Bing Spatial Data Services instead of SQL. the white paper shows how to do this. You could then either render the data server side using a web service, or keep things simple and load the data directly into the browser. The Bing Maps V8 map control can easily render several megabytes worth of data. If you use this approach the only server side component you would need is a place to host your webpage as a database and web service wouldn't be needed.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Wednesday, September 7, 2016 6:17 PM
    • Marked as answer by Calle.M Thursday, September 8, 2016 9:27 AM
    Wednesday, September 7, 2016 6:17 PM
  • Hi Ricky,

    thanks a lot for your detailed answer and the link to your excellent White Paper.

    As I understood from this doc the best solution for us - because we Need to create layers for projects in many countries with different data - would be to use dynamic tile layers from SQL Server.

    But then I detected the drawback - following your doc - that no interactivity with this approach is possible.
    But we need to click areas and fire an attached event to collect the data (here Locations from our database) inside an area/polygon. Is there no way to retrieve the area id from the position where the mouse click occured on the map?

    Our Goal is: With the area ID I would go back to our SQL Server, find the record for this area which we loaded from the shape file, get the coordinates of the shape/polygon and select all locations inside the area/polygon by gps coordinates stored in our database.

    Is using dynamic tiles from SQL Server the right approach if in the end we Need to work with the shape/polygon coordinates of a clicked polygon?

    Thanks

    Calle

    Thursday, September 8, 2016 12:20 PM
  • Actually, you can interact with data that is rendered as a tile layer... with a little trick. Add a click event to the map. When triggered, take the coordinate where the click event occurred and call a web service that can query your database. Then do an intersection query against your spatial data. This will tell you which shape was clicked. Not sure if the whitepaper included details on how to do this, if not, here are some useful blog posts:

    http://blogs.bing.com/maps/2013/07/31/how-to-create-a-spatial-web-service-that-connects-a-database-to-bing-maps-using-ef5

    http://blogs.bing.com/maps/2013/08/05/advance-spatial-queries-using-entity-framework-5

    I've used this technique many times to interact with big data sets. I've seen some solutions that did this with data sets that had 0.5 billion rows of data. Here is a demo I built that does this: http://onsbingmapsdemo.cloudapp.net/ However, to try something different, rather than using a click event I added a draggable pushpin that when you drag and drop it somewhere it then grabs the metadata for the shape it is on from the database.


    [Blog] [twitter] [LinkedIn]

    Friday, September 9, 2016 1:10 AM
  • Thanks. Seems to be complicated but we will go this way...
    Friday, September 9, 2016 11:29 AM
  • If you store the data in the Bing Spatial Data Services instead, it already exposes a spatial REST service that has tall these queries built in. Bing Maps V8 also has a module that makes it easy to access this service.

    [Blog] [twitter] [LinkedIn]

    Friday, September 9, 2016 5:02 PM