0.1.8 • Published 3 years ago

react-viewer360 v0.1.8

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

React-Viewer360

This is a 360 viewer library inspired by google map's navigation. Using points for each 360 image, the 360 images are placed in a 3D world using XYZ coordinates and the POV travels to each position in transition.

Why

  • Transitions to other 360 images as though flying to it
  • Each 360 image can hold their own markers
  • Each marker can customize sprite, content (with html support) and line from marker to a position (can be used to illustrate pointing to an item)

Installation

npm install react-viewer360 # or yarn add react-viewer360

Usage

Display one 360 image

import Viewer360 from "react-viewer360";

export const App = () => {
  return (
    <Viewer360
      img="./360_1.jpg"
    />
  )
}

Display one 360 image with markers

import Viewer360 from "react-viewer360";
import "react-viewer360/dist/viewer360.css";

export const App = () => {
  return (
    <Viewer360
      img="./360_1.jpg"
      markers={[
        {
          point: [2, 0, 3],
          content: (
            <div>
              An apple product
              <a href="www.apple.com">Apple Store</a>
            </div>
          )
        }
      ]}
    />
  )
}

Display multiple 360 images with markers

import Viewer360 from "react-viewer360";
import "react-viewer360/dist/viewer360.css";

export const App = () => {
  return (
    <Viewer360
      positions={[
        {
          point: { x: 0, y: 0, z: 0 },
          img: "./360_1.jpg",
          label: "Bedroom",
          markers: [
            {
              point: [2, 0, 3],
              content: (
                <div>
                  An apple product
                  <a href="www.apple.com">Apple Store</a>
                </div>
              )
            }
          ]
        },
        {
          point: [1, 0, 0],
          img: './360_2.jpg',
          label: 'Living Room',
          sprite: './sprite_1.png',
        },
        {
          point: [3, 0, 3],
          img: './360_3.jpg',
          label: 'Kitchen',
        },
      ]}
    />
  )
}

Options

PropTypeDefaultDescription
positionsViewer360Position[][]Positions of each 360, along with each 360's settings such as its markers and sprite
imgstringA 360 image. Use this if only displaying one image ever
markersMarker[][]A list of markers for the singular img (only applies to img prop)
dragSpeednumber1The speed when mouse drag screen (ev.movementX * dragSpeed)
autoRotatebooleanfalseFlag for whether screen will auto rotate
autoRotateSpeednumber1If autoRotate true, the speed it'll move per frame
initialCameraRotationView360PointThe initial camera rotation (using XYZ) on first load
pointMarkerSpritestringA marker image to indicate next travel point
markerSpritestringA marker image indicating a marker position
pointMarkerSpriteScalenumber0.2Scale the point marker image
markerSpriteScalenumber0.15Scale the marker image
stylesViewer360Styles{}Styles for each part of the dom layer
hideLabelsbooleanfalseHide all labels (both markers and points)
enableZoombooleantrueEnable zoom in/out on scroll

Ref Functions

zoomDelta(delta: number)

change zoom by delta

goToIndex: (positionIndex: number, duration?: number)

go to position by index

startDrawing()

start drawing loop

stopDrawing()

stop drawing loop

dragDelta(delta: Position2D, speed?: number)

drag the 3D world through 2D screen

Structures

Viewer360Position

point: View360Point;
img: string;
label?: string | React.ReactNode;
markers?: Marker[];
sprite?: string;
spriteScale?: number;

Marker

point: View360Point;
content: string | React.ReactNode;
lineTo?: View360Point;
sprite?: string;
spriteScale?: string;

View360Point

{ x: number; y: number; z: number } | [ number, number, number ]

Viewer360Styles

container?: React.CSSProperties;
pointMarkerLabel?: React.CSSProperties;
pointMarkerLabelHover?: React.CSSProperties;
pointMarkerLabelContent?: React.CSSProperties;
markerLabel?: React.CSSProperties;
markerLabelHover?: React.CSSProperties;
markerLabelContent?: React.CSSProperties;

Styling

Classes to override | ClassName | Position | | --------- | -------- | | .viewer_360_marker_label | Marker's label container| | .viewer_360_marker_label_content | Marker's label content | | .viewer_360_marker_label_hover | Marker's label hover area | | .viewer_360_point_marker_label | Position's label container | | .viewer_360_point_marker_label_content | Position's label content | | .viewer_360_point_marker_label_hover | Position's label hover area |

TODO


  • Define sprite scales
  • Add js styling
  • Define customized transitions

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago