Wednesday, May 2, 2012

Heat map using Bing and Windows Azure Web Role

Today I will explain how Azure web role can be used with Bing Maps to draw Heat map based on the input file. The input file data is as follows –
I have state name of USA, latitude and longitude, number of units sold of a product (typical sales data) in the particular state sorted in ascending order.

35.41,-105.56,1400,New Mexico          
44.22,-100.21,1500,South Dakota        

I have downloaded heatmap.js javascript file to plot heat map on Bing map using HTML 5 canvas element. The complete code of heatmap.js is here. We need to add this file in Scripts folder of web role.
Now let’s create a web role. I will have my input file added in the web role. In the page load I will read input text file and plot heat map.
Add a page in the project named as BingHeatMap.aspx and copy paste the code mentioned here on aspx and code behind side. Don’t forget to replace string YourBing Map Key with key of your windows live account.
In my code behind, I actually read the input file in variable which declared as public and then I use this variable of c# code behind in Javascript code of plotting heat map point.
So my solution structure is as follows –

Now download and install Mozilla latest version. The HTML 5 canvas element is supported in IE9 (and above) and latest version of Mozilla. I don’t have IE9 therefore here I am using Mozilla.

Run the project. Final heat map plotted as shown below –

From the diagram it is apparent that, California, Florida and Vermont region has less number of sales so these regions are in red and somewhat yellow in Heat Map. Whereas Washington and Colorado has maximum number of sales so these regions are in Green on Heat Map. If you drilldown (zoom in on the map), the color difference becomes more vivid as shown below –


Happy Heating!!!

No comments:

Post a Comment