Здесь возникают некоторые проблемы.У меня есть переменная geoJSON из 30 аэропортов, и я пытаюсь сравнить ее с данными FAA, но я не уверен, как изменить значки Leaflet, если два массива содержат совпадающее имя аэропорта.
{"status":{"code":200,"info":"OK","count":3},"GroundDelays":{"groundDelay":[{"airport":"CYYZ","avgTime":"4 hours and 29 minutes","reason":"WX / WIND"},{"airport":"EWR","avgTime":"1 hour and 57 minutes","reason":"VOLUME / VOLUME"},{"airport":"MSP","avgTime":"4 hours and 21 minutes","reason":"WEATHER / SNOW-ICE"}],"count":3},"GroundStops":{"groundStop":[],"count":0},"ArriveDepartDelays":{"arriveDepart":[],"count":0},"Closures":{"closure":[],"count":0}}
выше - из API отдыха FAA.
var airports=[{"type":"Feature","properties":{"icao":"KSEA","iata":"SEA","name":"Seattle Tacoma International Airport"},"geometry":{"type":"Point","coordinates":[-122.3089981079,47.4490013123]}},{"type":"Feature","properties":{"icao":"KPDX","iata":"PDX","name":"Seattle Tacoma International Airport"},"geometry":{"type":"Point","coordinates":[-122.5979996,45.58869934]}},{"type":"Feature","properties":{"icao":"KSFO","iata":"SFO","name":"San Francisco International Aiport"},"geometry":{"type":"Point","coordinates":[-122.375,37.6189994812]}},{"type":"Feature","properties":{"icao":"KSJC","iata":"SJC","name":"Norman Y. Mineta San Jose International Airport"},"geometry":{"type":"Point","coordinates":[-121.9290008545,37.3625984192]}},{"type":"Feature","properties":{"icao":"KLAX","iata":"LAX","name":"Los Angeles International Airport"},"geometry":{"type":"Point","coordinates":[-118.4079971,33.94250107]}},{"type":"Feature","properties":{"icao":"KSAN","iata":"SAN","name":"San Diego International Airport"},"geometry":{"type":"Point","coordinates":[-117.1900024414,32.7336006165]}},{"type":"Feature","properties":{"icao":"KLAS","iata":"LAS","name":"McCarran International Airport"},"geometry":{"type":"Point","coordinates":[-115.1520004,36.08010101]}},{"type":"Feature","properties":{"icao":"KPHX","iata":"PHX","name":"Phoenix Sky Harbor International Airport"},"geometry":{"type":"Point","coordinates":[-112.0120010376,33.434299469]}},{"type":"Feature","properties":{"icao":"KSLC","iata":"SLC","name":"Salt Lake City International Airport"},"geometry":{"type":"Point","coordinates":[-111.9779968262,40.7883987427]}},{"type":"Feature","properties":{"icao":"KDEN","iata":"DEN","name":"Denver International Airport"},"geometry":{"type":"Point","coordinates":[-104.672996521,39.8616981506]}},{"type":"Feature","properties":{"icao":"KMSP","iata":"MSP","name":"Minneapolis-St Paul International\/Wold-Chamberlain Airport"},"geometry":{"type":"Point","coordinates":[-93.2218017578,44.8819999695]}},{"type":"Feature","properties":{"icao":"KMCI","iata":"MCI","name":"Kansas City International Airport"},"geometry":{"type":"Point","coordinates":[-94.7138977051,39.2975997925]}},{"type":"Feature","properties":{"icao":"KDFW","iata":"DFW","name":"Dallas Fort Worth International Airport"},"geometry":{"type":"Point","coordinates":[-97.0380020142,32.8968009949]}},{"type":"Feature","properties":{"icao":"KIAH","iata":"IAH","name":"George Bush Intercontinental Houston Airport"},"geometry":{"type":"Point","coordinates":[-95.3414001465,29.9843997955]}},{"type":"Feature","properties":{"icao":"KORD","iata":"ORD","name":"Chicago O'Hare International Airport"},"geometry":{"type":"Point","coordinates":[-87.90480042,41.97859955]}},{"type":"Feature","properties":{"icao":"KSTL","iata":"STL","name":"Lambert St Louis International Airport"},"geometry":{"type":"Point","coordinates":[-90.3700027466,38.7486991882]}},{"type":"Feature","properties":{"icao":"KMEM","iata":"MEM","name":"Memphis International Airport"},"geometry":{"type":"Point","coordinates":[-89.9766998291,35.0424003601]}},{"type":"Feature","properties":{"icao":"KBNA","iata":"BNA","name":"Nashville International Airport"},"geometry":{"type":"Point","coordinates":[-86.6781997681,36.1245002747]}},{"type":"Feature","properties":{"icao":"KIND","iata":"IND","name":"Indianapolis International Airport"},"geometry":{"type":"Point","coordinates":[-86.2944030762,39.717300415]}},{"type":"Feature","properties":{"icao":"KMDW","iata":"MDW","name":"Chicago Midway International Airport"},"geometry":{"type":"Point","coordinates":[-87.7524032593,41.7859992981]}},{"type":"Feature","properties":{"icao":"KDTW","iata":"DTW","name":"Detroit Metropolitan Wayne County Airport"},"geometry":{"type":"Point","coordinates":[-83.3534011841,42.2123985291]}},{"type":"Feature","properties":{"icao":"KCLE","iata":"CLE","name":"Cleveland Hopkins International Airport"},"geometry":{"type":"Point","coordinates":[-81.8498001099,41.4117012024]}},{"type":"Feature","properties":{"icao":"KCVG","iata":"CVG","name":"Cincinnati Northern Kentucky International Airport"},"geometry":{"type":"Point","coordinates":[-84.6678009033,39.0488014221]}},{"type":"Feature","properties":{"icao":"KATL","iata":"ATL","name":"Hartsfield Jackson Atlanta International Airport"},"geometry":{"type":"Point","coordinates":[-84.4281005859,33.6366996765]}},{"type":"Feature","properties":{"icao":"KPIT","iata":"PIT","name":"Pittsburgh International Airport"},"geometry":{"type":"Point","coordinates":[-80.23290253,40.49150085]}},{"type":"Feature","properties":{"icao":"KIAD","iata":"IAD","name":"Washington Dulles International Airport"},"geometry":{"type":"Point","coordinates":[-77.45580292,38.94449997]}},{"type":"Feature","properties":{"icao":"KDCA","iata":"DCA","name":"Ronald Reagan Washington National Airport"},"geometry":{"type":"Point","coordinates":[-77.0376968384,38.8521003723]}},{"type":"Feature","properties":{"icao":"KBWI","iata":"BWI","name":"Baltimore\/Washington International Thurgood Marshal Airport"},"geometry":{"type":"Point","coordinates":[-76.66829681,39.17539978]}},{"type":"Feature","properties":{"icao":"KPHL","iata":"PHL","name":"Philadelphia International Airport"},"geometry":{"type":"Point","coordinates":[-75.2410964966,39.8718986511]}},{"type":"Feature","properties":{"icao":"KEWR","iata":"EWR","name":"Newark Liberty International Airport"},"geometry":{"type":"Point","coordinates":[-74.1687011719,40.6925010681]}},{"type":"Feature","properties":{"icao":"KTEB","iata":"TEB","name":"Teterboro Airport"},"geometry":{"type":"Point","coordinates":[-74.060798645,40.8501014709]}},{"type":"Feature","properties":{"icao":"KJFK","iata":"JFK","name":"John F Kennedy International Airport"},"geometry":{"type":"Point","coordinates":[-73.77890015,40.63980103]}},{"type":"Feature","properties":{"icao":"KLGA","iata":"LGA","name":"La Guardia Airport"},"geometry":{"type":"Point","coordinates":[-73.87259674,40.77719879]}},{"type":"Feature","properties":{"icao":"KBOS","iata":"BOS","name":"General Edward Lawrence Logan International Airport"},"geometry":{"type":"Point","coordinates":[-71.00520325,42.36429977]}},{"type":"Feature","properties":{"icao":"KRDU","iata":"RDU","name":"Raleigh Durham International Airport"},"geometry":{"type":"Point","coordinates":[-78.7874984741,35.8776016235]}},{"type":"Feature","properties":{"icao":"KCLT","iata":"CLT","name":"Charlotte Douglas International Airport"},"geometry":{"type":"Point","coordinates":[-80.9430999756,35.2140007019]}},{"type":"Feature","properties":{"icao":"KTPA","iata":"TPA","name":"Tampa International Airport"},"geometry":{"type":"Point","coordinates":[-82.533203125,27.9755001068]}},{"type":"Feature","properties":{"icao":"KMCO","iata":"MCO","name":"Orlando International Airport"},"geometry":{"type":"Point","coordinates":[-81.3089981079,28.4293994904]}},{"type":"Feature","properties":{"icao":"KFLL","iata":"FLL","name":"Fort Lauderdale Hollywood International Airport"},"geometry":{"type":"Point","coordinates":[-80.1527023315,26.072599411]}},{"type":"Feature","properties":{"icao":"KMIA","iata":"MIA","name":"Miami International Airport"},"geometry":{"type":"Point","coordinates":[-80.2906036377,25.7931995392]}}];
выше - из файла geoJSON аэропортов, которые я создал.
Сейчас я заполняю карту листовки, используя файл geoJSON, например:
var dataLayer = L.geoJSON(airports, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon: myIcon});
}
});
dataLayer.addTo(map);
И затем я запрашиваю данные FAA в $ .each, но я не уверен, как перебрать geoJSON, найти совпадение, а затем обновить L.DivIcon, чтобы изменить цвет.
success: function (data, status, xhr) {
$.each(data.GroundDelays.groundDelay, function(index, i) {
var row = "<tr><td>Ground Delay</td><td>"+i.airport+"</td><td>"+i.avgTime+"</td><td>"+i.reason+"</td></tr>";
table.row.add($(row)).draw();
});