-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b262e0c
commit 596f4c5
Showing
4 changed files
with
81 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,64 @@ | ||
Mapa inventario de la aplicación | ||
<div id="map"></div> | ||
<script> | ||
mapboxgl.accessToken = '<?= getenv("MAPBOX")?>'; | ||
const map = new mapboxgl.Map({ | ||
container: 'map', | ||
style: 'mapbox://styles/mapbox/streets-v9', | ||
projection: 'globe', // Display the map as a globe, since satellite-v9 defaults to Mercator | ||
zoom: 1, | ||
center: [30, 15] | ||
}); | ||
|
||
map.addControl(new mapboxgl.NavigationControl()); | ||
map.scrollZoom.disable(); | ||
|
||
map.on('style.load', () => { | ||
map.setFog({}); // Set the default atmosphere style | ||
}); | ||
|
||
// The following values can be changed to control rotation speed: | ||
|
||
// At low zooms, complete a revolution every two minutes. | ||
const secondsPerRevolution = 240; | ||
// Above zoom level 5, do not rotate. | ||
const maxSpinZoom = 5; | ||
// Rotate at intermediate speeds between zoom levels 3 and 5. | ||
const slowSpinZoom = 3; | ||
|
||
let userInteracting = false; | ||
const spinEnabled = true; | ||
|
||
function spinGlobe() { | ||
const zoom = map.getZoom(); | ||
if (spinEnabled && !userInteracting && zoom < maxSpinZoom) { | ||
let distancePerSecond = 360 / secondsPerRevolution; | ||
if (zoom > slowSpinZoom) { | ||
// Slow spinning at higher zooms | ||
const zoomDif = | ||
(maxSpinZoom - zoom) / (maxSpinZoom - slowSpinZoom); | ||
distancePerSecond *= zoomDif; | ||
} | ||
const center = map.getCenter(); | ||
center.lng -= distancePerSecond; | ||
// Smoothly animate the map over one second. | ||
// When this animation is complete, it calls a 'moveend' event. | ||
map.easeTo({ center, duration: 1000, easing: (n) => n }); | ||
} | ||
} | ||
|
||
// Pause spinning on interaction | ||
map.on('mousedown', () => { | ||
userInteracting = true; | ||
}); | ||
map.on('dragstart', () => { | ||
userInteracting = true; | ||
}); | ||
|
||
// When animation is complete, start spinning if there is no ongoing interaction | ||
map.on('moveend', () => { | ||
spinGlobe(); | ||
}); | ||
|
||
spinGlobe(); | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters