pchen66 / panolens.js

Javascript panorama viewer based on Three.js
https://pchen66.github.io/Panolens/
MIT License
2.79k stars 498 forks source link

Is there any way to add info spot dynamically by click user ? #398

Open soheilhasanjani opened 2 years ago

soheilhasanjani commented 2 years ago

Hi , Is there any way to add info spot dynamically by click user ? for example , add event Listener for click , when user click any where , get me x, y ,z and i create a new info spot with this detail and add to panorama . please give me solution .

JoseManuelFV commented 1 year ago

Yes, you can use addEventListener to listen left click, and if you like control right click use contextmenu event

And for get actual position i use raycaster:

//Raycaster
viewer.raycaster.intersectObject(viewer.panorama, true);
clickPosition = intersectObjs[0].point;

//If you like check if exist infospot in same position
isInfospot = intersectObjs.filter(e=>e.object.type == "infospot");

// add you hostpot
infospot = new this.PANOLENS.Infospot();
// x position is inverted, i don't know why, but that's how it is
infospot.position.set( clickPosition.x * -1, clickPosition.y, clickPosition.z );
viewer.panorama.add(infospot);
viewer.paronama.toggleInfospotVisibility(true);
hungvo2010 commented 1 year ago

https://codepen.io/pchen66/pen/MWmqYVN