hoaiduyit / react-pannellum

46 stars 38 forks source link

Difficulties with creating multiple panoramas. #98

Open jurtomasz13 opened 1 year ago

jurtomasz13 commented 1 year ago

Changes made in PR: #97

Currently all API methods refers to the last panorama object since the package doesn't store every viewer. It makes it hard to control multiple panoramas because you can't rely on API. I made changes so every viewer is now stored and added to the list that can be retrieved by calling getViewers(). Viewers are added to the list sequentially so it's the best if you create Panoramas in similar order so it can be easily accessed by index. It will look something like this:

import { getViewers } from "react-pannellum";

const Panorama = ({id}) => {
  React.useEffect(() => {
    const currentViewer = getViewers()[id];
    console.log(currentViewer);
    // currentViewer now contains every method that is documented in https://pannellum.org/documentation/api/#viewer
    // and now you can use it separately for every panorama :)
  }, [(dependencies)]);

  return (
    <ReactPannellum
      id={panoramaId} // don't confuse this with id from index, it must be string 
      type="multires"
      multiRes={multiRes_}
      config={config_}
      style={style_}
    />)
}

const activePanoramas = (arrayHere).map(
  (item, index) => {
    return (
      <Panorama
        key={`panorama_key_${index}`}
        id={index} // Number
      />
    );
  }
);

If you don't list panoramas by map and use it separately then you will have to statically type index.

hoaiduyit commented 1 year ago

Hi @jurtomasz13 , I added some comments in your PR, please check.

jurtomasz13 commented 1 year ago

Hi @jurtomasz13 , I added some comments in your PR, please check.

Hi @hoaiduyit, I don't see the comments, however after reviewing a PR I found out that I accidentally left changed link to repository which was set to my fork, so I fixed it.

hoaiduyit commented 1 year ago

Hi @jurtomasz13 , I added a comment, please check again.