Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(all): update panScale for panning sensitivity when size is changed. #209

Merged
merged 8 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/PanoViewer/PanoViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,28 @@ export default class PanoViewer extends Component {
if (!this._isReady) {
return this;
}
this._width = (size && size.width) ||
parseInt(window.getComputedStyle(this._container).width, 10);
this._height = (size && size.height) ||
parseInt(window.getComputedStyle(this._container).height, 10);
this._aspectRatio = this._width / this._height;
this._photoSphereRenderer.updateViewportDimensions(this._width, this._height);

let containerSize;

if (!size !== undefined || size.width !== undefined || size.height !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that updateViewportDimensions can make simple using destructuring assignment.
How about it?

updateViewportDimensions(size={width:undefined, height:undefined}) {
	if (!this._isReady) {
		return this;
	}

	let containerSize;
	let [width, height] = size;

	if (width !== undefined || height !== undefined) {
		containerSize = window.getComputedStyle(this._container);
		width = parseInt(containerSize.width, 10);
		height = parseInt(containerSize.height, 10);
	}

	// Skip if viewport is not changed.
	if (width === this._width && height === this._height) {
		return this;
	}

	this._width = width;
	this._height = height;

	this._aspectRatio = width / height;
	this._photoSphereRenderer.updateViewportDimensions(width, height);
	this._yawPitchControl.option("aspectRatio", this._aspectRatio);
	this._yawPitchControl.updatePanScale({height});

	this.lookAt({}, 0);
	return this;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mixed Thank you for suggestion. That makes code more neat!
I'll apply it except the some logical part. Because there's some difference that I've intended.

containerSize = window.getComputedStyle(this._container);
}

const w = (size && size.width) || parseInt(containerSize.width, 10);
const h = (size && size.height) || parseInt(containerSize.height, 10);

// Skip if viewport is not changed.
if (w === this._width && h === this._height) {
return this;
}

this._width = w;
this._height = h;

this._aspectRatio = w / h;
this._photoSphereRenderer.updateViewportDimensions(w, h);
this._yawPitchControl.option("aspectRatio", this._aspectRatio);
this._yawPitchControl.updatePanScale({height: h});

this.lookAt({}, 0);
return this;
Expand Down
26 changes: 22 additions & 4 deletions src/YawPitchControl/YawPitchControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ const YawPitchControl = class YawPitchControl extends Component {
},
change: evt => {
if (evt.delta.fov !== 0) {
this._setPanScale(evt.pos.fov);
this._updateControlScale(evt);
this.updatePanScale();
}
this._triggerChange(evt);
},
Expand All @@ -140,12 +140,23 @@ const YawPitchControl = class YawPitchControl extends Component {
});
}

_setPanScale(fov) {
const areaHeight = parseInt(getComputedStyle(this._element).height, 10);
/**
* Update Pan Scale
*
* Scale(Sensitivity) values of panning is related with fov and height.
* If at least one of them is changed, this function need to be called.
* @param {*} param0
*/
updatePanScale(param) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

updatePanScale(param={}){
   const areaHeight = param.height || parseInt(getComputedStyle(this._element).height, 10);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mixed I'll apply it! Thank you 👍

const fov = this.axes.get().fov;
const areaHeight =
(param && param.height) || parseInt(getComputedStyle(this._element).height, 10);
const scale = MC_BIND_SCALE[0] * fov / this._initialFov * PAN_SCALE / areaHeight;

this.axesPanInput.options.scale = [scale, scale];
this.axes.options.deceleration = MC_DECELERATION * fov / MAX_FIELD_OF_VIEW;

return this;
}

/*
Expand Down Expand Up @@ -217,6 +228,11 @@ const YawPitchControl = class YawPitchControl extends Component {
key === "yawRange" || key === "pitchRange"
)) {
this._updateControlScale();

// If fov is changed, update pan scale
if (keys.indexOf("fov") >= 0) {
this.updatePanScale();
}
}

if (keys.some(key => key === "fovRange")) {
Expand All @@ -237,6 +253,7 @@ const YawPitchControl = class YawPitchControl extends Component {
fov: nextFov
}, 0);
this._updateControlScale();
this.updatePanScale();
}
}

Expand Down Expand Up @@ -540,7 +557,8 @@ const YawPitchControl = class YawPitchControl extends Component {
// touchDirection is decided by parameter is valid string (Ref. Axes.connect)
this._applyOptions(Object.keys(this.options), this.options);

this._setPanScale(this.getFov());
// TODO: Is this code is needed? Check later.
this.updatePanScale();

return this;
}
Expand Down
96 changes: 96 additions & 0 deletions test/manual/PanoViewer/FullScreen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>FullScreen Example</title>
<meta name="description" content="PanoViewer">
<meta name="author" content="egjs">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<link rel="stylesheet" href="../css/semantic.min.css">
<style>
#panoviewer-showcase {
position: relative;
width: 100%;
height: 320px;
margin: 0 auto;
}

#panoviewer-showcase.fullscreen {
width: 100%;
height: 100%;
}

#fullscreen-toggle {
position: absolute;
top: 10px;
right: 10px;
z-index: 2;
}

#fullscreen-container {
position: absolute;
display: none;
left:0;
top:0;
width: 100%;
height: 100%;
}

#fullscreen-container.activate {
display: block;
background-color:white;
}
</style>
</head>
<body>
<div class="ui menu">
<div class="ui container">
<div class="header item">
PanoViewer
</div>
</div>
</div>

<div class="ui main text container">
<h1 class="ui header">Full Screen</h1>

<div class="ui segment">
<button id="fullscreen-toggle" class="ui icon button">
<i class="expand icon"></i>
</button>
<div id="panoviewer-showcase"></div>
</div>
</div>
<div id="fullscreen-container"></div>

<!--To use semantic-ui-->
<script src="../lib/jquery-3.3.1.min.js"></script>
<script src="../lib/semantic.min.js"></script>
<script src="../../../node_modules/hammerjs/hammer.js"></script>
<script src="../../../node_modules/@egjs/component/dist/component.js"></script>
<script src="../../../node_modules/@egjs/axes/dist/axes.js"></script>
<script src="../../../dist/view360.js"></script>
<script src="../js/FullScreen.js"></script>
<script>
var isFullScreen = false;
var container = document.getElementById("panoviewer-showcase");

var PanoViewer = eg.view360.PanoViewer;
var panoViewer = new PanoViewer(container, {
yaw: 180,
image: "../img/test_equi_4096.jpg"
});

document.getElementById("fullscreen-toggle").addEventListener("click", function() {
isFullScreen = !isFullScreen;
isFullScreen ? FullScreen.request() : FullScreen.exit();

panoViewer.updateViewportDimensions();
});

window.addEventListener("resize", function() {
panoViewer.updateViewportDimensions();
});
</script>
</body>
</html>
364 changes: 364 additions & 0 deletions test/manual/css/semantic.min.css

Large diffs are not rendered by default.

Binary file not shown.
1,008 changes: 1,008 additions & 0 deletions test/manual/css/themes/default/assets/fonts/brand-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading