var sunAngle = 30;
window.addEventListener( "earthjsload", function() {
myearth = new Earth( document.getElementById('myearth'), {
location: { lat: 21, lng: 30 },
sunLocation: { lat: 0, lng: 360 - sunAngle },
zoom: 1,
light: 'sun',
sunDirection : { x: 0, y: 0.25 },
lightColor: '#FFFCE8' ,
shadows: false,
lightAmbience: 0.6,
shininess: 0.1,
autoRotate: true,
autoRotateSpeed: 0.4,
transparent: true,
mapLandColor: '#5b646b',
mapSeaColor: 'rgba(45,170,255,0.9)',
mapBorderColor: 'rgba(230,230,230,0.9)',
mapBorderWidth: 0.2,
mapStyles: '#ES, #PT, #FR, #IT, #TR, #NL, #BE, #PL, #CZ, #AT, #CH, #HU, #RO, #GR, #CY, #IL, #AE, #KR, #AU, #MX, #US, #CA, #DO, #GB, #NO, #SE, #FI, #AR, #NZ { fill: rgba(29,37,45,0.8); } #DE { fill: rgba(29,37,45,1); }',
} );
// setup
myearth.addEventListener( "ready", function() {
// add tooltip overlay
tooltip = this.addOverlay( {
className : 'tooltip',
visible : false,
containerScale : 0.2,
depthScale : 0.4
} );
photo_overlay = this.addOverlay( {
content: '<div id="photo"><div id="close-photo" onclick="closePhoto(); event.stopPropagation();"></div></div>',
visible: false,
containerScale: 1,
depthScale: 0.5
} );
// add markers
for ( var i=0; i < markers.length; i++ ) {
var marker = myearth.addMarker( {
mesh: ["Pin", "Needle"],
color: '#FFA300',
location : markers[i].location,
scale: 0.4,
hotspot: true,
hotspotRadius : 0.75,
hotspotHeight : 0.2,
// custom properties
title : markers[i].title,
link : markers[i].link
} );
marker.addEventListener('mouseover', enterMarker);
marker.addEventListener('mouseout', leaveMarker);
}
var photos = [
{ location: { lat: 51.07079729, lng: 10.97979517 }, src: 'https://enfold.webers-webdesign.de/wp-content/uploads/schmale-logtec-firmengebaeude-warburg.jpg' },
];
// add photo pins
for ( var j=0; j < photos.length; j++ ) {
var myMarker = this.addMarker( {
mesh: ["Pin", "Needle"],
color: '#FFA300',
title: 'Deutschland',
location : photos[j].location,
scale: 0.01,
offset: 1.6,
visible: false,
transparent: true,
hotspot: true,
hotspotRadius : 0.75,
hotspotHeight : 0.9,
// custom property
photo_info: photos[j]
} );
myMarker.addEventListener('click', openPhoto);
myMarker.addEventListener('mouseover', enterMarker);
myMarker.addEventListener('mouseout', leaveMarker);
// animate marker
setTimeout( (function() {
this.visible = true;
this.animate( 'scale', 0.7, { duration: 140 } );
this.animate( 'offset', 0, { duration: 1100, easing: 'bounce' } );
}).bind(myMarker), 280 * j );
}
});
// close photo overlay when navigating away
myearth.addEventListener( "change", function() {
if ( ! current_marker || auto_rotate ) return;
if ( Earth.getAngle( myearth.location, current_marker.location ) > 45 ) {
closePhoto();
}
} );
});
function enterMarker() {
tooltip.location = this.location;
tooltip.content = this.title;
tooltip.element.style.marginTop = '-' + String(this.scale*0.5 + 0.75) + 'em';
tooltip.visible = true;
}
function leaveMarker() {
tooltip.visible = false;
}
var current_marker, auto_rotate;
function openPhoto() {
// close current photo
if ( current_marker ) {
closePhoto();
window.setTimeout( openPhoto.bind(this), 120 );
return;
}
// rotate earth if needed
if ( myearth.goTo( this.location, { relativeDuration: 100, approachAngle: 12, end: function(){auto_rotate=false;} } ) ) {
auto_rotate = true;
}
document.getElementById('photo').style.backgroundImage = "url("+ this.photo_info.src +")";
photo_overlay.location = this.location;
photo_overlay.visible = true;
setTimeout( function(){
document.getElementById('photo').className = 'photo-appear';
}, 120);
this.animate( 'scale', 0.001, { duration: 150 } );
current_marker = this;
}
function closePhoto() {
if ( ! current_marker ) return;
document.getElementById('photo').className = '';
setTimeout( (function(){
document.getElementById('photo').style.backgroundImage = 'none';
photo_overlay.visible = false;
this.opacity = 0.9;
this.animate( 'scale', 0.7, { duration: 150 } );
}).bind(current_marker), 100 );
current_marker = false;
}