Skip to content

Commit

Permalink
Added onPositionChange Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
markpenaranda committed Mar 10, 2020
1 parent ea3d33b commit 68f83fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class App extends Component {
render () {
return (
<div>
<ReactPhotoSphereViewer height="500" src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQNfXFNW1ti-GCNgWuc6rFhdtClHTpnxsx3pd9LYBMyUN_wJXt2"/>
<ReactPhotoSphereViewer height="500" timeAnim={false} src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQNfXFNW1ti-GCNgWuc6rFhdtClHTpnxsx3pd9LYBMyUN_wJXt2"/>
</div>
)
}
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": "react-photosphere",
"version": "1.0.0",
"version": "1.0.2",
"description": "Photosphere Viewer for React.JS",
"author": "markpenaranda",
"license": "MIT",
Expand Down
20 changes: 15 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export interface Props {
navbar?: string[];
height: number;
width?: number;

timeAnim: number | boolean;
onPositionChange?(lat: number , lng: number): any;
}

const defaultNavbar = [
Expand All @@ -21,24 +22,33 @@ const defaultNavbar = [
'fullscreen'
];

export default function ReactPhotoSphereViewer ({ src, navbar, height, width }: Props): React.ReactElement {
export default function ReactPhotoSphereViewer ({ src, navbar, height, width, timeAnim, onPositionChange }: Props): React.ReactElement {
navbar = (navbar && navbar.length > 0) ? navbar : defaultNavbar;
const sphereElementRef = React.createRef<HTMLDivElement>();
React.useEffect(() => {

const shperePlayerInstance = PhotoSphereViewer({
const spherePlayerInstance = PhotoSphereViewer({
container: sphereElementRef.current,
panorama: src,
size: {
height,
width
},
navbar: navbar
navbar: navbar,
time_anim: timeAnim,
});

spherePlayerInstance.on('position-updated', () => {

if(onPositionChange) {
const position = spherePlayerInstance.getPosition();
onPositionChange(position.lat, position.lng)
}

});

return () => {
shperePlayerInstance.destroy();
spherePlayerInstance.destroy();
};
}, [src]);
return (
Expand Down

0 comments on commit 68f83fc

Please sign in to comment.