Skip to content

Commit

Permalink
gv: Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
j-devel committed May 17, 2022
1 parent 789d21d commit 7f0332d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
25 changes: 15 additions & 10 deletions examples/geo-viewer/src/gui-helper.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import OoGui from 'oo-gui/src';

class GuiHelper extends OoGui {
constructor(data, cbs, env={}) {
super(data, {
constructor(data, env={}) {
super(data, {
title: 'geo-viewer',
width: 240,
});

this.onChangeGrids = cbs.onChangeGrids;
this.onCapture = cbs.onCapture;
this.onChangeAutoOrbit = cbs.onChangeAutoOrbit;
this.onChangeMode = cbs.onChangeMode;
this.onChangeVrLaser = cbs.onChangeVrLaser;
this.onChangeLeaflet = cbs.onChangeLeaflet;
this.onChangeMedia = cbs.onChangeMedia;
this.onChangeLoc = cbs.onChangeLoc;
this.onChangeMode = null;
this.onCapture = null;
this.onChangeGrids = null;
this.onChangeAutoOrbit = null;
this.onChangeVrLaser = null;
this.onChangeLeaflet = null;
this.onChangeMedia = null;
this.onChangeLoc = null;

this.env = env;
this._autoOrbitController = null;
this.footer = GuiHelper.createFooter();
}

setCallbacks(cbs) {
Object.assign(this, cbs);
return this;
}

// impl
init(gui, data, params) {
this.locations = { // key: [lat, lng],
Expand Down
40 changes: 22 additions & 18 deletions examples/geo-viewer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class App extends Threelet {

this.initComponents();

this.monitor = new Monitor();
this.render = () => { // override
this._render();
this.monitor.updateStats();
Expand Down Expand Up @@ -83,6 +82,7 @@ class App extends Threelet {

this.updateTerrain(title);

this.monitor = new Monitor();
this.map = new MapHelper({
dom: document.getElementById('map'),
domWrapper: document.getElementById('map-wrapper'),
Expand All @@ -97,7 +97,8 @@ class App extends Threelet {
},
});
this.media = new MediaHelper(
document.getElementById('media'), document.getElementById('media-wrapper'));
document.getElementById('media'),
document.getElementById('media-wrapper'));

this.laser = new Laser(this.scene, this.camera);
this.orbit = new Orbit(this.scene);
Expand Down Expand Up @@ -139,7 +140,25 @@ class App extends Threelet {
}

initGui(monitorDom) {
const cbs = {
const defaults = App.guiDefaults();
const data = Object.assign({}, defaults);
const gh = new GuiHelper(data, this.env)
.setDefaults(defaults)
.setCallbacks(this.guiCallbacks())
.appendToFooter(monitorDom);

if (this.env.isGuiClosed) {
gh.close();
}

return gh;
}

guiCallbacks() {
return {
onChangeMode: mode => {
this._updateTerrain(mode.toLowerCase());
},
onCapture: () => {
this.capture();
},
Expand All @@ -159,9 +178,6 @@ class App extends Threelet {

this.anim.toggle(tf);
},
onChangeMode: mode => {
this._updateTerrain(mode.toLowerCase());
},
onChangeVrLaser: tf => {
this.laser.active = tf;
},
Expand All @@ -182,18 +198,6 @@ class App extends Threelet {
}
},
};

const defaults = App.guiDefaults();
const data = Object.assign({}, defaults);
const gh = new GuiHelper(data, cbs, this.env)
.setDefaults(defaults)
.appendToFooter(monitorDom);

if (this.env.isGuiClosed) {
gh.close();
}

return gh;
}

static guiDefaults() {
Expand Down

0 comments on commit 7f0332d

Please sign in to comment.