I'm working on a function in leaflet that changes the style weight
of the most recent object in a JSON response.(我正在使用传单中的函数来更改JSON响应中最新对象的样式weight
。)
That's beside the point though, because I can't properly get the JSON objects into an array.(不过,这很重要,因为我无法正确地将JSON对象放入数组中。)
When I run console.log(dates)
in order to see if they were pushed to the dates
array I return this in the console.(当我运行console.log(dates)
以便查看它们是否被推送到dates
数组时,我在控制台中将其返回。)
A bunch of empty arrays, amounting to the number of dates in the JSON response.(一堆空数组,总计为JSON响应中的日期数。)
When I run console.log(time)
to ensure I am in fact reaching the correct json feature I receive the dates (epoch format) as expected, but can not understand why they will not be pushed into the array dates
.(当我运行console.log(time)
以确保我实际上达到了正确的json功能时,我收到了预期的日期(纪元格式),但无法理解为什么它们不会被推入数组dates
。)
Any ideas?(有任何想法吗?)
Function(功能)
//most recent earthquake identifer
function mostRecent(time) {
var dates=[];
for (var i = 0; i < time.length; i++) {
dates.push(time[i])
}
console.log(dates)
return true
}
Javascript(Java脚本)
// adds geojson feed of earthquakes from USGS url (must create a function to layer it on leaflet)
$.getJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson', function(earthQuakes) {
var points = L.geoJSON(earthQuakes, {
filter: eqFilter,
onEachFeature: function (feature, layer) { // binds data in geosjon to a popup
var eqDate = new Date(feature.properties.time); // converts epoch date
layer.bindPopup(
'<b>Location: </b>' + feature.properties.place + '<br>' +
'<b>Magnitude: </b>' + feature.properties.mag + '<br>' +
'<b>Depth: </b>' + feature.geometry.coordinates[2] + 'km' + '<br>' +
'<b>Time: </b>' + eqDate.toGMTString() + '<br>' +
'<br><center><a href=' + feature.properties.url + '>USGS Details</a></center>',
)
},
pointToLayer: function(feature, latlng){ // changes default icons to circles and styles accordingly
return new L.CircleMarker(latlng, {
radius: circleSize(feature.properties.mag),
fillColor: getColor(feature.properties.mag),
color: "#000",
weight: mostRecent(feature.properties.time),
opacity: 1,
fillOpacity: 0.5,
});
}
}).addTo(map);
map.fitBounds(points.getBounds()); // pans to points
});
ask by prime90 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…