Skip to content

Commit

Permalink
- #111 Show the dimensions of a model
Browse files Browse the repository at this point in the history
  • Loading branch information
jscastro76 committed Dec 20, 2020
1 parent 3541034 commit a041fea
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 10 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 2.1.6

Minor version by [@jscastro76](https://github.com/jscastro76), some enhancements and bugs.

#### :sparkles: Enhancements

- #111 Show the dimensions of a model
- #151 Remove auxiliary test method on CameraSync used to debug #145

<br>

- - -

## 2.1.5

Minor version by [@jscastro76](https://github.com/jscastro76), some enhancements and bugs.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v.2.0.1 - v.2.1.5
v.2.0.1 - v.2.1.6
MIT License
Copyright (c) 2020 Jesus Serrano

Expand Down
43 changes: 42 additions & 1 deletion dist/threebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,44 @@ Threebox.prototype = {
this.tb.zoomLayers.forEach((l) => {this.tb.toggleLayer(l);});
}

let ctrlDown = false;
let shiftDown = false;
let ctrlKey = 17, cmdKey = 91, shiftKey = 16, sK = 83; dK = 68;

function onKeyDown(e) {

if (e.which === ctrlKey || e.which === cmdKey) ctrlDown = true;
if (e.which === shiftKey) shiftDown = true;
let obj = this.selectedObject;
if (shiftDown && e.which === sK && obj) {
//shift + sS
let dc = utils.toDecimal;
if (!obj.help) {
let s = obj.modelSize;
let sf = 1;
if (obj.userData.units !== 'meters') {
//if not meters, calculate scale to the current lat
sf = utils.projectedUnitsPerMeter(obj.coordinates[1]);
if (!sf) { sf = 1; };
sf = dc(sf, 7);
}

obj.addHelp("size(m): " + dc((s.x / sf), 3) + " W, " + dc((s.y / sf), 3) + " L, " + dc((s.z / sf), 3) + " H");
this.repaint = true;
}
else {
obj.removeHelp();
}
return false;
}

};

function onKeyUp (e) {
if (e.which == ctrlKey || e.which == cmdKey) ctrlDown = false;
if (e.which === shiftKey) shiftDown = false;
}

//listener to the events
//this.on('contextmenu', map.onContextMenu);
this.on('click', this.onClick);
Expand All @@ -493,6 +531,9 @@ Threebox.prototype = {
this.on('mousedown', this.onMouseDown);
this.on('zoom', this.onZoomEnd);

document.addEventListener('keydown', onKeyDown.bind(this), true);
document.addEventListener('keyup', onKeyUp.bind(this));

});
},

