1) Hands-on: SPFx Web Part com Photo Sphere Viewer
Aqui vai um esqueleto mínimo de Web Part SPFx que integra o Photo Sphere Viewer (PSV) com o adaptador equiretangular e o plugin de marcadores.
Passo 1 – Instalação
No projeto SPFx já criado:
npm install @photo-sphere-viewer/core @photo-sphere-viewer/equirectangular-adapter @photo-sphere-viewer/markers-plugin three
Passo 2 – Código da Web Part
360ViewerWebPart.ts
import { Version } from '@microsoft/sp-core-library';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import { SPComponentLoader } from '@microsoft/sp-loader';
import { Viewer } from '@photo-sphere-viewer/core';
import { EquirectangularAdapter } from '@photo-sphere-viewer/equirectangular-adapter';
import { MarkersPlugin } from '@photo-sphere-viewer/markers-plugin';
export interface I360ViewerWebPartProps {
imageUrl: string;
}
export default class Viewer360WebPart extends BaseClientSideWebPart<I360ViewerWebPartProps> {
private viewer: Viewer | undefined;
public render(): void {
this.domElement.innerHTML = `
<div id="psv-container" style="width:100%;height:500px;"></div>
`;
const container = this.domElement.querySelector('#psv-container') as HTMLElement;
this.viewer = new Viewer({
container,
adapter: EquirectangularAdapter,
panorama: this.properties.imageUrl ||
'https://example.com/pano-sample.jpg',
navbar: ['zoom', 'fullscreen'],
plugins: [
[MarkersPlugin, {
markers: [
{
id: 'marker-1',
position: { yaw: '45deg', pitch: '10deg' },
image: 'https://cdn-icons-png.flaticon.com/512/25/25694.png',
size: { width: 32, height: 32 },
tooltip: 'Machine 01'
}
]
}]
]
});
}
protected onDispose(): void {
if (this.viewer) {
this.viewer.destroy();
this.viewer = undefined;
}
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
}
Isso já monta um viewer funcional dentro de uma página do SharePoint, permitindo abrir imagens 360° hospedadas em qualquer biblioteca/documento.
Photo Sphere Viewer in SPFx: Quick Integration Guide
- Library: Photo Sphere Viewer is a modular JavaScript library built on top of Three.js for rendering equirectangular and cubemap panoramas, as well as 360° video.
- Adapters: select how textures are projected (sphere or cube).
- Plugins: add interactive features like markers, maps, plans, compass, and even virtual tours.
- SPFx integration:
- Install
@photo-sphere-viewer/coreand chosen adapter/plugins. - Render into a
divinsiderender()of your Web Part. - Use
onDispose()to callviewer.destroy().
- Install
- Use cases: Digital twins, training portals, interactive site tours, facility maintenance overlays.
- Alternatives: Pannellum (lightweight), Marzipano (toolchain), A-Frame (VR/3D scenes).
Summary Table
| Feature | How it Works in PSV | Why it Matters |
|---|---|---|
| Rendering | WebGL via Three.js | Hardware-accelerated 360° viewing |
| Formats | Equirectangular & Cubemap | Flexibility depending on capture pipeline |
| Plugins | Markers, Compass, Map, Plan, Virtual Tour | Build interactive tours with metadata |
| SPFx Integration | Import via npm, mount in render(), dispose on teardown | Native SharePoint support |
| License | MIT | Free for commercial use |
