mpetroff/pannellum

Viewer.removeHotSpot

Closed this issue · 3 comments

The documentation is quite unclear what the id in the parameter of removeHotSpot exactly is. I used an example to create a config file where hotSpots do not had an id and the id seems to be an interally unused attribute.

To get the hotspots, they can be queried from getConfig and accessing the scenes. This is okay but by doing so, you are aware that hotSpots is an iteratable / array. If hotSpots do not have an Attribte "id" they can not be removed and addHotSpot is not generating an id. The API-user has to take care of unique ids.

I see two solutions. The easy one would be to call remove with index of hotspot, which is not as stupid as it sounds, because querying hotSpots would require to access the array either. An alternative would be to generate an GUID in addHotSpot, but this gets difficult if users create config files with external applications or by hand.

My favorit suggestion

  1. removeHotSpot with index of hotSpot in the scene, or
  2. hint in removeHotSpot documentation that this requires, that hotSpots have an unique id (or that the first occurance of that id will be deleted, or
  3. addHotSpot provides GUID and will be used during json loading as well

the id seems to be an interally unused attribute.

The API-user has to take care of unique ids.

Exactly. It's not used internally, which is why it's left to the API user to manage.

Following your second suggestion, I added additional clarification; let me know if you have additional suggests for improving the description. For the reason above, I'd prefer to not manage IDs, and your other two suggestions are API-breaking changes.

I agree, but if it is totally suffiecient to document this. Another thought: You could add an optional Argument to addHotSpot for the id which is undefined as default. It would not break API, but API user will see there, that they should think about the issue.

Bye the way: I have developed a first version of an Unity player for VR and non-VR that reads the pannellum config and assets. Is that maybe later of interest?

If someone else runs into this:

I ran into this problem today, I solved it by modifying the loaded .json for a panorama or tour before initializing it into the viewer.

// Loop through each scene and assign an 'id' to each hotspot based on its index
    for (let sceneKey in data.scenes) {
      if (data.scenes.hasOwnProperty(sceneKey)) {
        let scene = data.scenes[sceneKey];
        if (scene.hotSpots && Array.isArray(scene.hotSpots)) {
          scene.hotSpots.forEach((hotspot, index) => {
            hotspot.id = index; // Assign 'id' property as the array index
          });
        }
      }
    }