Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Can't find the right way to manage the Plugins Methods #6

Closed
Elius94 opened this issue Sep 12, 2022 · 4 comments
Closed

Can't find the right way to manage the Plugins Methods #6

Elius94 opened this issue Sep 12, 2022 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Elius94
Copy link
Owner

Elius94 commented Sep 12, 2022

import "./styles.css";
import {
  ReactPhotoSphereViewer,
  MarkersPlugin
} from "react-photo-sphere-viewer";
import React from "react";

function App() {
  //const photoSphereRef = React.createRef();
  const [markersManager, setMarkerManager] = React.useState();
  const pSRef = React.useCallback((node) => {
    const markersPlugs = node?.getPlugin(MarkersPlugin);
    setMarkerManager(markersPlugs);
  }, []);

  React.useEffect(() => {
    if (markersManager) {
      console.log(markersManager);
    }
  }, [markersManager]);

  const plugins = [
    [
      MarkersPlugin,
      {
        // list of markers
        markers: [
          {
            // image marker that opens the panel when clicked
            id: "image",
            longitude: 0.33,
            latitude: 0.1,
            image: "pin-blue.png",
            width: 32,
            height: 32,
            anchor: "bottom center",
            tooltip: "Mountain peak. <b>Click me!</b>"
          },
          {
            // image marker rendered in the 3D scene
            id: "imageLayer",
            imageLayer: "drone.png",
            width: 220,
            height: 220,
            longitude: 13.5,
            latitude: -0.1,
            tooltip: "Image embedded in the scene"
          }
        ]
      }
    ]
  ];

  const handleClick = (data) => {
    console.log(data);
  };

  return (
    <div className="App">
      <ReactPhotoSphereViewer
        ref={pSRef}
        src="Test_Pano.jpg"
        height={"100vh"}
        width={"100%"}
        littlePlanet={false}
        onClick={handleClick}
        plugins={plugins}
      ></ReactPhotoSphereViewer>
    </div>
  );
}

export default App;

It's currently difficult to manage the marker plugins methods.

@Elius94 Elius94 added the help wanted Extra attention is needed label Sep 12, 2022
@Elius94
Copy link
Owner Author

Elius94 commented Sep 12, 2022

@aziez
Copy link

aziez commented Sep 27, 2022

how to implmenets on Next.js,,,

I Tray but have an error Cannot use import statement outside a module

@Elius94
Copy link
Owner Author

Elius94 commented Sep 27, 2022

how to implmenets on Next.js,,,

I Tray but have an error Cannot use import statement outside a module

Hi! Can you show me your implementation?

@Elius94 Elius94 mentioned this issue Dec 21, 2022
Elius94 added a commit that referenced this issue Dec 21, 2022
Elius94/issue14

Now The library is based on the [psv](https://github.com/mistic100/Photo-Sphere-Viewer)  version 5.0.0.

## Library Version
Original Wrapped Library: [PhotoSphereViewer](https://github.com/mistic100/Photo-Sphere-Viewer) Version: 5.0.0 [<font color="green">**NEW**</font>]
Now the component version is composed by the semantic version of the wrapper and the version of the original library. For example, the current version is 2.1.4-psv5.0.0. This means that the wrapper is in version 2.1.4 and the original library [psv](https://github.com/mistic100/Photo-Sphere-Viewer) is in version 5.0.0.

#### Calling plugin methods and handling events from outside the component [**NEW**](#6)

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.

```jsx
const handleReady = (instance) => {
  const markersPlugs = instance.getPlugin(MarkersPlugin);
  if (!markersPlugs)
    return;
  markersPlugs.addMarker({
    id: "imageLayer2",
    imageLayer: "drone.png",
    size: { width: 220, height: 220 },
    position: { yaw: '130.5deg', pitch: '-0.1deg' },
    tooltip: "Image embedded in the scene"
  });
  markersPlugs.addEventListener("select-marker", () => {
    console.log("asd");
  });
}

return (
  <div className="App">
    <ReactPhotoSphereViewer src="Test_pano.jpg" plugins={plugins} height={'100vh'} width={"100%"} onReady={handleReady}></ReactPhotoSphereViewer>
  </div>
);
```
@Elius94
Copy link
Owner Author

Elius94 commented Dec 21, 2022

import "./styles.css";
import {
  ReactPhotoSphereViewer,
  MarkersPlugin
} from "react-photo-sphere-viewer";
import React from "react";

function App() {
  const pSRef = React.createRef();

  const handleReady = (instance) => {
    const markersPlugs = instance.getPlugin(MarkersPlugin);
    if (!markersPlugs) return;
    console.log(markersPlugs);
    markersPlugs.addMarker({
      id: "imageLayer2",
      imageLayer: "drone.png",
      size: { width: 220, height: 220 },
      position: { yaw: "130.5deg", pitch: "-0.1deg" },
      tooltip: "Image embedded in the scene"
    });
    markersPlugs.addEventListener("select-marker", () => {
      console.log("asd");
    });
  };

  const plugins = [
    [
      MarkersPlugin,
      {
        // list of markers
        markers: [
          {
            // image marker that opens the panel when clicked
            id: "image",
            position: { yaw: "0.33deg", pitch: "0.1deg" },
            image: "pin-blue.png",
            anchor: "bottom center",
            size: { width: 32, height: 32 },
            tooltip: "Mountain peak. <b>Click me!</b>"
          },
          {
            // image marker rendered in the 3D scene
            id: "imageLayer",
            imageLayer: "drone.png",
            size: { width: 220, height: 220 },
            position: { yaw: "13.5deg", pitch: "-0.1deg" },
            tooltip: "Image embedded in the scene"
          }
        ]
      }
    ]
  ];

  const handleClick = (data) => {
    console.log(data);
  };

  return (
    <div className="App">
      <ReactPhotoSphereViewer
        ref={pSRef}
        src="Test_Pano.jpg"
        height={"100vh"}
        width={"100%"}
        littlePlanet={false}
        onClick={handleClick}
        onReady={handleReady}
        plugins={plugins}
      ></ReactPhotoSphereViewer>
    </div>
  );
}

export default App;

@Elius94 Elius94 closed this as completed Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants