add destroy on Globe + startRoation option

This commit is contained in:
2020-04-19 16:13:29 +02:00
parent 094614f83c
commit caa84e10e3
4 changed files with 4705 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ import { Container, Mesh, Material, Texture, SphereGeometryBuffer, PlaneGeometry
import GlobeVS from './globe-vs'
import GlobeFS from './globe-fs'
const FOV = 1;
const FOV = 1;//camera Field of view; we use 1 to prevent strong perspective effect on the globe
/** get 3D position on a sphere from longitute lattitude */
const lonLatToVector3 = (lng, lat) => {
@@ -19,6 +19,11 @@ const lonLatToVector3 = (lng, lat) => {
return [x,y,z]
}
function degToRad(deg) {
return deg * Math.PI/180
}
class WebglGlobe {
// Constructor
@@ -35,6 +40,8 @@ class WebglGlobe {
this.currMarkerScrollOffset = 0
this.markersScrollOffset = 0
this.globeScrollOffset = 0
this.globeAutoRotation = degToRad(this.options.rotationStart * -1) || 0
let gl
let canvas = document.createElement('canvas')
@@ -252,6 +259,14 @@ class WebglGlobe {
}
}
destroy() {
this.disable()//stop render loop
document.body.removeChild( this.$markerWrapper )
document.body.removeChild( this.renderer.canvas )
this.camera.delete()//to remove event listeners
}
/**
* Flag to stop rendering the webgl if the globe isnt visible
* This helps saving perfs and battery
@@ -283,7 +298,8 @@ class WebglGlobe {
mat4.multiply(this.viewProjectionMatrix, this.viewProjectionMatrix, this.camera.inverseWorldMatrix)
// Auto rotate the globe
this.globeMesh.rotation[1] += this.options.autoRotationSpeed
this.globeAutoRotation += this.options.autoRotationSpeed
this.globeMesh.rotation[1] = this.globeAutoRotation
this.globeMesh.updateMatrix()
this.globeMesh.updateWorldMatrix()