Skip to content

Commit

Permalink
Fix click positions, fix tooltip position
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Apr 24, 2016
1 parent 81657fd commit fb721a9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 31 deletions.
26 changes: 14 additions & 12 deletions dist/photo-sphere-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ function PhotoSphereViewer(options) {
autorotate_reqid: null, // animationRequest id of the automatic rotation
animation_promise: null, // promise of the current animation (either go to position or image transition)
start_timeout: null, // timeout id of the automatic rotation delay
boundingRect: null, // DOMRect of the container
size: { // size of the container
width: 0,
height: 0
Expand Down Expand Up @@ -771,7 +770,7 @@ PhotoSphereViewer.DEFAULTS = {
keyboard: true,
gyroscope: false,
move_inertia: true,
click_event_on_marker: true,
click_event_on_marker: false,
transition: {
duration: 1500,
loader: true,
Expand Down Expand Up @@ -867,7 +866,6 @@ PhotoSphereViewer.prototype._onResize = function() {
this.prop.size.width = parseInt(this.container.clientWidth);
this.prop.size.height = parseInt(this.container.clientHeight);
this.prop.aspect = this.prop.size.width / this.prop.size.height;
this.prop.boundingRect = this.container.getBoundingClientRect();

if (this.renderer) {
this.renderer.setSize(this.prop.size.width, this.prop.size.height);
Expand Down Expand Up @@ -1061,12 +1059,14 @@ PhotoSphereViewer.prototype._stopMoveInertia = function(evt) {
* @private
*/
PhotoSphereViewer.prototype._click = function(evt) {
var boundingRect = this.container.getBoundingClientRect();

var data = {
target: evt.target,
client_x: evt.clientX,
client_y: evt.clientY,
viewer_x: parseInt(evt.clientX - this.prop.boundingRect.left),
viewer_y: parseInt(evt.clientY - this.prop.boundingRect.top)
viewer_x: parseInt(evt.clientX - boundingRect.left),
viewer_y: parseInt(evt.clientY - boundingRect.top)
};

var intersect = this.viewerCoordsToVector3(data.viewer_x, data.viewer_y);
Expand Down Expand Up @@ -2456,12 +2456,14 @@ PSVHUD.prototype._onMouseMove = function(e) {

this.hoveringMarker = marker;

var boundingRect = this.psv.container.getBoundingClientRect();

// simulate a marker with the size of the tooltip arrow to separate it from the cursor
this.psv.tooltip.showTooltip({
content: marker.tooltip.content,
position: marker.tooltip.position,
top: e.clientY - this.psv.prop.boundingRect.top - this.psv.config.tooltip.arrow_size,
left: e.clientX - this.psv.prop.boundingRect.left - this.psv.config.tooltip.arrow_size,
top: e.clientY - boundingRect.top - this.psv.config.tooltip.arrow_size / 2,
left: e.clientX - boundingRect.left - this.psv.config.tooltip.arrow_size,
marker: {
width: this.psv.config.tooltip.arrow_size * 2,
height: this.psv.config.tooltip.arrow_size * 2
Expand Down Expand Up @@ -2495,8 +2497,8 @@ PSVHUD.prototype._onClick = function(data, e) {
}
}
else if (this.currentMarker) {
this.psv.trigger('unselect-marker', this.currentMarker);
this.currentMarker = null;
this.psv.trigger('unselect-marker');
}

if (marker && marker.psvMarker && marker.psvMarker.content) {
Expand Down Expand Up @@ -3655,8 +3657,8 @@ PSVTooltip.prototype._computeTooltipPosition = function(style, config) {
switch (style.posClass[1]) {
case 'right':
if (topBottom) {
style.left = config.left;
style.arrow_left = config.marker.width / 2 - this.config.arrow_size;
style.left = config.left + config.marker.width / 2 - this.config.offset - this.config.arrow_size;
style.arrow_left = this.config.offset;
}
else {
style.left = config.left + config.marker.width + this.config.offset + this.config.arrow_size;
Expand All @@ -3671,8 +3673,8 @@ PSVTooltip.prototype._computeTooltipPosition = function(style, config) {

case 'left':
if (topBottom) {
style.left = config.left - style.width + config.marker.width;
style.arrow_left = style.width - config.marker.width / 2 - this.config.arrow_size;
style.left = config.left - style.width + config.marker.width / 2 + this.config.offset + this.config.arrow_size;
style.arrow_left = style.width - this.config.offset - this.config.arrow_size * 2;
}
else {
style.left = config.left - style.width - this.config.offset - this.config.arrow_size;
Expand Down
4 changes: 2 additions & 2 deletions dist/photo-sphere-viewer.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions example/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ <h3>Header Level 3</h3>
id: 'polygon',
content: 'This mountain is so great it has dots on it!',
polygon_px: [3184,794,3268,841,3367,1194,3327,1307,3065,1221,3097,847],
style: {
svgStyle: {
fill: 'url(#points)', //'rgba(255,0,0,0.3)',
stroke: 'rgba(255, 0, 50, 0.8)',
'stroke-width': '2px'
Expand All @@ -222,7 +222,7 @@ <h3>Header Level 3</h3>
id: 'circle',
tooltip: 'A circle of radius 30',
circle: 30,
style: {
svgStyle: {
fill: 'rgba(255,255,0,0.3)',
stroke: 'yellow',
'stroke-width': '2px'
Expand All @@ -236,7 +236,7 @@ <h3>Header Level 3</h3>
id: 'ellipse',
tooltip: 'An ellipse of radius 60/30',
ellipse: [60, 30],
style: {
svgStyle: {
fill: 'rgba(255,255,0,0.3)',
stroke: 'yellow',
'stroke-width': '2px'
Expand All @@ -250,7 +250,7 @@ <h3>Header Level 3</h3>
id: 'rect',
tooltip: 'A square a side 60',
rect: [60, 60],
style: {
svgStyle: {
fill: 'rgba(255,255,0,0.3)',
stroke: 'yellow',
'stroke-width': '2px'
Expand All @@ -264,7 +264,7 @@ <h3>Header Level 3</h3>
id: 'path',
tooltip: 'A custom path',
path: 'M 0 0 L 60 60 L 60 0 L 0 60 L 0 0',
style: {
svgStyle: {
fill: 'rgba(255,255,0,0.3)',
stroke: 'yellow',
'stroke-width': '2px'
Expand Down
2 changes: 1 addition & 1 deletion src/js/PhotoSphereViewer.defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ PhotoSphereViewer.DEFAULTS = {
keyboard: true,
gyroscope: false,
move_inertia: true,
click_event_on_marker: true,
click_event_on_marker: false,
transition: {
duration: 1500,
loader: true,
Expand Down
7 changes: 4 additions & 3 deletions src/js/PhotoSphereViewer.events.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ PhotoSphereViewer.prototype._onResize = function() {
this.prop.size.width = parseInt(this.container.clientWidth);
this.prop.size.height = parseInt(this.container.clientHeight);
this.prop.aspect = this.prop.size.width / this.prop.size.height;
this.prop.boundingRect = this.container.getBoundingClientRect();

if (this.renderer) {
this.renderer.setSize(this.prop.size.width, this.prop.size.height);
Expand Down Expand Up @@ -255,12 +254,14 @@ PhotoSphereViewer.prototype._stopMoveInertia = function(evt) {
* @private
*/
PhotoSphereViewer.prototype._click = function(evt) {
var boundingRect = this.container.getBoundingClientRect();

var data = {
target: evt.target,
client_x: evt.clientX,
client_y: evt.clientY,
viewer_x: parseInt(evt.clientX - this.prop.boundingRect.left),
viewer_y: parseInt(evt.clientY - this.prop.boundingRect.top)
viewer_x: parseInt(evt.clientX - boundingRect.left),
viewer_y: parseInt(evt.clientY - boundingRect.top)
};

var intersect = this.viewerCoordsToVector3(data.viewer_x, data.viewer_y);
Expand Down
1 change: 0 additions & 1 deletion src/js/PhotoSphereViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ function PhotoSphereViewer(options) {
autorotate_reqid: null, // animationRequest id of the automatic rotation
animation_promise: null, // promise of the current animation (either go to position or image transition)
start_timeout: null, // timeout id of the automatic rotation delay
boundingRect: null, // DOMRect of the container
size: { // size of the container
width: 0,
height: 0
Expand Down
8 changes: 5 additions & 3 deletions src/js/components/PSVHUD.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,14 @@ PSVHUD.prototype._onMouseMove = function(e) {

this.hoveringMarker = marker;

var boundingRect = this.psv.container.getBoundingClientRect();

// simulate a marker with the size of the tooltip arrow to separate it from the cursor
this.psv.tooltip.showTooltip({
content: marker.tooltip.content,
position: marker.tooltip.position,
top: e.clientY - this.psv.prop.boundingRect.top - this.psv.config.tooltip.arrow_size,
left: e.clientX - this.psv.prop.boundingRect.left - this.psv.config.tooltip.arrow_size,
top: e.clientY - boundingRect.top - this.psv.config.tooltip.arrow_size / 2,
left: e.clientX - boundingRect.left - this.psv.config.tooltip.arrow_size,
marker: {
width: this.psv.config.tooltip.arrow_size * 2,
height: this.psv.config.tooltip.arrow_size * 2
Expand Down Expand Up @@ -483,8 +485,8 @@ PSVHUD.prototype._onClick = function(data, e) {
}
}
else if (this.currentMarker) {
this.psv.trigger('unselect-marker', this.currentMarker);
this.currentMarker = null;
this.psv.trigger('unselect-marker');
}

if (marker && marker.psvMarker && marker.psvMarker.content) {
Expand Down
8 changes: 4 additions & 4 deletions src/js/components/PSVTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ PSVTooltip.prototype._computeTooltipPosition = function(style, config) {
switch (style.posClass[1]) {
case 'right':
if (topBottom) {
style.left = config.left;
style.arrow_left = config.marker.width / 2 - this.config.arrow_size;
style.left = config.left + config.marker.width / 2 - this.config.offset - this.config.arrow_size;
style.arrow_left = this.config.offset;
}
else {
style.left = config.left + config.marker.width + this.config.offset + this.config.arrow_size;
Expand All @@ -262,8 +262,8 @@ PSVTooltip.prototype._computeTooltipPosition = function(style, config) {

case 'left':
if (topBottom) {
style.left = config.left - style.width + config.marker.width;
style.arrow_left = style.width - config.marker.width / 2 - this.config.arrow_size;
style.left = config.left - style.width + config.marker.width / 2 + this.config.offset + this.config.arrow_size;
style.arrow_left = style.width - this.config.offset - this.config.arrow_size * 2;
}
else {
style.left = config.left - style.width - this.config.offset - this.config.arrow_size;
Expand Down

0 comments on commit fb721a9

Please sign in to comment.