├── .eslintrc.cjs ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yaml │ ├── feature_request.yaml │ └── support_request.yaml └── workflows │ └── release.yml ├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── example ├── generic │ ├── .gitignore │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── Test_Pano.jpg │ │ ├── drone.png │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── logo192.png │ │ ├── logo512.png │ │ ├── manifest.json │ │ ├── pin-blue.png │ │ ├── pin-red.png │ │ └── robots.txt │ └── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ ├── reportWebVitals.js │ │ └── setupTests.js └── virtualtour │ ├── package-lock.json │ ├── package.json │ ├── public │ ├── Test_Pano.jpg │ ├── drone.png │ ├── index.html │ ├── pin-blue.png │ └── pin-red.png │ └── src │ ├── App.js │ ├── index.css │ ├── index.js │ ├── reportWebVitals.js │ └── setupTests.js ├── package-lock.json ├── package.json ├── rollup.config.js ├── src ├── index.d.ts ├── index.tsx ├── styles.css └── test.ts └── tsconfig.json /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "env": { 3 | "es2020": true 4 | }, 5 | "root": true, 6 | "parser": "@typescript-eslint/parser", 7 | "plugins": [ 8 | "@typescript-eslint" 9 | ], 10 | "extends": [ 11 | "eslint:recommended", 12 | "plugin:@typescript-eslint/eslint-recommended", 13 | "plugin:@typescript-eslint/recommended" 14 | ], 15 | "parserOptions": { 16 | "ecmaVersion": "latest", 17 | "sourceType": "module" 18 | }, 19 | "rules": { 20 | "indent": [ 21 | "error", 22 | 4 23 | ], 24 | "linebreak-style": [ 25 | "error", 26 | "windows" 27 | ], 28 | "quotes": [ 29 | "error", 30 | "double" 31 | ], 32 | "semi": [ 33 | "error", 34 | "never" 35 | ], 36 | "@typescript-eslint/ban-ts-comment": [ 37 | "error", 38 | { 39 | "ts-ignore": "allow-with-description" 40 | } 41 | ] 42 | }, 43 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yaml: -------------------------------------------------------------------------------- 1 | name: 🐞 Bug Report 2 | description: File a bug report 3 | title: "[Bug]: " 4 | labels: ["bug", "triage"] 5 | assignees: 6 | - Elius94 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | Thanks for taking the time to fill out this bug report! 12 | - type: textarea 13 | id: what-happened 14 | attributes: 15 | label: What happened? 16 | description: Tell us, what did you expect to happen? 17 | placeholder: Tell us what you see! 18 | value: "A bug happened!" 19 | validations: 20 | required: true 21 | - type: textarea 22 | id: what-should-happen 23 | attributes: 24 | label: What should have happened? 25 | description: Tell us, what did you expect to happen? 26 | placeholder: Tell us what you expected! 27 | value: "A bug happened!" 28 | validations: 29 | required: true 30 | - type: textarea 31 | id: code 32 | attributes: 33 | label: Code 34 | description: Please provide a code that you are trying to run 35 | placeholder: | 36 | ```js 37 | // Your code here 38 | ``` 39 | validations: 40 | required: false 41 | - type: textarea 42 | id: sandbox-link 43 | attributes: 44 | label: Sandbox Link 45 | description: Please provide a link to a sandbox that reproduces the issue 46 | placeholder: https://codesandbox.io/s/... 47 | validations: 48 | required: false 49 | - type: textarea 50 | id: version 51 | attributes: 52 | label: Library Version 53 | description: What version of the lib are you using? 54 | placeholder: "latest" 55 | validations: 56 | required: true 57 | - type: dropdown 58 | id: os 59 | attributes: 60 | label: What operating system are you using? 61 | options: 62 | - Windows 63 | - macOS 64 | - Ubuntu 65 | - Other Linux 66 | - Other 67 | validations: 68 | required: true 69 | - type: dropdown 70 | id: browser 71 | attributes: 72 | label: What browser are you using? 73 | options: 74 | - Chrome 75 | - Firefox 76 | - Safari 77 | - Edge 78 | - Other 79 | - type: textarea 80 | id: logs 81 | attributes: 82 | label: Logs 83 | description: Please provide logs 84 | placeholder: | 85 | ```log 86 | // Your logs here 87 | ``` 88 | validations: 89 | required: false 90 | - type: checkboxes 91 | id: terms 92 | attributes: 93 | label: Interest to fix the bug 94 | description: Are you interested in fixing this bug? 95 | options: 96 | - label: I would like to fix this bug! 97 | required: false -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yaml: -------------------------------------------------------------------------------- 1 | name: 🚀 Feature Request 2 | description: Suggest an idea for this project 3 | title: "[Feature]: " 4 | labels: ["enhancement", "triage"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to suggest a new feature! 10 | - type: textarea 11 | id: what-do-you-want 12 | attributes: 13 | label: What do you want? 14 | description: Tell us, what do you want to happen? 15 | placeholder: Tell us what you want! 16 | value: "A new feature!" 17 | validations: 18 | required: true 19 | - type: textarea 20 | id: why-do-you-want 21 | attributes: 22 | label: Why do you want it? 23 | description: Tell us, why do you want this feature? 24 | placeholder: Tell us why you want this feature! 25 | value: "A new feature!" 26 | validations: 27 | required: true 28 | - type: textarea 29 | id: how-do-you-implement-it 30 | attributes: 31 | label: How do you implement it? 32 | description: Tell us, how do you want to implement this feature? 33 | placeholder: Tell us how you want to implement this feature! 34 | value: "A new feature!" 35 | validations: 36 | required: false 37 | - type: checkboxes 38 | id: interest-to-develop 39 | attributes: 40 | label: Are you interested in developing this feature? 41 | description: Tell us, if you are interested in developing this feature 42 | options: 43 | - label: Yes, I am interested in developing this feature 44 | - label: No, I am not interested in developing this feature -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/support_request.yaml: -------------------------------------------------------------------------------- 1 | name: 📖 Support Request 2 | description: Request support for this project 3 | title: "[Support]: " 4 | labels: ["question", "triage"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to request support for this project! 10 | - type: textarea 11 | id: what-do-you-want 12 | attributes: 13 | label: What are you trying to do? 14 | description: Tell us, what do you want to happen? 15 | placeholder: Tell us what you want! 16 | value: "To get support!" 17 | validations: 18 | required: true 19 | - type: textarea 20 | id: code 21 | attributes: 22 | label: Code 23 | description: Please provide a code that you are trying to run 24 | placeholder: | 25 | ```js 26 | // Your code here 27 | ``` 28 | validations: 29 | required: false 30 | - type: textarea 31 | id: sandbox-link 32 | attributes: 33 | label: Sandbox Link 34 | description: Please provide a link to a sandbox that reproduces the issue 35 | placeholder: https://codesandbox.io/s/... 36 | validations: 37 | required: false 38 | - type: textarea 39 | id: version 40 | attributes: 41 | label: Library Version 42 | description: What version of the lib are you using? 43 | placeholder: "latest" 44 | validations: 45 | required: true 46 | - type: dropdown 47 | id: os 48 | attributes: 49 | label: What operating system are you using? 50 | options: 51 | - Windows 52 | - macOS 53 | - Ubuntu 54 | - Other Linux 55 | - Other 56 | validations: 57 | required: true 58 | - type: dropdown 59 | id: browser 60 | attributes: 61 | label: What browser are you using? 62 | options: 63 | - Chrome 64 | - Firefox 65 | - Safari 66 | - Edge 67 | - Other 68 | - type: textarea 69 | id: logs 70 | attributes: 71 | label: Logs 72 | description: Please provide logs 73 | placeholder: | 74 | ```log 75 | // Your logs here 76 | ``` 77 | validations: 78 | required: false -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release Package 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | 7 | jobs: 8 | test: 9 | runs-on: ${{ matrix.os }} 10 | strategy: 11 | fail-fast: false 12 | matrix: 13 | node: [18, 20] 14 | os: [ubuntu-latest, windows-latest] 15 | 16 | steps: 17 | - name: Check out Git repository 18 | uses: actions/checkout@v2 19 | 20 | - name: Install Node.js, NPM and Yarn 21 | uses: actions/setup-node@v2 22 | with: 23 | node-version: ${{ matrix.node }} 24 | registry-url: "https://registry.npmjs.org" 25 | 26 | - name: Run ci 27 | run: npm ci 28 | 29 | release: 30 | runs-on: windows-latest 31 | needs: test 32 | steps: 33 | - name: Release 34 | uses: softprops/action-gh-release@v1 35 | if: startsWith(github.ref, 'refs/tags/v') 36 | with: 37 | generate_release_notes: true 38 | 39 | publish: 40 | name: Release and NPM publish 41 | needs: release 42 | runs-on: ubuntu-latest 43 | steps: 44 | - name: Check out Git repository 45 | uses: actions/checkout@v2 46 | 47 | - name: Install Node.js, NPM and Yarn 48 | uses: actions/setup-node@v2 49 | with: 50 | node-version: 20 51 | registry-url: "https://registry.npmjs.org" 52 | 53 | - name: Run ci 54 | run: npm ci 55 | 56 | - id: check 57 | uses: EndBug/version-check@v1 58 | with: 59 | file-url: "https://unpkg.com/react-photo-sphere-viewer@latest/package.json" 60 | static-checking: localIsNew 61 | 62 | - name: Publish package to NPM 📦 63 | if: steps.check.outputs.changed == 'true' && startsWith(github.ref, 'refs/tags/v') 64 | run: npm publish 65 | 66 | env: 67 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # See https://help.github.com/ignore-files/ for more about ignoring files. 3 | 4 | # dependencies 5 | node_modules 6 | 7 | # builds 8 | build 9 | dist 10 | .rpt2_cache 11 | 12 | # misc 13 | .DS_Store 14 | .env 15 | .env.local 16 | .env.development.local 17 | .env.test.local 18 | .env.production.local 19 | 20 | npm-debug.log* 21 | yarn-debug.log* 22 | yarn-error.log* 23 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.codeActionsOnSave": { 3 | "source.fixAll.eslint": "explicit" 4 | }, 5 | "eslint.validate": [ 6 | "javascript" 7 | ], 8 | "cSpell.words": [ 9 | "Lensflare", 10 | "lensflares", 11 | "pano", 12 | "PANOS" 13 | ] 14 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Elia Lazzari 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-photo-sphere-viewer 2 | 3 | > Photosphere Viewer for React.JS 4 | 5 | ![Screenshot](https://user-images.githubusercontent.com/14907987/194562000-0411b51e-f017-468a-a51c-c6ce6df9b629.png) 6 | 7 | ```bash 8 | npm install @photo-sphere-viewer/core react-photo-sphere-viewer 9 | ``` 10 | 11 | > [!IMPORTANT] 12 | > Since [v5.0.0-psv5.7.1](https://github.com/Elius94/react-photo-sphere-viewer/releases/tag/v5.0.0-psv5.7.1), to use `` you have to manually install the JS library `@photo-sphere-viewer/core`. This is a breaking change. The library is not included in the package anymore. You can install it using the command `npm install @photo-sphere-viewer/core` or `yarn add @photo-sphere-viewer/core`. I decided to remove the library from the package to reduce the size of the package and to avoid the need to update the package every time the original library is updated. In particular, from now on, to use a plugin or an adapter, you need to import it directly from the package. For example, to use the `MarkersPlugin` you need to import it from the package `import { MarkersPlugin } from '@photo-sphere-viewer/markers-plugin'`. 13 | 14 | ## Library Version 15 | Original Wrapped Library: [PhotoSphereViewer](https://github.com/mistic100/Photo-Sphere-Viewer) used as Peer Dependency - Minimum Version: 5.13.1 [**NEW**] 16 | 17 | ## Description 18 | 19 | [![NPM](https://img.shields.io/npm/v/react-photo-sphere-viewer.svg)](https://www.npmjs.com/package/react-photo-sphere-viewer) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) 20 | 21 | [](https://user-images.githubusercontent.com/14907987/180258193-7d6179dc-64d7-4b08-9381-95e061c9ff79.mp4) 22 | 23 | This is a simple React component that allows you to display a 360° photo sphere. 24 | It is based on [PhotoSphereViewer](https://github.com/mistic100/Photo-Sphere-Viewer) by [Mistic100](https://github.com/mistic100). 25 | This component is a well managed wrapper around the original JS library. It is easy to use and has a lot of features. It is also easy to customize. It is also easy to extend. 26 | Addictional features are: 27 | 28 | - Little Planet Mode: display the panorama like a little planet (Similar to the DJI drones exported panoramas) 29 | 30 | ## Demo 31 | 32 | [Enjoy it in this sandbox](https://codesandbox.io/p/sandbox/react-photo-sphere-viewer-playground-zd8nt8) 33 | 34 | ## Usage 35 | 36 | ### Using React 37 | 38 | ```jsx 39 | import "./App.css"; 40 | import { ReactPhotoSphereViewer } from "react-photo-sphere-viewer"; 41 | import React from "react"; 42 | 43 | function App() { 44 | return ( 45 |
46 | 51 |
52 | ); 53 | } 54 | 55 | export default App; 56 | ``` 57 | 58 | ### Using Next.js 59 | 60 |
61 | With App Router 62 | 63 | ```jsx 64 | // # app/page.js 65 | 66 | "use client" 67 | 68 | import React from "react"; 69 | import { ReactPhotoSphereViewer } from "react-photo-sphere-viewer"; 70 | 71 | // Import plugins 72 | import { MarkersPlugin } from '@photo-sphere-viewer/markers-plugin'; 73 | import { CompassPlugin } from '@photo-sphere-viewer/compass-plugin'; 74 | 75 | // Import plugins stylesheets 76 | import '@photo-sphere-viewer/markers-plugin/index.css'; 77 | import '@photo-sphere-viewer/compass-plugin/index.css'; 78 | 79 | export default function Home() { 80 | const imgSrc = 'https://photo-sphere-viewer-data.netlify.app/assets/sphere.jpg' 81 | const plugins = [ 82 | [MarkersPlugin, 83 | { 84 | markers: [ 85 | { 86 | id: "image", 87 | position: { yaw: "0.33deg", pitch: "0.1deg" }, 88 | image: "vercel.svg", 89 | anchor: "bottom center", 90 | size: { width: 128, height: 128 }, 91 | tooltip: "Marker Tooltip Test", 92 | }, 93 | ], 94 | },], 95 | [CompassPlugin, { 96 | hotspots: [ 97 | { yaw: '0deg' }, 98 | { yaw: '90deg' }, 99 | { yaw: '180deg' }, 100 | { yaw: '270deg' }, 101 | ], 102 | }] 103 | ] 104 | 105 | return ( 106 |
107 | 112 |
113 | ); 114 | } 115 | 116 | ```` 117 |
118 | 119 |
120 | 121 | [Next DevBox Template](https://codesandbox.io/p/devbox/k6j6mk) 122 | 123 | > [!IMPORTANT] 124 | > To use `` in Next.js with [Page Router](https://nextjs.org/docs/pages), you'll need to use some work-arounds in order to import correctly the CSS modules. Otherwise you will encounter the `CSS Modules cannot be imported from within node_modules` error. See more [here](https://nextjs.org/docs/messages/css-npm). 125 | 126 |
127 | With Page Router 128 | 129 | 1. Install [`next-transpile-modules`](https://www.npmjs.com/package/next-transpile-modules) 130 | ```bash 131 | $ npm install --save-dev next-transpile-modules 132 | ```` 133 | 134 | 2. Update your `next.config.js` as shown below: 135 | 136 | ```js 137 | // # next.config.js 138 | 139 | const withTM = require("next-transpile-modules")([ 140 | // Add this 2 modules 141 | "@photo-sphere-viewer/core", 142 | "react-photo-sphere-viewer", 143 | ]); 144 | 145 | /** @type {import('next').NextConfig} */ 146 | const nextConfig = { 147 | reactStrictMode: true, 148 | }; 149 | module.exports = withTM(nextConfig); 150 | ``` 151 | 152 | 3. Import the CSS manually into `_app.js`: 153 | 154 | ```js 155 | // # pages/_app.js 156 | 157 | import "@/styles/globals.css"; 158 | 159 | // Import plugins stylesheets 160 | import "@photo-sphere-viewer/markers-plugin/index.css"; 161 | import "@photo-sphere-viewer/compass-plugin/index.css"; 162 | 163 | export default function App({ Component, pageProps }) { 164 | return ; 165 | } 166 | ``` 167 | 168 | 4. Import dynamicly `react-photo-sphere-viewer` and import the plugins manually: 169 | 170 | ```jsx 171 | // # pages/index.js 172 | 173 | import dynamic from "next/dynamic"; 174 | const ReactPhotoSphereViewer = dynamic( 175 | () => 176 | import("react-photo-sphere-viewer").then( 177 | (mod) => mod.ReactPhotoSphereViewer 178 | ), 179 | { 180 | ssr: false, 181 | } 182 | ); 183 | 184 | // Import plugins 185 | import { MarkersPlugin } from "@photo-sphere-viewer/markers-plugin"; 186 | import { CompassPlugin } from "@photo-sphere-viewer/compass-plugin"; 187 | 188 | export default function Home() { 189 | const imgSrc = 190 | "https://photo-sphere-viewer-data.netlify.app/assets/sphere.jpg"; 191 | const plugins = [ 192 | [ 193 | MarkersPlugin, 194 | { 195 | markers: [ 196 | { 197 | id: "image", 198 | position: { yaw: "0.33deg", pitch: "0.1deg" }, 199 | image: "vercel.svg", 200 | anchor: "bottom center", 201 | size: { width: 128, height: 128 }, 202 | tooltip: "Marker Tooltip Test", 203 | }, 204 | ], 205 | }, 206 | ], 207 | [ 208 | CompassPlugin, 209 | { 210 | hotspots: [ 211 | { yaw: "0deg" }, 212 | { yaw: "90deg" }, 213 | { yaw: "180deg" }, 214 | { yaw: "270deg" }, 215 | ], 216 | }, 217 | ], 218 | ]; 219 | 220 | return ( 221 |
222 | 228 |
229 | ); 230 | } 231 | ``` 232 | 233 |
234 | 235 | ## Little planet mode 236 | 237 | I've added this custom effect that allows you to display the panorama like a little planet. To enable it, you need to pass the `littlePlanet` prop to the component. 238 | 239 | ```jsx 240 | 246 | ``` 247 | 248 | The effect is this: 249 | 250 | [](https://user-images.githubusercontent.com/14907987/180257570-4070d0b4-b3d8-493d-8f23-efde84074573.mp4) 251 | 252 | ## Features 253 | 254 | ### options 255 | 256 | #### Standard props 257 | 258 | ```ts 259 | type standardProps = { 260 | src: string; // The URL of the panorama image. 261 | height: number; 262 | width?: number; 263 | containerClass?: string; // The class name of the div that wrap the component. 264 | littlePlanet?: boolean; // Display the panorama like a little planet. 265 | hideNavbarButton?: boolean; // Hide the navbar button. 266 | }; 267 | ``` 268 | 269 | #### Original props 270 | 271 | Currently all options of the original library are supported and exported as props. 272 | 273 | ```ts 274 | /** 275 | * Viewer configuration 276 | * @link https://photo-sphere-viewer.js.org/guide/config.html 277 | */ 278 | type ViewerConfig = { 279 | container: HTMLElement | string; 280 | panorama?: any; 281 | /** @default equirectangular */ 282 | adapter?: AdapterConstructor | [AdapterConstructor, any]; 283 | plugins?: PluginConfig[]; 284 | /** @default null */ 285 | caption?: string; 286 | /** @default null */ 287 | description?: string; 288 | /** @default null */ 289 | downloadUrl?: string; 290 | /** @default null */ 291 | downloadName?: string; 292 | /** @default null */ 293 | loadingImg?: string; 294 | /** @default 'Loading...' */ 295 | loadingTxt?: string; 296 | /** @default `container` size */ 297 | size?: CssSize; 298 | /** @default false */ 299 | fisheye?: boolean | number; 300 | /** @default 30 */ 301 | minFov?: number; 302 | /** @default 90 */ 303 | maxFov?: number; 304 | /** @default 50 */ 305 | defaultZoomLvl?: number; 306 | /** @default 0 */ 307 | defaultYaw?: number | string; 308 | /** @default 0 */ 309 | defaultPitch?: number | string; 310 | /** @default `0,0,0` */ 311 | sphereCorrection?: SphereCorrection; 312 | /** @default 1 */ 313 | moveSpeed?: number; 314 | /** @default 1 */ 315 | zoomSpeed?: number; 316 | /** @default 0.8 */ 317 | moveInertia?: boolean | number; 318 | /** @default true */ 319 | mousewheel?: boolean; 320 | /** @default true */ 321 | mousemove?: boolean; 322 | /** @default false */ 323 | mousewheelCtrlKey?: boolean; 324 | /** @default false */ 325 | touchmoveTwoFingers?: boolean; 326 | panoData?: PanoData | PanoDataProvider; 327 | requestHeaders?: Record | ((url: string) => Record); 328 | /** @default '#000' */ 329 | canvasBackground?: string; 330 | /** @default '{ speed: 1500, rotation: true, effect: "fade" }' */ 331 | defaultTransition?: TransitionOptions; 332 | /** @default '{ alpha: true, antialias: true }' */ 333 | rendererParameters?: WebGLRendererParameters; 334 | /** @default false */ 335 | withCredentials?: boolean; 336 | /** @default 'zoom move download description caption fullscreen' */ 337 | navbar?: boolean | string | Array; 338 | lang?: Record; 339 | keyboard?: boolean | 'always' | 'fullscreen'; 340 | keyboardActions?: Record void)>; 341 | }; 342 | ``` 343 | 344 | > This code is generated from the original library. Click [here](http://photo-sphere-viewer.js.org/guide/config.html) to see documentation. 345 | 346 | ### Plugins 347 | 348 | To use the standard plugins provided by the original library, you need to pass the `plugins` prop to the component. The prop is an array of plugins. Each plugin can be a constructor or an array of constructor and options. To include them in the component, you need to import them directly from the "@photo-sphere-viewer/" package. 349 | 350 | > The only "third-party" plugin that is supported at the moment is the "Lensflare" plugin. To use it, you need to import it from the "photo-sphere-viewer-lensflare-plugin" package. This plugin is made by me and it is not included in the original library. 351 | 352 | > For Typescript users: the plugin array type is `PluginConfig[]` and you can import it from the library. 353 | 354 | ```jsx 355 | import { ReactPhotoSphereViewer } from "react-photo-sphere-viewer"; 356 | import { LensflarePlugin } from "photo-sphere-viewer-lensflare-plugin"; 357 | import { CompassPlugin } from "@photo-sphere-viewer/compass-plugin"; 358 | import { MarkersPlugin } from "@photo-sphere-viewer/markers-plugin"; 359 | 360 | function App() { 361 | const plugins = [ 362 | [ 363 | LensflarePlugin, 364 | { 365 | // list of lensflares 366 | lensflares: [ 367 | { 368 | id: "sun", 369 | position: { yaw: "145deg", pitch: "2deg" }, 370 | type: 0, 371 | }, 372 | ], 373 | }, 374 | ], 375 | [ 376 | CompassPlugin, 377 | { 378 | hotspots: [ 379 | { yaw: "0deg" }, 380 | { yaw: "90deg" }, 381 | { yaw: "180deg" }, 382 | { yaw: "270deg" }, 383 | ], 384 | }, 385 | ], 386 | [ 387 | MarkersPlugin, 388 | { 389 | markers: [ 390 | { 391 | id: "polygon", 392 | polygonPx: [ 393 | 2941, 1413, 3042, 1402, 3222, 1419, 3433, 1463, 3480, 1505, 3438, 394 | 1538, 3241, 1543, 3041, 1555, 2854, 1559, 2739, 1516, 2775, 1469, 395 | 2941, 1413, 396 | ], 397 | svgStyle: { 398 | fill: "rgba(255,0,0,0.2)", 399 | stroke: "rgba(255, 0, 50, 0.8)", 400 | strokeWidth: "2px", 401 | }, 402 | data: { compass: "rgba(255, 0, 50, 0.8)" }, 403 | }, 404 | { 405 | id: "polyline", 406 | polylinePx: [ 407 | 2478, 1635, 2184, 1747, 1674, 1953, 1166, 1852, 709, 1669, 301, 408 | 1519, 94, 1399, 34, 1356, 409 | ], 410 | svgStyle: { 411 | stroke: "rgba(80, 150, 50, 0.8)", 412 | strokeLinecap: "round", 413 | strokeLinejoin: "round", 414 | strokeWidth: "20px", 415 | }, 416 | data: { compass: "rgba(80, 150, 50, 0.8)" }, 417 | }, 418 | ], 419 | }, 420 | ], 421 | ]; 422 | 423 | return ( 424 |
425 | 431 |
432 | ); 433 | } 434 | ``` 435 | 436 | #### Calling plugin methods and handling events from outside the component [**NEW**](https://github.com/Elius94/react-photo-sphere-viewer/issues/6) 437 | 438 | To handle events from outside the component, you need to declare the callback function in the `onReady(instance: Viewer)` prop. The `instance` is the instance of the viewer. You can call the plugin methods using the `instance.getPlugin()` method. The `instance.getPlugin()` method returns the plugin instance. You can call the plugin methods using the plugin instance. 439 | 440 | ```jsx 441 | const handleReady = (instance) => { 442 | const markersPlugs = instance.getPlugin(MarkersPlugin); 443 | if (!markersPlugs) return; 444 | markersPlugs.addMarker({ 445 | id: "imageLayer2", 446 | image: "drone.png", 447 | size: { width: 220, height: 220 }, 448 | position: { yaw: "130.5deg", pitch: "-0.1deg" }, 449 | tooltip: "Image embedded in the scene", 450 | }); 451 | markersPlugs.addEventListener("select-marker", () => { 452 | console.log("asd"); 453 | }); 454 | }; 455 | 456 | return ( 457 |
458 | 465 |
466 | ); 467 | ``` 468 | 469 | > Click [here](https://photo-sphere-viewer.js.org/plugins/) to see plugins documentation. 470 | 471 | ### Note for Virtual Tour Plugin 472 | 473 | Please follow this Sandbox template to see how to use the original plugin: [Sandbox](https://codesandbox.io/p/sandbox/mj2p5k) 474 | 475 | Please remember to set the 'src' prop of the ReactPhotoSphereViewer component to a placeholder image, it colud be for example the first picture of the virtual tour. [#36](https://github.com/Elius94/react-photo-sphere-viewer/issues/36) 476 | If you want to use virtual tour functions, you can store them to a React state: [#69](https://github.com/Elius94/react-photo-sphere-viewer/issues/69#issuecomment-2606710741) 477 | 478 | ```jsx 479 | const handleReady = useCallback((instance) => { 480 | const animate = instance.animate.bind(instance); // Extract the "animate" function for example. 481 | setAnimateFunction(() => animate); // Store function into state 482 | }, []); 483 | ``` 484 | This quick tip can be used to call every library method. 485 | 486 | ### Adapters (NEW - 3.1.0-psv5.0.1) 487 | 488 | To use the standard library adapters provided by the original library, you need to pass the `adapter` prop to the component. The prop is an array of adapters. Each adapter can be a constructor or an array of constructor and options. To include them in the component, you need to import them directly from the "react-photo-sphere-viewer" package. 489 | 490 | ```jsx 491 | import { 492 | CubemapAdapter, 493 | CubemapAdapterOptions, 494 | } from "@photo-sphere-viewer/cubemap-adapter"; 495 | ``` 496 | 497 | > Click [here](https://photo-sphere-viewer.js.org/guide/adapters/) to see adapters documentation. 498 | 499 | ### events 500 | 501 | All documented events are exported as props (function names). 502 | 503 | ```ts 504 | type ViewerEvents = { 505 | onPositionChange?(lat: number, lng: number, instance: Viewer): any; 506 | onZoomChange?( 507 | data: events.ZoomUpdatedEvent & { type: "zoom-updated" }, 508 | instance: Viewer 509 | ): any; 510 | onClick?(data: events.ClickEvent & { type: "click" }, instance: Viewer): void; 511 | onDblclick?( 512 | data: events.ClickEvent & { type: "dblclick" }, 513 | instance: Viewer 514 | ): void; 515 | onReady?(instance: Viewer): void; 516 | }; 517 | ``` 518 | 519 | You can declare an event callback: 520 | 521 | ```js 522 | const handleClick = (data: events.ClickEvent & { type: "click" }) => { 523 | console.log(data); 524 | }; 525 | ``` 526 | 527 | and then: 528 | 529 | ```jsx 530 | { 531 | /*Pass the callback to the component*/ 532 | } 533 | ; 538 | ``` 539 | 540 | > To see the original events, click [here](http://photo-sphere-viewer.js.org/guide/events.html). 541 | 542 | ### methods 543 | 544 | To trigger a method you need to pass a reference to the component and access the method directly. 545 | 546 | ```js 547 | // Create a reference to the component 548 | const photoSphereRef = React.createRef(); 549 | 550 | // And calling the method 551 | photoSphereRef.current.zoom(10); 552 | 553 | // Or to be sure that the component is mounted 554 | React.useEffect(() => { 555 | if (!photoSphereRef.current) 556 | return; 557 | photoSphereRef.current.animate({ 558 | yaw: 0, 559 | pitch: 0, 560 | zoom: 55, 561 | speed: '10rpm', 562 | }); // Or any other method 563 | }, [photoSphereRef]); 564 | 565 | ``` 566 | 567 | And then: 568 | 569 | ```jsx 570 | { 571 | /*Pass the ref to the component*/ 572 | } 573 | ; 577 | ``` 578 | 579 | Currently managed methods are: 580 | 581 | - animate(options: AnimateOptions): utils.Animation; 582 | - destroy(): void; 583 | - createTooltip(config: TooltipConfig): Tooltip; 584 | - needsContinuousUpdate(enabled: boolean): void; 585 | - observeObjects(userDataKey: string): void; 586 | - unobserveObjects(userDataKey: string): void; 587 | - setCursor(cursor: string): void; 588 | - stopAnimation(): PromiseLike; 589 | - rotate(position: ExtendedPosition): void; 590 | - setOption(option: keyof UpdatableViewerConfig, value: unknown): void; 591 | - setOptions(options: Partial): void; 592 | - getCurrentNavbar(): (string | object)[] | void; 593 | - zoom(value: number): void; 594 | - zoomIn(step: number): void; 595 | - zoomOut(step: number): void; 596 | - resize(size: CssSize): void; 597 | - enterFullscreen(): void; 598 | - exitFullscreen(): void; 599 | - toggleFullscreen(): void; 600 | - isFullscreenEnabled(): boolean | void; 601 | - startAutoRotate(): void; 602 | - stopAutoRotate(): void; 603 | - getPlugin(pluginId: string | PluginConstructor): T; 604 | - getPosition(): Position; // Specify the return type 605 | - getZoomLevel(): number; // Specify the return type 606 | - getSize(): Size; // Specify the return type 607 | - needsUpdate(): void; 608 | - autoSize(): void; 609 | - setPanorama(path: any, options?: PanoramaOptions): Promise; 610 | - toggleAutorotate(): void; 611 | - showError(message: string): void; 612 | - hideError(): void; 613 | - startKeyboardControl(): void; 614 | - stopKeyboardControl(): void; 615 | 616 | > To see the original methods, click [here](http://photo-sphere-viewer.js.org/guide/methods.html). 617 | 618 | ## License 619 | 620 | MIT © [elius94](https://github.com/elius94) 621 | -------------------------------------------------------------------------------- /example/generic/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /example/generic/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /example/generic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@photo-sphere-viewer/autorotate-plugin": "^5.13.1", 7 | "@photo-sphere-viewer/core": "^5.13.1", 8 | "@photo-sphere-viewer/markers-plugin": "^5.13.1", 9 | "@photo-sphere-viewer/plan-plugin": "^5.13.1", 10 | "@testing-library/jest-dom": "^6.6.3", 11 | "@testing-library/react": "^16.3.0", 12 | "@testing-library/user-event": "^14.6.1", 13 | "leaflet": "^1.9.4", 14 | "photo-sphere-viewer-lensflare-plugin": "^2.1.4", 15 | "prop-types": "^15.8.1", 16 | "react": "^19.1.0", 17 | "react-dom": "^19.1.0", 18 | "react-photo-sphere-viewer": "file:../../", 19 | "react-scripts": "5.0.1", 20 | "web-vitals": "^4.2.4" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": [ 30 | "react-app", 31 | "react-app/jest" 32 | ] 33 | }, 34 | "browserslist": { 35 | "production": [ 36 | ">0.2%", 37 | "not dead", 38 | "not op_mini all" 39 | ], 40 | "development": [ 41 | "last 1 chrome version", 42 | "last 1 firefox version", 43 | "last 1 safari version" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/generic/public/Test_Pano.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/generic/public/Test_Pano.jpg -------------------------------------------------------------------------------- /example/generic/public/drone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/generic/public/drone.png -------------------------------------------------------------------------------- /example/generic/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/generic/public/favicon.ico -------------------------------------------------------------------------------- /example/generic/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /example/generic/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/generic/public/logo192.png -------------------------------------------------------------------------------- /example/generic/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/generic/public/logo512.png -------------------------------------------------------------------------------- /example/generic/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /example/generic/public/pin-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/generic/public/pin-blue.png -------------------------------------------------------------------------------- /example/generic/public/pin-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/generic/public/pin-red.png -------------------------------------------------------------------------------- /example/generic/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /example/generic/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /example/generic/src/App.js: -------------------------------------------------------------------------------- 1 | import './App.css'; 2 | import { ReactPhotoSphereViewer } from 'react-photo-sphere-viewer'; 3 | import { MarkersPlugin } from '@photo-sphere-viewer/markers-plugin'; 4 | import { PlanPlugin } from '@photo-sphere-viewer/plan-plugin'; 5 | import { LensflarePlugin } from 'photo-sphere-viewer-lensflare-plugin'; 6 | import { TileLayer } from 'leaflet'; 7 | import React from 'react'; 8 | import "@photo-sphere-viewer/plan-plugin/index.css" 9 | import "@photo-sphere-viewer/markers-plugin/index.css" 10 | import 'leaflet/dist/leaflet.css'; 11 | 12 | 13 | const PANOS = [ 14 | "https://srv.eliusoutdoor.com/ws/api/immersive/images/?n=gran-sasso-1&t=p", 15 | "https://srv.eliusoutdoor.com/ws/api/immersive/images/?n=mondeval&t=p" 16 | ]; 17 | 18 | const plugins = [ 19 | [ 20 | LensflarePlugin, 21 | { 22 | // list of lensflares 23 | lensflares: [ 24 | { 25 | id: 'sun', 26 | position: { yaw: '145deg', pitch: '2deg' }, 27 | type: 0, 28 | } 29 | ] 30 | } 31 | ], 32 | [ 33 | PlanPlugin, { 34 | defaultZoom: 14, 35 | coordinates: [6.78677, 44.58241], 36 | bearing: '120deg', 37 | layers: [ 38 | { 39 | name: 'OpenStreetMap', 40 | urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', 41 | attribution: '© OpenStreetMap', 42 | }, 43 | { 44 | name: 'OpenTopoMap', 45 | layer: new TileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', { 46 | subdomains: ['a', 'b', 'c'], 47 | maxZoom: 17, 48 | }), 49 | attribution: '© OpenTopoMap', 50 | }, 51 | ], 52 | hotspots: [ 53 | { 54 | coordinates: [6.7783, 44.58506], 55 | id: 'green-lake', 56 | tooltip: 'Lac vert', 57 | color: 'green', 58 | }, 59 | ], 60 | } 61 | ], 62 | [ 63 | MarkersPlugin, 64 | { 65 | // list of markers 66 | markers: [ 67 | { 68 | // image marker that opens the panel when clicked 69 | id: "image", 70 | position: { yaw: '0.33deg', pitch: '0.1deg' }, 71 | image: "pin-blue.png", 72 | anchor: "bottom center", 73 | size: { width: 32, height: 32 }, 74 | tooltip: "Mountain peak. Click me!" 75 | }, 76 | { 77 | // image marker rendered in the 3D scene 78 | id: "imageLayer", 79 | image: "drone.png", 80 | size: { width: 220, height: 220 }, 81 | position: { yaw: '13.5deg', pitch: '-0.1deg' }, 82 | tooltip: "Image embedded in the scene" 83 | } 84 | ] 85 | } 86 | ], 87 | ]; 88 | 89 | function App() { 90 | const [panoIndex, setPanoIndex] = React.useState(0); 91 | const photoSphereRef = React.useRef(); 92 | 93 | const handleClick = (instance) => { 94 | photoSphereRef.current.animate({ 95 | yaw: 0, 96 | pitch: 0, 97 | zoom: 55, 98 | speed: '10rpm', 99 | }); 100 | } 101 | 102 | const handleReady = (instance) => { 103 | const markersPlugs = instance.getPlugin(MarkersPlugin); 104 | if (!markersPlugs) 105 | return; 106 | console.log(markersPlugs); 107 | markersPlugs.addEventListener("select-marker", () => { 108 | console.log("asd"); 109 | }); 110 | } 111 | 112 | return ( 113 | <> 114 |
115 | 121 | 135 |
136 | 137 | ); 138 | } 139 | 140 | export default App; 141 | -------------------------------------------------------------------------------- /example/generic/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /example/generic/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /example/generic/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /example/generic/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/generic/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /example/generic/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /example/virtualtour/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-photo-sphere-viewer-virtual-tour-example", 3 | "version": "1.0.0", 4 | "description": "", 5 | "keywords": [], 6 | "main": "src/index.js", 7 | "dependencies": { 8 | "@photo-sphere-viewer/gallery-plugin": "^5.7.1", 9 | "@photo-sphere-viewer/markers-plugin": "^5.7.1", 10 | "@photo-sphere-viewer/virtual-tour-plugin": "^5.7.1", 11 | "@testing-library/jest-dom": "^5.16.4", 12 | "@testing-library/react": "^13.3.0", 13 | "@testing-library/user-event": "^13.5.0", 14 | "prop-types": "^15.5.4", 15 | "react": "18.2.0", 16 | "react-dom": "18.2.0", 17 | "react-photo-sphere-viewer": "file:../../", 18 | "react-scripts": "5.0.1", 19 | "web-vitals": "^2.1.4" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test --env=jsdom", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /example/virtualtour/public/Test_Pano.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/virtualtour/public/Test_Pano.jpg -------------------------------------------------------------------------------- /example/virtualtour/public/drone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/virtualtour/public/drone.png -------------------------------------------------------------------------------- /example/virtualtour/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 23 | React App 24 | 25 | 26 | 27 | 30 |
31 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /example/virtualtour/public/pin-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/virtualtour/public/pin-blue.png -------------------------------------------------------------------------------- /example/virtualtour/public/pin-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Elius94/react-photo-sphere-viewer/e475d1e0de6a5bb814d96ff55b738bbd67eca722/example/virtualtour/public/pin-red.png -------------------------------------------------------------------------------- /example/virtualtour/src/App.js: -------------------------------------------------------------------------------- 1 | import { 2 | ReactPhotoSphereViewer, 3 | } from "react-photo-sphere-viewer"; 4 | import { VirtualTourPlugin } from "@photo-sphere-viewer/virtual-tour-plugin"; 5 | import { MarkersPlugin } from "@photo-sphere-viewer/markers-plugin"; 6 | import { GalleryPlugin } from "@photo-sphere-viewer/gallery-plugin"; 7 | import "@photo-sphere-viewer/markers-plugin/index.css"; 8 | import "@photo-sphere-viewer/virtual-tour-plugin/index.css"; 9 | import "@photo-sphere-viewer/gallery-plugin/index.css"; 10 | import React from "react"; 11 | 12 | const baseUrl = "https://photo-sphere-viewer-data.netlify.app/assets/"; 13 | const caption = "Cape Florida Light, Key Biscayne © Pixexid"; 14 | 15 | function App() { 16 | const pSRef = React.createRef(); 17 | const [getCurrentNodeFunction, setGetCurrentNodeFunction] = React.useState(null); 18 | 19 | const handleReady = (instance) => { 20 | const virtualTour = instance.getPlugin(VirtualTourPlugin); 21 | if (!virtualTour) return; 22 | 23 | const markerLighthouse = { 24 | id: "marker-1", 25 | image: baseUrl + "pictos/pin-red.png", 26 | tooltip: "Cape Florida Light, Key Biscayne", 27 | size: { width: 32, height: 32 }, 28 | anchor: "bottom center", 29 | gps: [-80.155973, 25.666601, 29 + 3] 30 | }; 31 | 32 | virtualTour.setNodes( 33 | [ 34 | { 35 | id: "1", 36 | panorama: baseUrl + "tour/key-biscayne-1.jpg", 37 | thumbnail: baseUrl + "tour/key-biscayne-1-thumb.jpg", 38 | name: "One", 39 | caption: `[1] ${caption}`, 40 | links: [{ nodeId: "2" }], 41 | markers: [markerLighthouse], 42 | gps: [-80.156479, 25.666725, 3], 43 | panoData: { poseHeading: 327 } 44 | }, 45 | { 46 | id: "2", 47 | panorama: baseUrl + "tour/key-biscayne-2.jpg", 48 | thumbnail: baseUrl + "tour/key-biscayne-2-thumb.jpg", 49 | name: "Two", 50 | caption: `[2] ${caption}`, 51 | links: [{ nodeId: "3" }, { nodeId: "1" }], 52 | markers: [markerLighthouse], 53 | gps: [-80.156168, 25.666623, 3], 54 | panoData: { poseHeading: 318 } 55 | }, 56 | { 57 | id: "3", 58 | panorama: baseUrl + "tour/key-biscayne-3.jpg", 59 | thumbnail: baseUrl + "tour/key-biscayne-3-thumb.jpg", 60 | name: "Three", 61 | caption: `[3] ${caption}`, 62 | links: [{ nodeId: "4" }, { nodeId: "2" }, { nodeId: "5" }], 63 | gps: [-80.155932, 25.666498, 5], 64 | panoData: { poseHeading: 310 } 65 | }, 66 | { 67 | id: "4", 68 | panorama: baseUrl + "tour/key-biscayne-4.jpg", 69 | thumbnail: baseUrl + "tour/key-biscayne-4-thumb.jpg", 70 | name: "Four", 71 | caption: `[4] ${caption}`, 72 | links: [{ nodeId: "3" }, { nodeId: "5" }], 73 | gps: [-80.156089, 25.666357, 3], 74 | panoData: { poseHeading: 78 } 75 | }, 76 | { 77 | id: "5", 78 | panorama: baseUrl + "tour/key-biscayne-5.jpg", 79 | thumbnail: baseUrl + "tour/key-biscayne-5-thumb.jpg", 80 | name: "Five", 81 | caption: `[5] ${caption}`, 82 | links: [{ nodeId: "6" }, { nodeId: "3" }, { nodeId: "4" }], 83 | gps: [-80.156292, 25.666446, 2], 84 | panoData: { poseHeading: 190 } 85 | }, 86 | { 87 | id: "6", 88 | panorama: baseUrl + "tour/key-biscayne-6.jpg", 89 | thumbnail: baseUrl + "tour/key-biscayne-6-thumb.jpg", 90 | name: "Six", 91 | caption: `[6] ${caption}`, 92 | links: [{ nodeId: "5" }, { nodeId: "7" }], 93 | gps: [-80.156465, 25.666496, 2], 94 | panoData: { poseHeading: 295 } 95 | }, 96 | { 97 | id: "7", 98 | panorama: baseUrl + "tour/key-biscayne-7.jpg", 99 | thumbnail: baseUrl + "tour/key-biscayne-7-thumb.jpg", 100 | name: "Seven", 101 | caption: `[7] ${caption}`, 102 | links: [{ nodeId: "6" }], 103 | gps: [-80.15707, 25.6665, 3], 104 | panoData: { poseHeading: 250, posePitch: 3 } 105 | } 106 | ], 107 | "2" 108 | ); 109 | 110 | const getCurrentNode = virtualTour.getCurrentNode.bind(virtualTour); 111 | setGetCurrentNodeFunction(() => getCurrentNode); 112 | }; 113 | 114 | const handleClick = () => { 115 | const curr_node = getCurrentNodeFunction(); 116 | console.log(curr_node); 117 | } 118 | 119 | const plugins = [ 120 | MarkersPlugin, 121 | [ 122 | GalleryPlugin, 123 | { 124 | thumbnailSize: { width: 100, height: 100 } 125 | } 126 | ], 127 | [ 128 | VirtualTourPlugin, 129 | { 130 | positionMode: "gps", 131 | renderMode: "3d" 132 | } 133 | ] 134 | ]; 135 | 136 | return ( 137 |
138 | 153 | 154 |
155 | ); 156 | } 157 | 158 | export default App; 159 | -------------------------------------------------------------------------------- /example/virtualtour/src/index.css: -------------------------------------------------------------------------------- 1 | .App { 2 | font-family: sans-serif; 3 | text-align: center; 4 | } 5 | -------------------------------------------------------------------------------- /example/virtualtour/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /example/virtualtour/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /example/virtualtour/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-photo-sphere-viewer", 3 | "version": "6.2.3", 4 | "description": "A React wrapper for Photo Sphere Viewer, to display 360° panoramas with ease.", 5 | "author": "Elius94", 6 | "license": "MIT", 7 | "keywords": [ 8 | "react", 9 | "photosphere", 10 | "viewer", 11 | "360", 12 | "panorama", 13 | "photo", 14 | "sphere", 15 | "photo-sphere-viewer", 16 | "react-photo-sphere-viewer" 17 | ], 18 | "sideEffects": false, 19 | "homepage": "https://github.com/elius94/react-photo-sphere-viewer#readme", 20 | "bugs": { 21 | "url": "https://github.com/elius94/react-photo-sphere-viewer/issues" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "git+https://github.com/elius94/react-photo-sphere-viewer.git" 26 | }, 27 | "module": "dist/index.js", 28 | "types": "dist/index.d.ts", 29 | "type": "module", 30 | "engines": { 31 | "node": ">=16", 32 | "npm": ">=8" 33 | }, 34 | "scripts": { 35 | "clean": "rimraf dist/", 36 | "clean-peers": "rimraf node_modules/@photo-sphere-viewer && rimraf node_modules/react && rimraf node_modules/react-dom", 37 | "copy-files": "copyfiles -u 1 src/**/*.css dist/", 38 | "types": "tsc --emitDeclarationOnly", 39 | "build": "npm run clean && rollup -c && npm run types && npm run copy-files", 40 | "start": "rollup -c -w", 41 | "prepare": "npm run build && npm run clean-peers", 42 | "predeploy": "cd example && npm install && npm run build", 43 | "deploy": "gh-pages -d example/build" 44 | }, 45 | "dependencies": { 46 | "eventemitter3": "^5.0.1" 47 | }, 48 | "peerDependencies": { 49 | "@photo-sphere-viewer/core": ">=5.13.1", 50 | "prop-types": "^15.5.4", 51 | "react": ">=16.0.0", 52 | "react-dom": ">=16.0.0" 53 | }, 54 | "devDependencies": { 55 | "@babel/preset-typescript": "^7.27.0", 56 | "@rollup/plugin-babel": "^6.0.4", 57 | "@rollup/plugin-commonjs": "^25.0.7", 58 | "@rollup/plugin-node-resolve": "^15.2.3", 59 | "@rollup/plugin-typescript": "^11.1.6", 60 | "@rollup/plugin-url": "^8.0.2", 61 | "@svgr/rollup": "^8.1.0", 62 | "@types/react": "^18.2.60", 63 | "@types/three": "^0.175.0", 64 | "@typescript-eslint/eslint-plugin": "^7.1.0", 65 | "@typescript-eslint/parser": "^7.1.0", 66 | "babel-plugin-styled-components": "^2.1.4", 67 | "copyfiles": "^2.4.1", 68 | "gh-pages": "^6.1.1", 69 | "rimraf": "^5.0.5", 70 | "rollup": "^4.12.0", 71 | "rollup-plugin-peer-deps-external": "^2.2.4", 72 | "rollup-plugin-postcss": "^4.0.2" 73 | }, 74 | "files": [ 75 | "dist" 76 | ] 77 | } 78 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import commonjs from "@rollup/plugin-commonjs" 2 | import postcss from "rollup-plugin-postcss" 3 | import resolve from "@rollup/plugin-node-resolve" 4 | import url from "@rollup/plugin-url" 5 | import svgr from "@svgr/rollup" 6 | import babel from "@rollup/plugin-babel" 7 | import peerDepsExternal from "rollup-plugin-peer-deps-external" 8 | 9 | export default { 10 | input: "src/index.tsx", 11 | output: [ 12 | { 13 | dir: "dist", 14 | format: "esm", 15 | exports: "named", 16 | preserveModules: true, 17 | preserveModulesRoot: "src", 18 | sourcemap: true 19 | } 20 | ], 21 | plugins: [ 22 | peerDepsExternal(), 23 | resolve({ extensions: [".js", ".jsx", ".ts", ".tsx"] }), 24 | postcss({ 25 | extract: true, 26 | modules: false, 27 | minimize: true 28 | }), 29 | commonjs(), 30 | url(), 31 | svgr(), 32 | babel({ 33 | babelHelpers: "bundled", 34 | exclude: "node_modules/**", 35 | extensions: [".ts", ".tsx", ".js", ".jsx"], 36 | presets: [ 37 | "@babel/preset-env", 38 | "@babel/preset-react", 39 | "@babel/preset-typescript" // 👈 aggiunto preset per TS 40 | ], 41 | plugins: [["babel-plugin-styled-components", { displayName: true }]] 42 | }) 43 | ], 44 | external: (id) => 45 | ["react", "react-dom", "@photo-sphere-viewer/core", "photo-sphere-viewer-lensflare-plugin"].some(pkg => id === pkg || id.startsWith(pkg + "/")), 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/index.d.ts: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | /** 4 | * Default CSS definition for typescript, 5 | * will be overridden with file-specific definitions by rollup 6 | */ 7 | declare module "*.css" { 8 | const content: { [className: string]: string } 9 | export default content 10 | } 11 | 12 | type SvgrComponent = React.Component> 13 | 14 | declare module "*.svg" { 15 | const svgUrl: string 16 | const svgComponent: SvgrComponent 17 | export default svgUrl 18 | export { svgComponent as ReactComponent } 19 | } 20 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect, useImperativeHandle, forwardRef, useRef, useCallback, useMemo } from "react" 2 | import { 3 | Viewer, 4 | ViewerConfig, 5 | AnimateOptions, 6 | CssSize, 7 | ExtendedPosition, 8 | UpdatableViewerConfig, 9 | events, 10 | PluginConstructor, 11 | NavbarCustomButton, 12 | TooltipConfig, 13 | Tooltip, 14 | Position, 15 | Size, 16 | PanoramaOptions, 17 | utils, 18 | AbstractPlugin 19 | /* @ts-ignore next line */ 20 | } from "@photo-sphere-viewer/core" // Peer dependency 21 | import "./styles.css" 22 | import "@photo-sphere-viewer/core/index.css" 23 | 24 | import EventEmitter from "eventemitter3" 25 | 26 | 27 | const eventEmitter = new EventEmitter() 28 | const Emitter = { 29 | on: (event: string, fn: (...args: unknown[]) => void) => eventEmitter.on(event, fn), 30 | once: (event: string, fn: (...args: unknown[]) => void) => eventEmitter.once(event, fn), 31 | off: (event: string, fn: (...args: unknown[]) => void) => eventEmitter.off(event, fn), 32 | emit: (event: string, payload: unknown) => eventEmitter.emit(event, payload), 33 | } 34 | 35 | Object.freeze(Emitter) 36 | 37 | const omittedProps = [ 38 | "src", 39 | "height", 40 | "width", 41 | "hideNavbarButton", 42 | "containerClass", 43 | "littlePlanet", 44 | "onPositionChange", 45 | "onZoomChange", 46 | "onClick", 47 | "onDblclick", 48 | "onReady", 49 | ] 50 | type MakeOptional = Omit & Partial>; 51 | 52 | export interface CubeMapSrc { 53 | left: string; 54 | front: string; 55 | right: string; 56 | back: string; 57 | top: string; 58 | bottom: string; 59 | } 60 | 61 | export interface TilesAdapterSrc { 62 | width: number; 63 | cols: number; 64 | rows: number; 65 | baseUrl: string; 66 | tileUrl: (col: number, row: number) => string; 67 | } 68 | 69 | type PluginEntry = 70 | | PluginConstructor 71 | | [PluginConstructor, Record]; 72 | 73 | export type PluginConfig = PluginEntry; 74 | 75 | /** 76 | * Props interface for the Viewer component. 77 | * 78 | * @interface 79 | * @property {string} src - The source of the image to be viewed. 80 | * @property {boolean | string | Array} [navbar] - Configuration for the navbar. Can be a boolean, string, or an array of strings or NavbarCustomButton. 81 | * @property {string} height - The height of the viewer. 82 | * @property {string} [width] - The width of the viewer. 83 | * @property {string} [containerClass] - The CSS class for the viewer container. 84 | * @property {boolean} [littlePlanet] - Enable or disable the little planet effect. 85 | * @property {boolean | number} [fishEye] - Enable or disable the fisheye effect, or set the fisheye level. 86 | * @property {boolean} [hideNavbarButton] - Show/hide the button that hides the navbar. 87 | * @property {Object} [lang] - Language configuration for the viewer. Each property is a string that represents the text for a specific action. 88 | * @property {Function} [onPositionChange] - Event handler for when the position changes. Receives the latitude, longitude, and the Viewer instance. 89 | * @property {Function} [onZoomChange] - Event handler for when the zoom level changes. Receives the ZoomUpdatedEvent and the Viewer instance. 90 | * @property {Function} [onClick] - Event handler for when the viewer is clicked. Receives the ClickEvent and the Viewer instance. 91 | * @property {Function} [onDblclick] - Event handler for when the viewer is double clicked. Receives the ClickEvent and the Viewer instance. 92 | * @property {Function} [onReady] - Event handler for when the viewer is ready. Receives the Viewer instance. 93 | */ 94 | export interface Props extends MakeOptional { 95 | src: string | CubeMapSrc | TilesAdapterSrc; 96 | navbar?: boolean | string | Array; 97 | height: string; 98 | width?: string; 99 | containerClass?: string; 100 | littlePlanet?: boolean; 101 | fishEye?: boolean | number; 102 | hideNavbarButton?: boolean; 103 | lang?: Record; 104 | plugins?: PluginEntry[]; 105 | // Events 106 | onPositionChange?(lat: number, lng: number, instance: Viewer): void; 107 | onZoomChange?(data: events.ZoomUpdatedEvent & { type: "zoom-updated"; }, instance: Viewer): void; 108 | onClick?(data: events.ClickEvent & { type: "click"; }, instance: Viewer): void; 109 | onDblclick?(data: events.ClickEvent & { type: "dblclick"; }, instance: Viewer): void; 110 | onReady?(instance: Viewer): void; 111 | } 112 | 113 | const defaultNavbar = [ 114 | "zoom", 115 | "fullscreen" 116 | ] 117 | 118 | function adaptOptions(options: Props): ViewerConfig { 119 | const adaptedOptions = { ...options } 120 | for (const key in adaptedOptions) { 121 | if (omittedProps.includes(key)) { 122 | delete (adaptedOptions as Record)[key] 123 | } 124 | } 125 | return adaptedOptions as ViewerConfig 126 | } 127 | 128 | function map(_in: number, inMin: number, inMax: number, outMin: number, outMax: number): number { 129 | return (_in - inMin) * (outMax - outMin) / (inMax - inMin) + outMin 130 | } 131 | 132 | function filterNavbar(navbar?: boolean | string | Array): false | Array { 133 | if (navbar == null) return defaultNavbar 134 | if (!Array.isArray(navbar)) { 135 | if (typeof navbar === "string") { 136 | return navbar === "" ? false : [navbar] 137 | } 138 | return navbar ? defaultNavbar : false 139 | } 140 | return navbar 141 | } 142 | 143 | function useDomElement(): [HTMLDivElement | undefined, (r: HTMLDivElement) => void] { 144 | const [element, setElement] = useState() 145 | const ref = useCallback( 146 | (r: HTMLDivElement) => { 147 | if (r && r !== element) { 148 | setElement(r) 149 | } 150 | }, 151 | [element] 152 | ) 153 | return [element, ref] 154 | } 155 | 156 | /** 157 | * Interface for the Viewer API. 158 | * 159 | * @interface 160 | * @property {Function} animate - Starts an animation. Receives an object of AnimateOptions. 161 | * @property {Function} destroy - Destroys the viewer. 162 | * @property {Function} createTooltip - Creates a tooltip. Receives a TooltipConfig object. 163 | * @property {Function} needsContinuousUpdate - Enables or disables continuous updates. Receives a boolean. 164 | * @property {Function} observeObjects - Starts observing objects. Receives a string key. 165 | * @property {Function} unobserveObjects - Stops observing objects. Receives a string key. 166 | * @property {Function} setCursor - Sets the cursor. Receives a string. 167 | * @property {Function} stopAnimation - Stops the current animation. Returns a Promise. 168 | * @property {Function} rotate - Rotates the viewer. Receives an ExtendedPosition object. 169 | * @property {Function} setOption - Sets a single option. Receives an option key and a value. 170 | * @property {Function} setOptions - Sets multiple options. Receives an object of options. 171 | * @property {Function} getCurrentNavbar - Returns the current navbar. 172 | * @property {Function} zoom - Sets the zoom level. Receives a number. 173 | * @property {Function} zoomIn - Increases the zoom level. Receives a number. 174 | * @property {Function} zoomOut - Decreases the zoom level. Receives a number. 175 | * @property {Function} resize - Resizes the viewer. Receives a CssSize object. 176 | * @property {Function} enterFullscreen - Enters fullscreen mode. 177 | * @property {Function} exitFullscreen - Exits fullscreen mode. 178 | * @property {Function} toggleFullscreen - Toggles fullscreen mode. 179 | * @property {Function} isFullscreenEnabled - Returns whether fullscreen is enabled. 180 | * @property {Function} getPlugin - Returns a plugin. Receives a plugin ID or a PluginConstructor. 181 | * @property {Function} getPosition - Returns the current position. 182 | * @property {Function} getZoomLevel - Returns the current zoom level. 183 | * @property {Function} getSize - Returns the current size. 184 | * @property {Function} needsUpdate - Updates the viewer. 185 | * @property {Function} autoSize - Sets the size to auto. 186 | * @property {Function} setPanorama - Sets the panorama. Receives a path and an optional PanoramaOptions object. Returns a Promise. 187 | * @property {Function} showError - Shows an error message. Receives a string. 188 | * @property {Function} hideError - Hides the error message. 189 | * @property {Function} startKeyboardControl - Starts keyboard control. 190 | * @property {Function} stopKeyboardControl - Stops keyboard control. 191 | */ 192 | export interface ViewerAPI { 193 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 194 | animate(options: AnimateOptions): utils.Animation; 195 | destroy(): void; 196 | createTooltip(config: TooltipConfig): Tooltip; 197 | needsContinuousUpdate(enabled: boolean): void; 198 | observeObjects(userDataKey: string): void; 199 | unobserveObjects(userDataKey: string): void; 200 | setCursor(cursor: string): void; 201 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 202 | stopAnimation(): PromiseLike; 203 | rotate(position: ExtendedPosition): void; 204 | setOption(option: T, value: UpdatableViewerConfig[T]): void; 205 | setOptions(options: Partial): void; 206 | getCurrentNavbar(): (string | object)[] | void; 207 | zoom(value: number): void; 208 | zoomIn(step: number): void; 209 | zoomOut(step: number): void; 210 | resize(size: CssSize): void; 211 | enterFullscreen(): void; 212 | exitFullscreen(): void; 213 | toggleFullscreen(): void; 214 | isFullscreenEnabled(): boolean | void; 215 | /** 216 | * Returns the instance of a plugin if it exists 217 | * @example By plugin identifier 218 | * ```js 219 | * viewer.getPlugin('markers') 220 | * ``` 221 | * @example By plugin class with TypeScript support 222 | * ```ts 223 | * viewer.getPlugin(MarkersPlugin) 224 | * ``` 225 | */ 226 | getPlugin>(pluginId: string | PluginConstructor): T; 227 | getPosition(): Position; // Specify the return type 228 | getZoomLevel(): number; // Specify the return type 229 | getSize(): Size; // Specify the return type 230 | needsUpdate(): void; 231 | autoSize(): void; 232 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 233 | setPanorama(path: any, options?: PanoramaOptions): Promise; 234 | showError(message: string): void; 235 | hideError(): void; 236 | startKeyboardControl(): void; 237 | stopKeyboardControl(): void; 238 | } 239 | 240 | const ReactPhotoSphereViewer = forwardRef((props, ref): React.ReactElement => { 241 | const [sphereElement, setRef] = useDomElement() 242 | const options = useMemo( 243 | () => props, 244 | [ 245 | // recreate options when individual props change 246 | props.panorama, 247 | props.src, 248 | props.size, 249 | props.canvasBackground, 250 | props.navbar, 251 | props.height, 252 | props.width, 253 | props.containerClass, 254 | props.hideNavbarButton || true, 255 | props.littlePlanet, 256 | props.fishEye, 257 | props.lang, 258 | props.onPositionChange, 259 | props.onZoomChange, 260 | props.onClick, 261 | props.onDblclick, 262 | props.onReady, 263 | props.moveSpeed, 264 | props.zoomSpeed, 265 | props.moveInertia, 266 | props.mousewheel, 267 | props.mousemove, 268 | props.mousewheelCtrlKey, 269 | props.touchmoveTwoFingers, 270 | props.panoData, 271 | props.requestHeaders, 272 | props.withCredentials, 273 | props.keyboard, 274 | props.keyboardActions, 275 | props.plugins, 276 | props.adapter, 277 | props.sphereCorrection, 278 | props.minFov, 279 | props.maxFov, 280 | props.defaultZoomLvl, 281 | props.defaultYaw, 282 | props.defaultPitch, 283 | props.caption, 284 | props.description, 285 | props.downloadUrl, 286 | props.downloadName, 287 | props.loadingImg, 288 | props.loadingTxt, 289 | props.rendererParameters, 290 | props.defaultTransition, 291 | ] 292 | ) 293 | 294 | 295 | const spherePlayerInstance = useRef(null) 296 | let LITTLEPLANET_MAX_ZOOM = 130 297 | const [LITTLEPLANET_DEF_LAT] = useState(-90) 298 | const [LITTLEPLANET_FISHEYE] = useState(2) 299 | const [LITTLEPLANET_DEF_ZOOM] = useState(0) 300 | const [currentNavbar, setCurrentNavbar] = useState<(string | object)[]>(defaultNavbar) 301 | const littlePlanetEnabledRef = useRef(true) 302 | 303 | useEffect(() => { 304 | function handleResize() { 305 | const aspectRatio = window.innerWidth / window.innerHeight 306 | //console.log(aspectRatio) 307 | LITTLEPLANET_MAX_ZOOM = Math.floor(map(aspectRatio, 0.5, 1.8, 140, 115)) 308 | } 309 | // Add event listener 310 | window.addEventListener("resize", handleResize) 311 | 312 | handleResize() 313 | return () => window.removeEventListener("resize", handleResize) 314 | }, []) 315 | 316 | useEffect(() => { 317 | if (sphereElement && !spherePlayerInstance.current) { 318 | const _c = new Viewer({ 319 | ...adaptOptions(options), 320 | container: sphereElement, 321 | panorama: options.panorama || options.src, 322 | size: { 323 | height: options.height, 324 | width: options.width || "100px" 325 | }, 326 | fisheye: options.littlePlanet ? LITTLEPLANET_FISHEYE : options.fisheye || false, 327 | minFov: options.minFov ?? 30, 328 | maxFov: options.littlePlanet ? LITTLEPLANET_MAX_ZOOM : options.maxFov ?? 90, 329 | defaultZoomLvl: options.littlePlanet ? LITTLEPLANET_DEF_ZOOM : options.defaultZoomLvl ?? 50, 330 | defaultYaw: options.defaultYaw ?? 0, 331 | defaultPitch: options.littlePlanet ? LITTLEPLANET_DEF_LAT : options.defaultPitch ?? 0, 332 | sphereCorrection: options.sphereCorrection || { pan: 0, tilt: 0, roll: 0 }, 333 | moveSpeed: options.moveSpeed || 1, 334 | zoomSpeed: options.zoomSpeed || 1, 335 | // when it undefined, = true, then use input value. 336 | // The input value maybe false, value || true => false => true 337 | moveInertia: options.moveInertia ?? true, 338 | mousewheel: options.littlePlanet ? false : options.mousewheel ?? true, 339 | mousemove: options.mousemove ?? true, 340 | mousewheelCtrlKey: options.mousewheelCtrlKey || false, 341 | touchmoveTwoFingers: options.touchmoveTwoFingers || false, 342 | panoData: options.panoData || undefined, 343 | requestHeaders: options.requestHeaders || undefined, 344 | withCredentials: options.withCredentials || false, 345 | navbar: filterNavbar(options.navbar), 346 | lang: options.lang || {} as keyof Props["lang"], 347 | keyboard: options.keyboard || "fullscreen", 348 | plugins: options.plugins ?? [], 349 | }) 350 | _c.addEventListener("ready", () => { 351 | if (options.onReady) { 352 | options.onReady(_c) 353 | } 354 | }, { once: true }) 355 | _c.addEventListener("click", (data: events.ClickEvent & { type: "click"; }) => { 356 | if (options.onClick) { 357 | options.onClick(data, _c) 358 | } 359 | if (options.littlePlanet && littlePlanetEnabledRef.current) { 360 | littlePlanetEnabledRef.current = false 361 | // fly inside the sphere 362 | _c.animate({ 363 | yaw: 0, 364 | pitch: LITTLEPLANET_DEF_LAT, 365 | zoom: 75, 366 | speed: "3rpm", 367 | }).then(() => { 368 | // watch on the sky 369 | _c.animate({ 370 | yaw: 0, 371 | pitch: 0, 372 | zoom: 90, 373 | speed: "10rpm", 374 | }).then(() => { 375 | // Disable Little Planet. 376 | _c.setOption("maxFov", options.maxFov || 70) 377 | _c.setOption("mousewheel", options.mousewheel ?? true) 378 | }) 379 | }) 380 | } 381 | }) 382 | _c.addEventListener("dblclick", (data: events.ClickEvent & { type: "dblclick"; }) => { 383 | if (options.onDblclick) { 384 | options.onDblclick(data, _c) 385 | } 386 | }) 387 | _c.addEventListener("zoom-updated", (zoom: events.ZoomUpdatedEvent & { type: "zoom-updated" }) => { 388 | if (options.onZoomChange) { 389 | options.onZoomChange(zoom, _c) 390 | } 391 | }) 392 | _c.addEventListener("position-updated", (position: events.PositionUpdatedEvent & { type: "position-updated"; }) => { 393 | if (options.onPositionChange) { 394 | options.onPositionChange(position.position.pitch, position.position.yaw, _c) 395 | } 396 | }) 397 | 398 | const _currentNavbar = filterNavbar(options.navbar) 399 | if (options.littlePlanet) { 400 | const littlePlanetIcon = ` 401 | 402 | ` 403 | const resetLittlePlanetButton = { 404 | id: "resetLittlePlanetButton", 405 | content: props.lang?.littlePlanetIcon || littlePlanetIcon, 406 | title: props.lang?.littlePlanetButton || "Reset Little Planet", 407 | className: "resetLittlePlanetButton", 408 | onClick: () => { 409 | littlePlanetEnabledRef.current = true 410 | _c.setOption("maxFov", LITTLEPLANET_MAX_ZOOM) 411 | //_c.setOption("fisheye", LITTLEPLANET_FISHEYE) // @ts-ignore ts(2345) 412 | _c.setOption("mousewheel", false) 413 | _c.animate({ 414 | yaw: 0, 415 | pitch: LITTLEPLANET_DEF_LAT, 416 | zoom: LITTLEPLANET_DEF_ZOOM, 417 | speed: "10rpm", 418 | }) 419 | }, 420 | } 421 | if (_currentNavbar !== false && !_currentNavbar.find((item) => typeof item === "object" && item?.id === "resetLittlePlanetButton")) { 422 | _currentNavbar.splice(1, 0, resetLittlePlanetButton) 423 | } 424 | } 425 | 426 | if (options.hideNavbarButton) { 427 | // add toggle navbar visibility button 428 | const hideNavbarButton = { 429 | id: "hideNavbarButton", 430 | content: ` 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | `, 440 | title: "Hide Navbar", 441 | className: "hideNavbarButton", 442 | onClick: () => { 443 | _c.navbar.hide() 444 | // add a show navbar button that is always hidden until mouseover 445 | const btn = document.createElement("a") 446 | btn.className = "showNavbarButton" 447 | // add svg icon 448 | btn.innerHTML = ` 449 | 450 | 457 | 458 | ` 459 | btn.title = "Show Navbar" 460 | btn.onclick = (e) => { 461 | e.preventDefault() 462 | _c.navbar.show() 463 | btn.remove() 464 | } 465 | 466 | // add the button to the viewer container 467 | document.body.appendChild(btn) 468 | }, 469 | } 470 | 471 | if (_currentNavbar !== false && !_currentNavbar.find((item) => typeof item === "object" && item?.id === "hideNavbarButton")) { 472 | _currentNavbar.push(hideNavbarButton) 473 | } 474 | } 475 | 476 | if (_currentNavbar !== false) { 477 | _c.setOption("navbar", _currentNavbar) 478 | setCurrentNavbar(_currentNavbar as (string | object)[]) 479 | } else { 480 | _c.navbar.hide() 481 | } 482 | 483 | /* @ts-ignore next line */ 484 | Emitter.on("animate", (options: AnimateOptions) => { 485 | _c.animate(options) 486 | }).on("stop-animation", () => { 487 | _c.stopAnimation() 488 | }).on("destroy", () => { 489 | _c.destroy() 490 | }).on("rotate", (options: ExtendedPosition) => { 491 | _c.rotate(options) 492 | }).on("setOption", (pair: { option: keyof UpdatableViewerConfig, value: UpdatableViewerConfig[keyof UpdatableViewerConfig] }) => { 493 | const { option, value } = pair 494 | _c.setOption(option, value) 495 | }).on("setOptions", (options: Partial) => { 496 | _c.setOptions(options) 497 | }).on("zoom", (zoom: number) => { 498 | _c.zoom(zoom) 499 | }).on("zoomIn", (step: number) => { 500 | _c.zoomIn(step) 501 | }).on("zoomOut", (step: number) => { 502 | _c.zoomOut(step) 503 | }).on("resize", (size: CssSize) => { 504 | _c.resize(size) 505 | }).on("enterFullscreen", () => { 506 | _c.enterFullscreen() 507 | }).on("exitFullscreen", () => { 508 | _c.exitFullscreen() 509 | }).on("toggleFullscreen", () => { 510 | _c.toggleFullscreen() 511 | }).on("needsContinuousUpdate", (enabled: boolean) => { 512 | _c.needsContinuousUpdate(enabled) 513 | }).on("observeObjects", (userDataKey: string) => { 514 | _c.observeObjects(userDataKey) 515 | }).on("unobserveObjects", (userDataKey: string) => { 516 | _c.unobserveObjects(userDataKey) 517 | }).on("setCursor", (cursor: string) => { 518 | _c.setCursor(cursor) 519 | }).on("setPanorama", (payload: { path: unknown, options?: PanoramaOptions }) => { 520 | _c.setPanorama(payload.path, payload.options) 521 | }).on("showError", (message: string) => { 522 | _c.showError(message) 523 | }).on("hideError", () => { 524 | _c.hideError() 525 | }).on("startKeyboardControl", () => { 526 | _c.startKeyboardControl() 527 | }).on("stopKeyboardControl", () => { 528 | _c.stopKeyboardControl() 529 | }) 530 | 531 | spherePlayerInstance.current = _c 532 | } 533 | }, [sphereElement, options]) 534 | 535 | useEffect(() => { 536 | const viewer: Viewer | null = spherePlayerInstance.current 537 | if (viewer && viewer.container && viewer.container.parentNode) { 538 | if (viewer && viewer.container && viewer.container.parentNode) { 539 | (viewer.renderer as unknown as { renderer?: { dispose: () => void } })?.renderer?.dispose() 540 | ; (viewer.renderer as unknown as { renderer?: { forceContextLoss: () => void } })?.renderer?.forceContextLoss() 541 | viewer.destroy() 542 | } 543 | } 544 | }, [spherePlayerInstance]) 545 | 546 | useEffect(() => { 547 | const panorama = options.panorama ?? options.src 548 | if (spherePlayerInstance.current && panorama) { 549 | spherePlayerInstance.current.setPanorama(panorama, {}) 550 | } 551 | }, [options.src, options.panorama]) 552 | 553 | const _imperativeHandle = () => ({ 554 | animate(options: AnimateOptions) { 555 | Emitter.emit("animate", options) 556 | }, 557 | destroy() { 558 | Emitter.emit("destroy", {}) 559 | }, 560 | createTooltip(config: TooltipConfig): Tooltip { 561 | return spherePlayerInstance.current?.createTooltip(config) as Tooltip 562 | }, 563 | needsContinuousUpdate(enabled: boolean) { 564 | Emitter.emit("needsContinuousUpdate", enabled) 565 | }, 566 | observeObjects(userDataKey: string) { 567 | Emitter.emit("observeObjects", userDataKey) 568 | }, 569 | unobserveObjects(userDataKey: string) { 570 | Emitter.emit("unobserveObjects", userDataKey) 571 | }, 572 | setCursor(cursor: string) { 573 | Emitter.emit("setCursor", cursor) 574 | }, 575 | stopAnimation() { 576 | Emitter.emit("stop-animation", {}) 577 | }, 578 | rotate(position: ExtendedPosition) { 579 | Emitter.emit("rotate", position) 580 | }, 581 | setOption(option: T, value: UpdatableViewerConfig[T]) { 582 | Emitter.emit("setOption", { option, value }) 583 | }, 584 | setOptions(options: Partial): void { 585 | return spherePlayerInstance.current?.setOptions(options) 586 | }, 587 | getCurrentNavbar(): (string | object)[] { 588 | return currentNavbar 589 | }, 590 | zoom(value: number) { 591 | Emitter.emit("zoom", value) 592 | }, 593 | zoomIn(step: number) { 594 | Emitter.emit("zoomIn", { step }) 595 | }, 596 | zoomOut(step: number) { 597 | Emitter.emit("zoomOut", { step }) 598 | }, 599 | resize(size: CssSize) { 600 | return spherePlayerInstance.current?.resize(size) 601 | }, 602 | enterFullscreen() { 603 | return spherePlayerInstance.current?.enterFullscreen() 604 | }, 605 | exitFullscreen() { 606 | return spherePlayerInstance.current?.exitFullscreen() 607 | }, 608 | toggleFullscreen() { 609 | return spherePlayerInstance.current?.toggleFullscreen() 610 | }, 611 | isFullscreenEnabled() { 612 | return spherePlayerInstance.current?.isFullscreenEnabled() 613 | }, 614 | getPlugin>(pluginId: string | PluginConstructor): T { 615 | return spherePlayerInstance.current?.getPlugin(pluginId) as T 616 | }, 617 | getPosition(): Position { 618 | return spherePlayerInstance.current?.getPosition() as Position 619 | }, 620 | getZoomLevel(): number { 621 | return spherePlayerInstance.current?.getZoomLevel() as number 622 | }, 623 | getSize(): Size { 624 | return spherePlayerInstance.current?.getSize() as Size 625 | }, 626 | needsUpdate() { 627 | return spherePlayerInstance.current?.needsUpdate() 628 | }, 629 | autoSize() { 630 | return spherePlayerInstance.current?.autoSize() 631 | }, 632 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 633 | setPanorama(path: any, options?: PanoramaOptions): Promise { 634 | return spherePlayerInstance.current?.setPanorama(path, options) as Promise 635 | }, 636 | showError(message: string) { 637 | return spherePlayerInstance.current?.showError(message) 638 | }, 639 | hideError() { 640 | return spherePlayerInstance.current?.hideError() 641 | }, 642 | startKeyboardControl() { 643 | return spherePlayerInstance.current?.startKeyboardControl() 644 | }, 645 | stopKeyboardControl() { 646 | return spherePlayerInstance.current?.stopKeyboardControl() 647 | }, 648 | }) as ViewerAPI 649 | // Methods 650 | useImperativeHandle(ref, _imperativeHandle, [ 651 | spherePlayerInstance.current, 652 | sphereElement, 653 | options, 654 | ref, 655 | ]) 656 | 657 | return
658 | }) 659 | 660 | ReactPhotoSphereViewer.displayName = "ReactPhotoSphereViewer" 661 | 662 | export { 663 | ReactPhotoSphereViewer 664 | } 665 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* add css styles here (optional) */ 2 | .view-container { 3 | position: relative; 4 | overflow: hidden; 5 | } 6 | 7 | .showNavbarButton { 8 | display: flex; 9 | position: absolute; 10 | justify-content: center; 11 | align-items: center; 12 | cursor: pointer; 13 | z-index: 1000; 14 | 15 | background: rgba(0, 0, 0, 0.09); 16 | bottom: 10px; 17 | height: 30px; 18 | width: 30px; 19 | right: 10px; 20 | 21 | transition: background 0.2s ease, color 0.2s ease; 22 | 23 | &:hover { 24 | background-color: rgba(0, 0, 0, 0.8); 25 | } 26 | } 27 | 28 | .hideNavbarButton svg { 29 | width: 100%; 30 | transform: scale(1); 31 | transition: transform .2s ease; 32 | vertical-align: initial; 33 | margin-top: -2; 34 | 35 | &:hover { 36 | transform: scale(1.2); 37 | } 38 | } -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | /*import ExampleComponent from './' 2 | 3 | describe('ExampleComponent', () => { 4 | it('is truthy', () => { 5 | expect(ExampleComponent).toBeTruthy() 6 | }) 7 | }) 8 | */ -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // Output moderno e compatibile con i bundler 4 | "target": "ESNext", 5 | "module": "ESNext", 6 | 7 | // Librerie supportate 8 | "lib": ["DOM", "ESNext"], 9 | 10 | // JSX React moderno 11 | "jsx": "react-jsx", 12 | 13 | // Risoluzione moduli standard 14 | "moduleResolution": "Node", 15 | "baseUrl": "src", 16 | "rootDir": "src", 17 | 18 | // ⚙️ Output dei tipi 19 | "declaration": true, 20 | "emitDeclarationOnly": true, 21 | "declarationDir": "./dist", 22 | 23 | // Output JS non serve, ma è richiesto 24 | "noEmit": false, 25 | "outDir": "./dist", // richiesto anche se non usato 26 | 27 | // ⚠️ Sicurezza e pulizia 28 | "sourceMap": true, 29 | "strict": true, 30 | "noImplicitReturns": true, 31 | "noImplicitThis": true, 32 | "strictNullChecks": true, 33 | "noUnusedLocals": true, 34 | "noUnusedParameters": true, 35 | 36 | // Interoperabilità 37 | "esModuleInterop": true, 38 | "allowSyntheticDefaultImports": true, 39 | "forceConsistentCasingInFileNames": true 40 | }, 41 | "include": ["src"], 42 | "exclude": ["node_modules", "dist", "example", "build", "rollup.config.js"] 43 | } 44 | --------------------------------------------------------------------------------