none
Import Locations from file RRS feed

  • Question

  • Trying to fix a V7 to V8 problem, working with Heatmaps module.

    I have a JS file listing locations - this updates daily.

    This is a snippet of the file:

    data.js
    var Data = [
    new Microsoft.Maps.Location(39.900313,-84.222376),
    new Microsoft.Maps.Location(39.903133,-77.517685),
    new Microsoft.Maps.Location(40.433843,-84.967734),
    new Microsoft.Maps.Location(40.436251,-79.985544),
    new Microsoft.Maps.Location(40.439349,-79.769798),
    new Microsoft.Maps.Location(40.440449,-79.890538),
    new Microsoft.Maps.Location(40.440749,-84.968924),
    new Microsoft.Maps.Location(38.205918,-77.655679),
    new Microsoft.Maps.Location(40.783483,-79.796921),

    How can I import/read this file to generate a list of locations that would be equivalent to the data structure resulting from this command which works:

    var locs = Microsoft.Maps.TestDataGenerator.getLocations(170000, map.getBounds());       Microsoft.Maps.loadModule('Microsoft.Maps.HeatMap', function () {
                var heatmap = new Microsoft.Maps.HeatMapLayer(locs);
                map.layers.insert(heatmap);

    In the past with V7, I  was working with a Module that broke with V8 - with this old module I could do this:

    Microsoft.Maps.registerModule("HeatMapModule", "..url../data.js");
          Microsoft.Maps.loadModule("HeatMapModule", { callback: function() {
            // Create a basic heatmap from an array of locations
            heatmapLayer = new HeatMapLayer(map, Data, { intensity:0.1, radius:500});
          }});

    Bottom line, I want to read locs from file instead of generate them randomly.

    Monday, November 6, 2017 3:55 PM

Answers

All replies

  • Simply pass your Data variable into the HeatMapLayer when creating it instead of using locs.

    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Monday, November 6, 2017 5:26 PM
    • Marked as answer by tonto321 Thursday, November 9, 2017 2:02 PM
    Monday, November 6, 2017 5:26 PM
  • It's not working....if I do an alert on locs, I see an array of lat/lon locations,

           var locs = Microsoft.Maps.TestDataGenerator.getLocations(1000, map.getBounds());
           alert(locs);
            Microsoft.Maps.loadModule('Microsoft.Maps.HeatMap', function () {
                var heatmap = new Microsoft.Maps.HeatMapLayer(locs);
                map.layers.insert(heatmap);
            });

    but if import my locations from url, in the header of the document, after calling the map control, like this:

    <script type="text/javascript" src="..url../data.js"></script>

    then the Data array shows as "undefined" in the alert statement, and the Heatmap does not render.

    Monday, November 6, 2017 10:19 PM
  • Ok this worked! I just didn't have the javascript correct.

    After linking to stored array : <script type="text/javascript" src="..url../data.js"></script>

    I had to do

    var Arr = Data;

    and then pass Arr to Heatmap.

           Microsoft.Maps.loadModule('Microsoft.Maps.HeatMap', function () {
                var heatmap = new Microsoft.Maps.HeatMapLayer(Arr);
                map.layers.insert(heatmap);
            });

    Thursday, November 9, 2017 2:02 PM