Skip to content

Commit

Permalink
Merge pull request #129 from DavidLevinsky/master
Browse files Browse the repository at this point in the history
GPU optimalizations and new geodata message format
  • Loading branch information
davidmtech authored Jan 9, 2019
2 parents 7732fa2 + 355a83f commit 0d34990
Show file tree
Hide file tree
Showing 41 changed files with 2,227 additions and 1,284 deletions.
5 changes: 2 additions & 3 deletions demos/geodata-geojson-import-from-url/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function onHeightProcessed() {
},

"layers" : {

"track-line" : {
"filter" : ["==", "#type", "line"],
"line": true,
Expand All @@ -73,9 +74,7 @@ function onHeightProcessed() {
"line": true,
"line-width" : 20,
"line-color": [0,0,0,120],
"zbuffer-offset" : [-7,0,0],
"hover-event" : true,
"advanced-hit" : true
"zbuffer-offset" : [-7,0,0]
},

"place" : {
Expand Down
4 changes: 1 addition & 3 deletions demos/geodata-geojson-import/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ function onHeightProcessed() {
"line": true,
"line-width" : 20,
"line-color": [0,0,0,120],
"zbuffer-offset" : [-7,0,0],
"hover-event" : true,
"advanced-hit" : true
"zbuffer-offset" : [-7,0,0]
},

"place" : {
Expand Down
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.16.12",
"version": "2.17.1",
"description": "JavaScript WebGL 3D maps rendering engine",
"main": "src/browser/index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/browser/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ Browser.prototype.initConfig = function() {
jumpAllowed : false,
sensitivity : [1, 0.06, 0.05],
inertia : [0.81, 0.9, 0.7],
legacyInertia : false, // legacy inertia [0.8,0.8,0.8] sensitivity [0.5,0.4]
positionInUrl : false,
positionUrlHistory : false,
constrainCamera : true,
Expand Down Expand Up @@ -377,7 +378,7 @@ Browser.prototype.setConfigParam = function(key, value, ignoreCore) {
case 'zoomAllowed': this.config.zoomAllowed = utils.validateBool(value, true); break;
case 'jumpAllowed': this.config.jumpAllowed = utils.validateBool(value, false); break;
case 'constrainCamera': this.config.constrainCamera = utils.validateBool(value, true); break;
case 'navigationMode': this.config.navigationMode = value; break;
case 'navigationMode': this.config.navigationMode = value; break;
case 'positionInUrl': this.config.positionInUrl = utils.validateBool(value, false); break;
case 'positionUrlHistory': this.config.positionUrlHistory = utils.validateBool(value, false); break;
case 'controlCompass': this.config.controlCompass = utils.validateBool(value, true); this.updateUI(key); break;
Expand All @@ -404,6 +405,7 @@ Browser.prototype.setConfigParam = function(key, value, ignoreCore) {
case 'maxViewExtent': this.config.maxViewExtent = utils.validateNumber(value, 0.01, Number.MAXINTEGER, Number.MAXINTEGER); break;
case 'sensitivity': this.config.sensitivity = utils.validateNumberArray(value, 3, [0,0,0], [10, 10, 10], [1, 0.12, 0.05]); break;
case 'inertia': this.config.inertia = utils.validateNumberArray(value, 3, [0,0,0], [0.99, 0.99, 0.99], [0.85, 0.9, 0.7]); break;
case 'legacyInertia': this.config.legacyInertia = utils.validateBool(value, false); break;
case 'tiltConstrainThreshold': this.config.tiltConstrainThreshold = utils.validateNumberArray(value, 2, [0.5,1], [-Number.MAXINTEGER, -Number.MAXINTEGER], [Number.MAXINTEGER, Number.MAXINTEGER]); break;
case 'geodata': this.config.geodata = value; break;
case 'geojson': this.config.geojson = value; break;
Expand Down Expand Up @@ -474,6 +476,7 @@ Browser.prototype.getConfigParam = function(key) {
case 'jumpAllowed': return this.config.jumpAllowed;
case 'sensitivity': return this.config.sensitivity;
case 'inertia': return this.config.inertia;
case 'legacyInertia': return this.config.legacyInertia;
case 'navigationMode': return this.config.navigationMode;
case 'constrainCamera': return this.config.constrainCamera;
case 'positionInUrl': return this.config.positionInUrl;
Expand Down
118 changes: 42 additions & 76 deletions src/browser/control-mode/map-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ControlModeMapObserver.prototype.drag = function(event) {
//var zoom = event.getDragZoom();
var touches = event.getDragTouches();
var azimuthDistance = this.getAzimuthAndDistance(delta[0], delta[1]);
var sensitivity;
var sensitivity, config = this.config;

var modifierKey = (this.browser.controlMode.altKey
|| this.browser.controlMode.shiftKey
Expand All @@ -55,21 +55,26 @@ ControlModeMapObserver.prototype.drag = function(event) {
return;
}

if (event.getTouchParameter('touchMode') == 'pan' && this.config.rotationAllowed) {
//var pan = event.getTouchParameter('touchPanDelta');
sensitivity = this.config.sensitivity[1] * this.retinaFactor;
this.orientationDeltas.push([delta[0] * sensitivity,
-delta[1] * sensitivity, 0]);
if (event.getTouchParameter('touchMode') == 'pan' && config.rotationAllowed) {

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

} else if (config.zoomAllowed) {

var factor = 1.0 + (event.getTouchParameter('touchDistanceDelta') > 1.0 ? -1 : 1)*0.01;
this.viewExtentDeltas.push(factor);
this.reduceFloatingHeight(0.8);

if (config.legacyInertia) {
this.updateDeltas(false, false, true);
}

this.browser.callListener('map-position-zoomed', {});
}

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

if (pos.getHeightMode() == 'fix') {
var pos2 = map.convertPositionHeightMode(pos, 'float', true);
Expand All @@ -78,7 +83,7 @@ ControlModeMapObserver.prototype.drag = function(event) {
this.setPosition(pos);
}
} else {
sensitivity = this.config.sensitivity[0] * this.retinaFactor;
sensitivity = config.sensitivity[0] * this.retinaFactor;
var fov = pos.getFov();
var fovCorrection = (fov > 0.01 && fov < 179) ? (1.0 / Math.tan(math.radians(fov*0.5))) : 1.0;
var azimuth = math.radians(azimuthDistance[0]);
Expand All @@ -89,14 +94,22 @@ ControlModeMapObserver.prototype.drag = function(event) {

this.coordsDeltas.push(forward);
this.reduceFloatingHeight(0.9);

if (config.legacyInertia) {
this.updateDeltas(true);
}

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

sensitivity = this.config.sensitivity[1] * this.retinaFactor * (pos.getViewMode() != 'obj' ? 0.5 : 1);
this.orientationDeltas.push([delta[0] * sensitivity,
-delta[1] * sensitivity, 0]);
sensitivity = config.sensitivity[1] * this.retinaFactor * (pos.getViewMode() != 'obj' ? 0.5 : 1);
this.orientationDeltas.push([delta[0] * sensitivity, -delta[1] * sensitivity, 0]);

if (config.legacyInertia) {
this.updateDeltas(false, true);
}

this.browser.callListener('map-position-rotated', {});
}
};
Expand Down Expand Up @@ -146,42 +159,7 @@ ControlModeMapObserver.prototype.wheel = function(event) {
map.setPosition(pos);
return;
}

//if (this.config.navigationMode != 'azimuthal2' &&
// this.config.navigationMode != 'free') {

/*
var coords = pos.getCoords();
if (Math.abs(coords[1]) < 75) {
var distance = (pos.getViewExtent()*0.5) / Math.tan(math.radians(pos.getFov()*0.5));
//reduce azimuth when you are far off the planet
var rf = map.getReferenceFrame();
var srs = map.getSrsInfo(rf['navigationSrs']);
if (srs['a']) {
if (distance > (srs['a']*0.5)) {
this.northResetAnimation = true;
}
}
}
*/

//}

/*
var viewExtent = pos.getViewExtent();
if (viewExtent < 75) { factor = 1 + (factor - 1) * 0.7; }
if (viewExtent < 65) { factor = 1 + (factor - 1) * 0.7; }
if (viewExtent < 55) { factor = 1 + (factor - 1) * 0.7; }
if (viewExtent < 45) { factor = 1 + (factor - 1) * 0.7; }
if (viewExtent < 35) { factor = 1 + (factor - 1) * 0.7; }
if (viewExtent < 25) { factor = 1 + (factor - 1) * 0.7; }
if (viewExtent < 15) { factor = 1 + (factor - 1) * 0.7; }
if (viewExtent < 10) { factor = 1 + (factor - 1) * 0.7; }
if (viewExtent < 5) { factor = 1 + (factor - 1) * 0.7; }
*/


this.viewExtentDeltas.push(factor);
this.reduceFloatingHeight(0.8);
this.browser.callListener('map-position-zoomed', {});
Expand Down Expand Up @@ -289,40 +267,24 @@ ControlModeMapObserver.prototype.getAzimuthAndDistance = function(dx, dy) {
};


ControlModeMapObserver.prototype.tick = function() {
ControlModeMapObserver.prototype.updateDeltas = function(onlyLastPan, onlyLastRotate, onlyLastZoom) {
var map = this.browser.getMap();
if (!map) {
return;
}


var pos = map.getPosition(), delta, deltas;
var update = false, azimuth, correction, i;
var inertia = this.config.inertia; //[0.83, 0.9, 0.7];
//var inertia = [0.95, 0.8, 0.8];
//var inertia = [0, 0, 0];

/*if (this.northResetAnimation) {
var o = pos.getOrientation();
o[0] *= 0.85;
pos.setOrientation(o);
if (Math.abs(o[0]) < 0.1) {
this.config.navigationMode = 'azimuthal';
this.northResetAnimation = false;
}
update = true;
}*/
var inertia = this.config.inertia;

//process coords deltas
if (this.coordsDeltas.length > 0) {
if (!onlyLastRotate && !onlyLastZoom && this.coordsDeltas.length > 0) {
deltas = this.coordsDeltas;
var forward = [0,0];
var coords = pos.getCoords();

//get foward vector form coord deltas
for (i = 0; i < deltas.length; i++) {
for (i = (onlyLastPan ? (deltas.length - 1) : 0); i < deltas.length; i++) {
delta = deltas[i];

azimuth = delta[3];
Expand All @@ -339,7 +301,7 @@ ControlModeMapObserver.prototype.tick = function() {
i--;
}
}

var distance = Math.sqrt(forward[0]*forward[0] + forward[1]*forward[1]);
azimuth = math.degrees(Math.atan2(forward[0], forward[1]));

Expand All @@ -365,12 +327,12 @@ ControlModeMapObserver.prototype.tick = function() {
}

//process coords deltas
if (this.orientationDeltas.length > 0) {
if (!onlyLastPan && !onlyLastZoom && this.orientationDeltas.length > 0) {
deltas = this.orientationDeltas;
var orientation = pos.getOrientation();

//apply detals to current orientation
for (i = 0; i < deltas.length; i++) {
for (i = (onlyLastRotate ? (deltas.length - 1) : 0); i < deltas.length; i++) {
delta = deltas[i];
orientation[0] += delta[0];
orientation[1] += delta[1];
Expand All @@ -393,12 +355,12 @@ ControlModeMapObserver.prototype.tick = function() {
}

//process view extents deltas
if (this.viewExtentDeltas.length > 0) {
if (!onlyLastRotate && !onlyLastPan && this.viewExtentDeltas.length > 0) {
deltas = this.viewExtentDeltas;
var viewExtent = pos.getViewExtent();

//apply detals to current view extent
for (i = 0; i < deltas.length; i++) {
for (i = (onlyLastZoom ? (deltas.length - 1) : 0); i < deltas.length; i++) {
viewExtent *= deltas[i];
deltas[i] += (1 - deltas[i]) * (1.0 - inertia[2]);

Expand All @@ -422,6 +384,10 @@ ControlModeMapObserver.prototype.tick = function() {
}
};

ControlModeMapObserver.prototype.tick = function() {
this.updateDeltas();
};


ControlModeMapObserver.prototype.reset = function() {
this.coordsDeltas = [];
Expand Down
2 changes: 1 addition & 1 deletion src/browser/ui/control/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var UIControlSearch = function(ui, visible, visibleLock) {

this.ignoreDrag = false;

this.urlTemplate = '//cdn.melown.com/vts/geocode?q={value}&format=json&lang=en-US&addressdetails=1&limit=20';
this.urlTemplate = '//cdn.melown.com/vtsapi/geocode?q={value}&format=json&lang=en-US&addressdetails=1&limit=20';
this.urlTemplate2 = this.urlTemplate;
this.data = [];
this.lastSearch = '';
Expand Down
Loading

0 comments on commit 0d34990

Please sign in to comment.