Expand Down Expand Up @@ -16818,6 +16859,7 @@ Objects.prototype = {
obj.remove(obj.boxGroup);
}
if (obj.label && !obj.label.alwaysVisible) obj.label.visible = false;
obj.removeHelp();
}
if (obj.tooltip) obj.tooltip.visible = value;
//only fire the event if value is different
Expand Down Expand Up @@ -16928,7 +16970,6 @@ Objects.prototype = {
Object.defineProperty(obj, 'modelSize', {
get() {
_modelSize = obj.getSize();
//console.log(_modelSize);
return _modelSize;
},
set(value) {
Expand Down
4 changes: 2 additions & 2 deletions dist/threebox.min.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions examples/13-eiffel.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@
let date = new Date();
let mapConfig = {
// ALL: { center: [-100.021884, 39.609738, 0], zoom: 3.25, pitch: 12, bearing: 0, timezone: 'US/Central' },
NYC: { origin: [-74.044514, 40.689259, 47], center: [-74.044803, 40.690183, 0], zoom: 17.7, pitch: 60, bearing: -10, scale: 44, timezone: 'America/New_York' },
PAR: { origin: [2.294514, 48.857475, 0], center: [2.294625, 48.861085, 0], zoom: 15.95, pitch: 60, bearing: 0, scale: 0.01029, timezone: 'Europe/Paris' },
NYC: {
origin: [-74.044514, 40.689259, 47], center: [-74.044803, 40.690183, 0], zoom: 17.7, pitch: 60, bearing: -10, scale: { x: 44, y: 44, z: 44 }, timezone: 'America/New_York' },
PAR: {
origin: [2.294514, 48.857475, 0], center: [2.294625, 48.861085, 0], zoom: 15.95, pitch: 60, bearing: 0, scale: { x: 0.01039565, y: 0.01039565, z: 0.00997 }, timezone: 'Europe/Paris' },
names: {
customLayer: "custom-layer",
fillExtrusion: "composite-b",
fillExtrusionLayer: "building-b"
}
}
let point = mapConfig.PAR;
let point = mapConfig.NYC;
let p = document.querySelector("#hour");

let styles = {
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": "threebox-plugin",
"version": "2.1.5",
"version": "2.1.6",
"description": "A Three.js plugin for Mapbox GL JS, using the CustomLayerInterface feature. Provides convenient methods to manage objects in lnglat coordinates, and to synchronize the map and scene cameras.",
"main": "main.js",
"repository": {
Expand Down
41 changes: 41 additions & 0 deletions src/Threebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,44 @@ Threebox.prototype = {
this.tb.zoomLayers.forEach((l) => {this.tb.toggleLayer(l);});
}

let ctrlDown = false;
let shiftDown = false;
let ctrlKey = 17, cmdKey = 91, shiftKey = 16, sK = 83; dK = 68;

function onKeyDown(e) {

if (e.which === ctrlKey || e.which === cmdKey) ctrlDown = true;
if (e.which === shiftKey) shiftDown = true;
let obj = this.selectedObject;
if (shiftDown && e.which === sK && obj) {
//shift + sS
let dc = utils.toDecimal;
if (!obj.help) {
let s = obj.modelSize;
let sf = 1;
if (obj.userData.units !== 'meters') {
//if not meters, calculate scale to the current lat
sf = utils.projectedUnitsPerMeter(obj.coordinates[1]);
if (!sf) { sf = 1; };
sf = dc(sf, 7);
}

obj.addHelp("size(m): " + dc((s.x / sf), 3) + " W, " + dc((s.y / sf), 3) + " L, " + dc((s.z / sf), 3) + " H");
this.repaint = true;
}
else {
obj.removeHelp();
}
return false;
}

};

function onKeyUp (e) {
if (e.which == ctrlKey || e.which == cmdKey) ctrlDown = false;
if (e.which === shiftKey) shiftDown = false;
}

//listener to the events
//this.on('contextmenu', map.onContextMenu);
this.on('click', this.onClick);
Expand All @@ -488,6 +526,9 @@ Threebox.prototype = {
this.on('mousedown', this.onMouseDown);
this.on('zoom', this.onZoomEnd);

document.addEventListener('keydown', onKeyDown.bind(this), true);
document.addEventListener('keyup', onKeyUp.bind(this));

});
},

Expand Down
2 changes: 1 addition & 1 deletion src/objects/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ Objects.prototype = {
obj.remove(obj.boxGroup);
}
if (obj.label && !obj.label.alwaysVisible) obj.label.visible = false;
obj.removeHelp();
}
if (obj.tooltip) obj.tooltip.visible = value;
//only fire the event if value is different
Expand Down Expand Up @@ -685,7 +686,6 @@ Objects.prototype = {
Object.defineProperty(obj, 'modelSize', {
get() {
_modelSize = obj.getSize();
//console.log(_modelSize);
return _modelSize;
},
set(value) {
Expand Down
43 changes: 42 additions & 1 deletion tests/threebox-tests-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9423,6 +9423,44 @@ Threebox.prototype = {
this.tb.zoomLayers.forEach((l) => {this.tb.toggleLayer(l);});
}

let ctrlDown = false;
let shiftDown = false;
let ctrlKey = 17, cmdKey = 91, shiftKey = 16, sK = 83; dK = 68;

function onKeyDown(e) {

if (e.which === ctrlKey || e.which === cmdKey) ctrlDown = true;
if (e.which === shiftKey) shiftDown = true;
let obj = this.selectedObject;
if (shiftDown && e.which === sK && obj) {
//shift + sS
let dc = utils.toDecimal;
if (!obj.help) {
let s = obj.modelSize;
let sf = 1;
if (obj.userData.units !== 'meters') {
//if not meters, calculate scale to the current lat
sf = utils.projectedUnitsPerMeter(obj.coordinates[1]);
if (!sf) { sf = 1; };
sf = dc(sf, 7);
}

obj.addHelp("size(m): " + dc((s.x / sf), 3) + " W, " + dc((s.y / sf), 3) + " L, " + dc((s.z / sf), 3) + " H");
this.repaint = true;
}
else {
obj.removeHelp();
}
return false;
}

};

function onKeyUp (e) {
if (e.which == ctrlKey || e.which == cmdKey) ctrlDown = false;
if (e.which === shiftKey) shiftDown = false;
}

//listener to the events
//this.on('contextmenu', map.onContextMenu);
this.on('click', this.onClick);
Expand All @@ -9431,6 +9469,9 @@ Threebox.prototype = {
this.on('mousedown', this.onMouseDown);
this.on('zoom', this.onZoomEnd);

document.addEventListener('keydown', onKeyDown.bind(this), true);
document.addEventListener('keyup', onKeyUp.bind(this));

});
},

Expand Down Expand Up @@ -25756,6 +25797,7 @@ Objects.prototype = {
obj.remove(obj.boxGroup);
}
if (obj.label && !obj.label.alwaysVisible) obj.label.visible = false;
obj.removeHelp();
}
if (obj.tooltip) obj.tooltip.visible = value;
//only fire the event if value is different
Expand Down Expand Up @@ -25866,7 +25908,6 @@ Objects.prototype = {
Object.defineProperty(obj, 'modelSize', {
get() {
_modelSize = obj.getSize();
//console.log(_modelSize);
return _modelSize;
},
set(value) {
Expand Down

0 comments on commit a041fea

Please sign in to comment.