传单和热图:我无法从json文件中读取数据

时间:2018-02-22 22:10:18

标签: jquery json leaflet heatmap

我正在学习使用leaflet和heatmap.js生成热图的教程。该教程运行良好,但当我尝试从文件中读取数据时,它停止工作。目前,我正在尝试使用小型数据集,但数据集将来会增加。拜托,有人可以帮我修理它。

var testData = {
  max: 8,
  data : $.getJSON("js/ozone2.json", function(data){})
};

console.log(testData);

var baseLayer = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}',{
attribution: "thank you",
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoiZXJpa2FoZCIsImEiOiJjamRnMjY0cnUwY2hrMnBwaGdzZDl4OGpuIn0.t3JrTRNTPesh-gTCjAg4_w',
});

var configuration = {
"radius": 20,
"maxOpacity": 0.5,
"scaleRadius": false,
"useLocalExtrema": true,
latField: 'lat',
lngField: 'lng',
valueField: 'value'
};

var heatmapLayer = new HeatmapOverlay(configuration);

var map =  new L.map('map', { 
center: new L.latLng(53.1424, -7.6921),
zoom: 8,
minZoom: 3,
maxZoom: 14,
ZoomControl: false,
layers: [baseLayer, heatmapLayer]
});

heatmapLayer.setData(testData);
heatmapLayer.addTo(map);
layer=heatmapLayer;

json文件中的数据:

[
 {"lat":"58.75", "lng":"18.5", "value": "50"},
 {"lat":"59.0", "lng":"18.5", "value": "50"}
]

0 个答案:

没有答案