Skip to content

Commit

Permalink
Merge pull request #33 from DavidLevinsky/newdev
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
davidmtech authored Apr 28, 2017
2 parents 0c393cb + a69d695 commit 7ea0c74
Show file tree
Hide file tree
Showing 92 changed files with 5,486 additions and 5,510 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vts-browser-js",
"version": "2.1.2",
"version": "2.1.3",
"description": "JavaScript WebGL 3D maps rendering engine",
"main": "src/browser/index.js",
"scripts": {
Expand Down
26 changes: 13 additions & 13 deletions src/browser/autopilot/autopilot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Autopilot = function(browser) {

Autopilot.prototype.setAutorotate = function(speed) {
if (this.autoRotate != speed) {
this.browser.callListener("autorotate-changed", { "autorotate" : speed});
this.browser.callListener('autorotate-changed', { 'autorotate' : speed});
}

this.autoRotate = speed;
Expand Down Expand Up @@ -53,7 +53,7 @@ Autopilot.prototype.flyToDAH = function(distance, azimuth, height, options) {
options = options || {};

var trajectory = map.generatePIHTrajectory(map.getPosition(), distance, azimuth, height, options);
this.setTrajectory(trajectory, options["samplePeriod"] || 10, options);
this.setTrajectory(trajectory, options['samplePeriod'] || 10, options);
};


Expand All @@ -65,7 +65,7 @@ Autopilot.prototype.flyTo = function(position, options) {

options = options || {};
var trajectory = map.generateTrajectory(map.getPosition(), position, options);
this.setTrajectory(trajectory, options["samplePeriod"] || 10, options);
this.setTrajectory(trajectory, options['samplePeriod'] || 10, options);
};


Expand All @@ -89,20 +89,20 @@ Autopilot.prototype.setTrajectory = function(trajectory, sampleDuration, options
this.setAutorotate(0);
this.setAutopan(0,0);

this.speed = options["speed"] || 1.0;
this.speed = options['speed'] || 1.0;
if (this.finished) {
this.lastControlMode = this.browser.getControlMode().getCurrentControlMode();
}
this.browser.getControlMode().setCurrentControlMode("disabled");
this.browser.getControlMode().setCurrentControlMode('disabled');

this.trajectory = trajectory;
this.sampleDuration = sampleDuration;
//this.

this.browser.callListener("fly-start", { "startPosition" : this.trajectory[0],
"endPosition" : this.trajectory[this.trajectory.length - 1],
"options" : options
});
this.browser.callListener('fly-start', { 'startPosition' : this.trajectory[0],
'endPosition' : this.trajectory[this.trajectory.length - 1],
'options' : options
});

this.timeStart = performance.now();
this.finished = false;
Expand Down Expand Up @@ -146,17 +146,17 @@ Autopilot.prototype.tick = function() {
map.setPosition(this.trajectory[sampleIndex]);
//console.log(JSON.stringify(this.trajectory[sampleIndex]));

this.browser.callListener("fly-progress", { "position" : this.trajectory[sampleIndex],
"progress" : 100 * (sampleIndex / totalSamples)
});
this.browser.callListener('fly-progress', { 'position' : this.trajectory[sampleIndex],
'progress' : 100 * (sampleIndex / totalSamples)
});

} else {
map.setPosition(this.trajectory[totalSamples]);
//console.log(JSON.stringify(this.trajectory[totalSamples]));
}

if (sampleIndex >= this.trajectory.length) {
this.browser.callListener("fly-end", { "position" : this.trajectory[totalSamples] });
this.browser.callListener('fly-end', { 'position' : this.trajectory[totalSamples] });

this.browser.getControlMode().setCurrentControlMode(this.lastControlMode);
this.finished = true;
Expand Down
280 changes: 140 additions & 140 deletions src/browser/browser.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/browser/control-mode/control-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ ControlMode.prototype.setCurrentControlMode = function(id, options) {
this.currentControlMode = newMode;

// call reset
if (newMode["reset"]) {
newMode["reset"](options);
if (newMode['reset']) {
newMode['reset'](options);
}
};

Expand Down Expand Up @@ -165,9 +165,9 @@ ControlMode.prototype.onTick = function(event) {

// Private metod
ControlMode.prototype.updateModifierKeys = function(event) {
this.altKey = event.getModifierKey("alt");
this.shiftKey = event.getModifierKey("shift");
this.ctrlKey = event.getModifierKey("ctrl");
this.altKey = event.getModifierKey('alt');
this.shiftKey = event.getModifierKey('shift');
this.ctrlKey = event.getModifierKey('ctrl');
//console.log("alt:" + this.altKey + " ctrl:" + this.ctrlKey + " shift:" + this.shiftKey);
};

Expand Down
84 changes: 42 additions & 42 deletions src/browser/control-mode/map-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ var ControlModeMapObserver = function(browser) {
this.orientationDeltas = [];
this.viewExtentDeltas = [];

this["drag"] = this.drag;
this["wheel"] = this.wheel;
this["tick"] = this.tick;
this["reset"] = this.reset;
this["keyup"] = this.keyup;
this["keydown"] = this.keydown;
this["keypress"] = this.keypress;
this["doubleclick"] = this.doubleclick;
this['drag'] = this.drag;
this['wheel'] = this.wheel;
this['tick'] = this.tick;
this['reset'] = this.reset;
this['keyup'] = this.keyup;
this['keydown'] = this.keydown;
this['keypress'] = this.keypress;
this['doubleclick'] = this.doubleclick;

this.retinaFactor = 1.0 / Math.max(1.0,(window.devicePixelRatio || 1) - 1);
};
Expand All @@ -49,28 +49,28 @@ ControlModeMapObserver.prototype.drag = function(event) {


if (touches == 2) {//} && /*event.getDragButton("middle")*/ zoom != 0 && this.config.zoomAllowed) {
if (pos.getViewMode() != "obj") {
if (pos.getViewMode() != 'obj') {
return;
}

if (event.getTouchParameter("touchMode") == "pan" && this.config.rotationAllowed) {
var pan = event.getTouchParameter("touchPanDelta");
if (event.getTouchParameter('touchMode') == 'pan' && this.config.rotationAllowed) {
var pan = event.getTouchParameter('touchPanDelta');
var sensitivity = this.config.sensitivity[1] * this.retinaFactor;
this.orientationDeltas.push([delta[0] * sensitivity,
-delta[1] * sensitivity, 0]);
this.browser.callListener("map-position-rotated", {});
-delta[1] * sensitivity, 0]);
this.browser.callListener('map-position-rotated', {});
} else if (this.config.zoomAllowed) {
var factor = 1.0 + (event.getTouchParameter("touchDistanceDelta") > 1.0 ? -1 : 1)*0.01;
var factor = 1.0 + (event.getTouchParameter('touchDistanceDelta') > 1.0 ? -1 : 1)*0.01;
this.viewExtentDeltas.push(factor);
this.reduceFloatingHeight(0.8);
this.browser.callListener("map-position-zoomed", {});
this.browser.callListener('map-position-zoomed', {});
}

} else if ((event.getDragButton("left") && !modifierKey)
} else if ((event.getDragButton('left') && !modifierKey)
&& this.config.panAllowed) { //pan

if (pos.getHeightMode() == "fix") {
var pos2 = map.convertPositionHeightMode(pos, "float", true);
if (pos.getHeightMode() == 'fix') {
var pos2 = map.convertPositionHeightMode(pos, 'float', true);
if (pos2 != null) {
pos = pos2;
this.setPosition(pos);
Expand All @@ -81,21 +81,21 @@ ControlModeMapObserver.prototype.drag = function(event) {
var fovCorrection = (fov > 0.01 && fov < 179) ? (1.0 / Math.tan(math.radians(fov*0.5))) : 1.0;
var azimuth = math.radians(azimuthDistance[0]);
var forward = [Math.sin(azimuth), //direction vector x
Math.cos(azimuth), //direction vector y
azimuthDistance[1] * fovCorrection * sensitivity, azimuthDistance[0], //distance and azimut
coords[0], coords[1]]; //coords
Math.cos(azimuth), //direction vector y
azimuthDistance[1] * fovCorrection * sensitivity, azimuthDistance[0], //distance and azimut
coords[0], coords[1]]; //coords

this.coordsDeltas.push(forward);
this.reduceFloatingHeight(0.9);
this.browser.callListener("map-position-panned", {});
this.browser.callListener('map-position-panned', {});
}
} else if (((touches <= 1 && event.getDragButton("right")) || event.getDragButton("middle") || modifierKey)
} else if (((touches <= 1 && event.getDragButton('right')) || event.getDragButton('middle') || modifierKey)
&& this.config.rotationAllowed) { //rotate

var sensitivity = this.config.sensitivity[1] * this.retinaFactor;
this.orientationDeltas.push([delta[0] * sensitivity,
-delta[1] * sensitivity, 0]);
this.browser.callListener("map-position-rotated", {});
-delta[1] * sensitivity, 0]);
this.browser.callListener('map-position-rotated', {});
}
};

Expand All @@ -120,13 +120,13 @@ ControlModeMapObserver.prototype.wheel = function(event) {
pos.setFov(fov);
map.setPosition(pos);
} else {
if (pos.getViewMode() != "obj") {
if (pos.getViewMode() != 'obj') {
return;
}

this.viewExtentDeltas.push(factor);
this.reduceFloatingHeight(0.8);
this.browser.callListener("map-position-zoomed", {});
this.browser.callListener('map-position-zoomed', {});
}
};

Expand All @@ -149,17 +149,17 @@ ControlModeMapObserver.prototype.doubleclick = function(event) {
var coords = event.getMouseCoords();

//get hit coords with fixed height
var mapCoords = map.getHitCoords(coords[0], coords[1], "fix");
var mapCoords = map.getHitCoords(coords[0], coords[1], 'fix');

if (mapCoords) {
var pos = map.getPosition();
pos.setCoords(mapCoords);
pos = map.convertPositionHeightMode(pos, "fix");
pos = map.convertPositionHeightMode(pos, 'fix');
pos.setHeight(mapCoords[2]);
//pos = map.convertPositionHeightMode(pos, "fix");
//pos.setPositionHeight(0);

this.browser.autopilot.flyTo(pos, {"mode" : "direct", "maxDuration" : 2000 });
this.browser.autopilot.flyTo(pos, {'mode' : 'direct', 'maxDuration' : 2000 });
}
};

Expand Down Expand Up @@ -189,8 +189,8 @@ ControlModeMapObserver.prototype.reduceFloatingHeight = function(factor) {
var pos = map.getPosition();
var coords = pos.getCoords();

if (pos.getHeightMode() == "float" &&
pos.getViewMode() == "obj") {
if (pos.getHeightMode() == 'float' &&
pos.getViewMode() == 'obj') {
if (coords[2] != 0) {
coords[2] *= factor;

Expand All @@ -208,8 +208,8 @@ ControlModeMapObserver.prototype.reduceFloatingHeight = function(factor) {
ControlModeMapObserver.prototype.isNavigationSRSProjected = function() {
var map = this.browser.getMap();
var rf = map.getReferenceFrame();
var srs = map.getSrsInfo(rf["navigationSrs"]);
return (srs) ? (srs["type"] == "projected") : false;
var srs = map.getSrsInfo(rf['navigationSrs']);
return (srs) ? (srs['type'] == 'projected') : false;
};


Expand Down Expand Up @@ -282,7 +282,7 @@ ControlModeMapObserver.prototype.tick = function(event) {
//console.log("tick: " + azimuth + " " + distance);

//apply final azimuth and distance
if (this.config.navigationMode == "free") {
if (this.config.navigationMode == 'free') {
var correction = pos.getOrientation()[0];
pos = map.movePositionCoordsTo(pos, (this.isNavigationSRSProjected() ? -1 : 1) * azimuth, distance);
correction = pos.getOrientation()[0] - correction;
Expand Down Expand Up @@ -432,13 +432,13 @@ function constrainMapPosition(browser, pos) {
var distance = (pos.getViewExtent()*0.5) / Math.tan(math.radians(pos.getFov()*0.5));

//reduce tilt whe you are far off the planet
if (pos.getViewMode() == "obj") {
if (pos.getViewMode() == 'obj') {
var rf = map.getReferenceFrame();
var srs = map.getSrsInfo(rf["navigationSrs"]);
var srs = map.getSrsInfo(rf['navigationSrs']);


if (srs["a"]) {
var factor = Math.min(distance / (srs["a"]*0.5), 1.0);
if (srs['a']) {
var factor = Math.min(distance / (srs['a']*0.5), 1.0);
var maxTilt = 20 + ((-90) - 20) * factor;
var minTilt = -90;

Expand All @@ -457,7 +457,7 @@ function constrainMapPosition(browser, pos) {
}

//do not allow camera under terrain
var camPos = map.getPositionCameraCoords(pos, "float");
var camPos = map.getPositionCameraCoords(pos, 'float');
//var cameraConstrainDistance = 1;
var cameraConstrainDistance = (minVE*0.5) / Math.tan(math.radians(pos.getFov()*0.5));
cameraConstrainDistance *= 0.5; //divice by 2 to alow 45deg tilt in maximum zoom
Expand All @@ -479,7 +479,7 @@ function constrainMapPosition(browser, pos) {
o[1] = value;
pos.setOrientation(o);

if (map.getPositionCameraCoords(pos, "float")[2] < hmax) {
if (map.getPositionCameraCoords(pos, 'float')[2] < hmax) {
return getFinalOrientation(start, value, level+1);
} else {
return getFinalOrientation(value, end, level+1);
Expand All @@ -493,7 +493,7 @@ function constrainMapPosition(browser, pos) {
}

return pos;
};
}


export {ControlModeMapObserver, constrainMapPosition};
18 changes: 9 additions & 9 deletions src/browser/control-mode/pano.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ var ControlModePano = function(browser) {

this.impulse = [0, 0];

this["drag"] = this.drag;
this["down"] = this.drag;
this["up"] = this.drag;
this["wheel"] = this.wheel;
this["tick"] = this.tick;
this["reset"] = this.reset;
this["keyup"] = this.keyup;
this["keydown"] = this.keydown;
this["keypress"] = this.keypress;
this['drag'] = this.drag;
this['down'] = this.drag;
this['up'] = this.drag;
this['wheel'] = this.wheel;
this['tick'] = this.tick;
this['reset'] = this.reset;
this['keyup'] = this.keyup;
this['keydown'] = this.keydown;
this['keypress'] = this.keypress;
};


Expand Down
6 changes: 3 additions & 3 deletions src/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ var proj4 = Proj4;
function browser (element, config) {
var browserInterface = new BrowserInterface(element, config);
return browserInterface.core ? browserInterface : null;
};
}

function getBrowserVersion() {
// return "Browser: 2.0.0, Core: " + getCoreVersion();
return "" + getCoreVersion();
};
return '' + getCoreVersion();
}

export {vec2,vec3,vec4,mat3,mat4,math,utils,getCoreVersion,checkSupport,browser,getBrowserVersion,proj4};
Loading

0 comments on commit 7ea0c74

Please sign in to comment.