Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need a way of reading that JSON and parsing it into the variable(s) you need. Since you're using jQuery, here's a method that would work with the JSON structure you have.</p> <pre><code>$.getJSON("layers.json").then(function(data) { $.each(data, function(i,datapoints) { $.each(datapoints, function(j,datapoint) { layers.push({ location: new google.maps.LatLng(datapoint.lat, datapoint.lng), weight: datapoint.weight, layerID: datapoint.layer }); }); }); }); </code></pre> <p>Adapt as necessary.</p> <p>In response to davids12's update, here's a function that returns an array of arrays where each composite array has the datapoints from a certain layer. So, running over your example, <code>layers</code> would have 2 arrays in it (<code>layers[1]</code> and <code>layers[2]</code>) which are basically <code>layer1</code> and <code>layer2</code> that you describe in your code (with an additional <code>layerID</code> variable; you could remove it if you wish). This allows you to load much more layers and points just by putting them in the JSON using the format you have now.</p> <pre><code> function loadData() { var layers = [ ]; $.ajax({ url: 'j.json', async: false, dataType: 'json', success: function (data) { for (var i=0; i&lt;data.datapoints.length; i++) { var datapoint = data.datapoints[i]; if (layers[datapoint.layer]===undefined) { layers[datapoint.layer] = []; } layers[datapoint.layer].push({ location: new google.maps.LatLng(datapoint.lat, datapoint.lng), weight: datapoint.weight, layerID: datapoint.layer }); } } }); return layers; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload