viewof map2 = {
let buttonText = "Welcome!";
const container = html`<div id='map' class='bg-gray-dark w-full h600'></div>`;
const footer = html`
<div>
<ul class='nav_links'>
<li class='mylistElement'>
<p class='mylistTitle'>Flight progress</p>
<p>
<svg width="76" height="15" viewBox="0 0 76 15" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1.1582 7.54028H75.3711" stroke="white" stroke-linecap="round"/>
<path d="M49.3058 6.54773L48.1621 0.480224L50.0554 0.446686L52.6644 6.42321C60.1768 6.30932 60.4781 8.56037 52.7013 8.69623L50.2829 14.8895L48.3896 14.923L49.3829 8.73971L45.4535 8.78782L43.3102 10.8551L41.885 10.8652L43.9792 7.67166L41.7979 4.50845L43.2231 4.49835L45.4164 6.51463L49.2847 6.48715L49.3058 6.54773Z" fill="white"/>
</svg>
</p>
</li>
<li class='mylistElement'>
<p class='mylistTitle'>Distance</p>
<p>4710 km</p>
</li>
<li class='mylistElement'>
<p class='mylistTitle'>Time to go</p>
<p>2h 45min</p>
</li>
<li class='mylistElement'>
<p class='mylistTitle'>Altitude</p>
<p>11889 m</p>
</li>
<li class='mylistElement'>
<p class='mylistTitle'>Speed</p>
<p>878 km/h</p>
</li>
<li class='mylistElement'>
<p class='mylistTitle'>Local time</p>
<p>08:25 am</p>
</li>
<li class='mylistElement'>
<p class='mylistTitle'>Local radio station</p>
<div style="display: flex; align-items: center; justify-content: space-around;">
<p>Radio Alistiqama</p>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="7.87012" cy="7.67871" r="7.67871" fill="white"/>
<path d="M5.48145 10.7235V5.4441C5.48145 4.6734 6.31654 4.19239 6.98321 4.5791L11.4504 7.17035C12.1085 7.55212 12.1161 8.49987 11.4642 8.89218L6.99704 11.5803C6.33054 11.9814 5.48145 11.5013 5.48145 10.7235Z" fill="#29323A"/>
</svg>
</div>
</li>
</ul>
</div>`;
const button = html`
<div class='box'>
<p id="mapbutton">${buttonText}</p>
</div>`;
const parent = html`<div></div>`;
parent.appendChild(button);
parent.appendChild(container);
parent.appendChild(footer);
//console.log(test);
const configs = config.tenerifaHelsinki;
let bearing = turf.bearing(configs.origin, configs.destination);
const map = new mapboxgl.Map({
container,
style,
center: configs.mapCenter,
zoom: configs.zoom,
projection: 'globe',
pitch: 40,
attributionControl: false
});
invalidation.then(() => map.remove());
map.addControl(new mapboxgl.FullscreenControl());
container.value = map;
map.on('load', () => {
map.resize();
addIconLayers(map, features, bearing);
container.dispatchEvent(new CustomEvent('input'));
});
// wait for the terrain to load before starting animations
map.once('idle', () => {
// animate
const distance = turf.lineDistance(features.route);
let start;
const animationDuration = configs.animationDuration;
//get countries from source for geofencing
const countries = map.querySourceFeatures('composite', {sourceLayer: 'country_boundaries'});
const intersectingCountries = countries.filter((country) => turf.booleanIntersects(features.route, country));
function frame(time) {
if (!start) start = time;
const phase = (time - start) / animationDuration;
const pointAlongRoute = turf.along(
features.route.features[0],
distance * phase
);
map.getSource('animatedIconSource').setData(pointAlongRoute);
//this would be nicer with line-gradient, but can't get it to work
const split = turf.lineSplit(features.route.features[0], pointAlongRoute);
map.getSource('routeSourceUpdated').setData(split.features[0]);
//start camera behind
const translatedRoute = turf.transformTranslate(features.route.features[0], -800, bearing);
const pointAlongRouteCamera = turf.along(
translatedRoute,
distance * phase
);
//interate through country subset and update button
intersectingCountries.forEach((country) => {
if (turf.booleanPointInPolygon(pointAlongRoute, country)) {
document.getElementById('mapbutton').innerHTML = country.properties.name;
}
})
//constantly update bearing, otherwise icons gets off track
bearing = turf.bearing(pointAlongRoute, configs.destination);
map.setLayoutProperty(
'animatedIconShadow',
'icon-rotate',
bearing
);
map.setLayoutProperty(
'animatedIcon',
'icon-rotate',
bearing
);
if(followBtn)updateCamera(map, bearing, pointAlongRouteCamera.geometry.coordinates, configs);
if (phase > 1) {
return;
}
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
});
return parent;
}