/* eslint-disable */
var map = L.map('mapid').setView([63.8333, -152], 1),
accessToken = 'pk.eyJ1IjoiZmx5bG9jYWwiLCJhIjoiY2t0OHUxZXB6MTVueTJ4cGVwOHRuc2s2NyJ9.YF9frLvISHfOuT7nqs3TNg',
apiUrl = `https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=${accessToken}`;
var form = `AND(Is_Origin=1,{IsCurrent-AsOrigin}='Yes')`;
var markers = L.markerClusterGroup();
var destinationsLayer = L.layerGroup();
var points = [],
mainOffset;
async function fetchMapData() {
const response = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${form}&fields[]=Airport_IATA&fields[]=Icon_Url&fields[]=Latitude_Deg&fields[]=Longitude_Deg&sort[0][field]=Airport_IATA&sort[0][direction]=asc`, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer keyJ2ht64ZSN57AG1'
},
});
response.ok; // => false
response.status; // => 404
const mapData = await response.json();
points = mapData.records;
mainOffset = mapData.offset;
return mapData;
}
async function fetchMapData2(mapData) {
if (mapData.offset) {
const response = await fetch(`https://api.airtable.com/v0/appiQwfVZixRgRICe/Airports_IATA?filterByFormula=${form}&fields[]=Airport_IATA&fields[]=Icon_Url&fields[]=Latitude_Deg&fields[]=Longitude_Deg&sort[0][field]=Airport_IATA&sort[0][direction]=asc&offset=${mapData.offset}`, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer keyJ2ht64ZSN57AG1'
},
});
response.ok; // => false
response.status; // => 404
const mapData2 = await response.json();
points = [...points, ...mapData2.records];
return mapData2;
}
}
function getOrigIcon(icon) {
var origIcon = L.icon({
iconUrl: icon,
//shadowUrl: 'leaf-shadow.png',
iconSize: [80, 40], // size of the icon
//shadowSize: [50, 64], // size of the shadow
iconAnchor: [40, 40], // point of the icon which will correspond to marker's location
//shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [0, 0] // point from which the popup should open relative to the iconAnchor
});
return origIcon;
}
function getBlueIcon() {
var origIcon = L.icon({
iconUrl: 'https://spencerflagg.com/flylocal/pins/pin.svg',
//shadowUrl: 'leaf-shadow.png',
iconSize: [14, 16], // size of the icon
//shadowSize: [50, 64], // size of the shadow
iconAnchor: [7, 16], // point of the icon which will correspond to marker's location
//shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [0, 0] // point from which the popup should open relative to the iconAnchor
});
return origIcon;
}
fetchMapData().then(mapData => {
fetchMapData2(mapData).then(function () {
var mapDataFiltered = points.map((record) => {
return {
"iata": record.fields.Airport_IATA,
"lat": record.fields.Latitude_Deg,
"long": record.fields.Longitude_Deg,
"icon": record.fields.Icon_Url
}
});
console.log(mapDataFiltered); // => 'Page not found'
mapDataFiltered.forEach((record) => {
var popupContent = `