Scene.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { __rest } from "tslib";
  2. import { jsx as _jsx } from "react/jsx-runtime";
  3. import { useContext, useEffect } from "react";
  4. import { CurrentSceneContext, KrpanoRendererContext } from "../contexts";
  5. import { buildXML } from "../utils";
  6. export const Scene = ({ name, previewUrl, imageTagAttributes, images = [], content, children, }) => {
  7. const renderer = useContext(KrpanoRendererContext);
  8. const currentScene = useContext(CurrentSceneContext);
  9. useEffect(() => {
  10. const contentImageMeta = {
  11. tag: "image",
  12. // @ts-ignore
  13. attrs: imageTagAttributes,
  14. children: [],
  15. };
  16. // multires
  17. if (images.length > 1) {
  18. contentImageMeta.children.push(...images.map((_a) => {
  19. var { tiledImageWidth, tiledImageHeight } = _a, img = __rest(_a, ["tiledImageWidth", "tiledImageHeight"]);
  20. const imgXML = {
  21. tag: "level",
  22. attrs: {
  23. tiledImageWidth,
  24. tiledImageHeight,
  25. },
  26. children: [
  27. {
  28. tag: imageTagAttributes.type,
  29. attrs: Object.assign({}, img),
  30. },
  31. ],
  32. };
  33. return imgXML;
  34. }));
  35. }
  36. else if (images.length === 1) {
  37. const img = __rest(images[0], []);
  38. contentImageMeta.children.push({
  39. tag: imageTagAttributes.type,
  40. attrs: Object.assign({}, img),
  41. });
  42. }
  43. renderer === null || renderer === void 0 ? void 0 : renderer.setTag("scene", name, {
  44. content: content ||
  45. `${previewUrl ? `<preview url="${previewUrl}" />` : ""}${images.length > 0 ? buildXML(contentImageMeta) : ""}`,
  46. });
  47. return () => {
  48. renderer === null || renderer === void 0 ? void 0 : renderer.removeScene(name);
  49. };
  50. }, [renderer, name, images, imageTagAttributes, content, previewUrl]);
  51. return _jsx("div", { className: "scene", children: currentScene === name ? children : null });
  52. };