Cloudimage 360 View

repository·master·Indexed 24 days ago

https://github.com/scaleflex/cloudimage-360-view

A JavaScript library for creating interactive, high-performance 360-degree product views for e-commerce and virtual tours. It supports single-axis, dual-axis (X/Y), and 2D grid rotation modes. The library includes a React wrapper (@cloudimage/360-view/react) with a CI360Viewer component, a useCI360 hook, and support for interactive hotspots with navigation and custom themes. Version 4.10.0.

Tokens
16.9K
Snippets
34
Records
73
Agent score
84%

What's inside Cloudimage 360 View

  1. How 2D Grid Mode works

    master

    2D Grid Mode is used for products photographed at multiple horizontal and vertical angles. It is automatically detected when you provide filenameGrid or imageListGrid. In this mode, dragging diagonally updates both axes simultaneously.

    Using a filename pattern

    Use filenameGrid with {indexX} and {indexY} placeholders (1-based indices). You can use indexZeroBase to specify zero-padding (e.g., 3 for 001). Use stopAtEdgesX or stopAtEdgesY to prevent looping on a specific axis.

    Using an explicit image list

    Alternatively, provide a flat array of image strings via imageListGrid. The images should be ordered by row (all X frames for the first Y angle, then all X frames for the second Y angle, etc.).

    // Example: Filename pattern
    CI360.init(document.getElementById('viewer'), {
      folder: 'https://your-domain.com/images/',
      filenameGrid: 'product_{indexY}_{indexX}.jpg',
      amountX: 24,        // horizontal angles
      amountY: 4,         // vertical angles
      indexZeroBase: 3,    // zero-pad to 3 digits: 001, 002, ...
      stopAtEdgesY: true,  // prevent Y from looping
    });
    
    // Example: Explicit image list
    CI360.init(document.getElementById('viewer'), {
      imageListGrid: [
        // y=0 row (all X frames at first vertical angle)
        'img_001_001.jpg', 'img_001_002.jpg', /* ... */
        // y=1 row
        'img_002_001.jpg', 'img_002_002.jpg', /* ... */
      ],
      amountX: 24,
      amountY: 4,
    });
  2. Optimize for Mobile Devices

    master

    Mobile browsers have strict memory limits. While the library automatically enables several optimizations for mobile (sequential loading, main-thread canvas rendering, reduced touch rate, capped pixel ratio, and automatic memory management), you should manually adjust your configuration for the best experience.

    • amountX: Limit to 30-40 frames (Desktop can handle 60-100+).
    • zoomMax: Limit to 2-3 (Desktop can handle 3-5).

    Manual Memory Management

    You can manually control the IntersectionObserver based memory management (which releases memory when viewers are off-screen or the page is backgrounded) using:

    • viewer.enableMemoryManagement()
    • viewer.disableMemoryManagement()
    const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
      navigator.userAgent
    );
    
    const viewer = new CI360();
    viewer.init(container, {
      folder: 'https://example.com/images/',
      filenameX: '{index}.jpg',
      amountX: isMobile ? 36 : 72,           // Fewer images on mobile
      zoomMax: isMobile ? 2 : 5,             // Lower zoom on mobile
    });
  3. Set Hotspot Marker Themes

    master

    You can control the visual appearance of hotspot markers globally via the viewer configuration or individually per hotspot using the markerTheme property.

    Available Themes:

    • 'default': Light marker on light backgrounds.
    • 'inverted': Dark marker that blends with dark backgrounds.
    • 'brand': Uses the brandColor as the marker accent color.

    To use the 'brand' theme, you must provide a brandColor in your configuration.

    // Viewer-level theme
    const config = {
      hotspots: [...],
      markerTheme: 'inverted', // 'default', 'inverted', or 'brand'
      brandColor: '#ff6600',   // Used when markerTheme is 'brand'
    };
    
    // Per-hotspot theme override
    const hotspots = [
      {
        id: 'highlight',
        markerTheme: 'brand', // Override for this hotspot only
        positions: { 0: { x: 500, y: 300 } },
        content: '<div class="Highlighted feature"></div>',
      },
    ];
  4. Style the Viewer with CSS Variables

    master

    The recommended way to customize the viewer's appearance (buttons, icons, spinners, zoom controls, etc.) is through CSS variables. You can apply these globally via :root or scope them to a specific viewer instance by targeting its ID or class.

    /* Global customization */
    :root {
      --ci360-button-bg: #f0f0f0;
      --ci360-icon-color: #37414b;
      --ci360-hotspot-color: #00aaff;
    }
    
    /* Scoped customization */
    #my-special-viewer {
      --ci360-button-bg: #4a90d9;
      --ci360-hotspot-color: #ff6b6b;
    }
  5. Configure CI360Viewer for Next.js (SSR)

    master

    Because the viewer relies on browser APIs, you must use next/dynamic with ssr: false to prevent errors during server-side rendering in Next.js applications.

    import dynamic from 'next/dynamic';
    import '@cloudimage/360-view/css';
    
    const CI360Viewer = dynamic(
      () => import('@cloudimage/360-view/react').then(mod => mod.CI360Viewer),
      { ssr: false }
    );
    
    export default function ProductPage() {
      return (
        <CI360Viewer
          folder="https://example.com/images/"
          filenameX="{index}.jpg"
          amountX={36}
        />
      );
    }
  6. Quick Start with Cloudimage 360 View

    master

    To get started immediately without a build step, use the CDN version. You can create a viewer by adding a div with the cloudimage-360 class and specifying your image folder and filename patterns via data- attributes. Then, initialize the viewer using window.CI360().initAll().

    <!-- Add the library (CSS is auto-injected) -->
    <script src="https://cdn.cloudimage.io/360-view/4.10.0/360-view.min.js"></script>
    
    <!-- Create a container with data attributes -->
    <div
      class="cloudimage-360"
      data-folder="https://scaleflex.cloudimg.io/v7/demo/360-car/"
      data-filename-x="car-{index}.jpg"
      data-amount-x="36"
    ></div>
    
    <!-- Initialize -->
    <script>
      const viewer = new window.CI360();
      viewer.initAll();
    </script>
  7. Create Navigation Hotspots

    master

    Hotspots can act as navigation pins to link between different scenes. By adding the navigateTo property to a hotspot, it becomes a link to a specific sceneId. These hotspots display a directional arrow icon. Use arrowDirection (in degrees) to rotate the arrow; the default is 0 (pointing right).

    const hotspots = [
      {
        id: 'go-to-interior',
        navigateTo: 'interior-scene',
        label: 'View Interior',
        arrowDirection: 90, // Point downward (default is right)
        positions: { 10: { x: 600, y: 400 } },
        // ...
      },
    ];
    
    const config = {
      hotspots,
      onNavigate: (sceneId) => {
        // Handle scene transition
        console.log(`Navigate to: ${sceneId}`);
      },
    };
  8. Migrate from v3 to v4

    master

    Upgrading to v4 involves several breaking changes in CSS, initialization, and configuration.

    1. CSS Handling

    • CDN users: CSS is auto-injected.
    • npm/bundler users: You must now import CSS explicitly: import '@cloudimage/360-view/css';

    2. Initialization API

    Switch from the global window.CI360 methods to the instance-based new CI360() pattern.

    3. Deprecated Options Mapping

    v3 Optionv4 Alternative
    data-box-shadowUse CSS: .cloudimage-360 { box-shadow: ... }
    data-ratioContainer automatically maintains aspect ratio
    data-lazy-selectorUse data-lazyload (boolean)
    data-hide-360-logoUse data-initial-icon (boolean, inverted)
    data-disable-dragUse data-draggable (inverted: draggable="false")
    data-spin-reverseUse data-drag-reverse and data-autoplay-reverse

    4. Hotspot Configuration

    Hotspots no longer use individual properties like title or description. Instead, use the content property to provide flexible HTML.

    v4 Hotspot Example:

    const hotspot = {
      id: 'feature-1',
      orientation: 'x',
      containerSize: [1200, 800],
      positions: { 0: { x: 100, y: 200 } },
      content: `
        <div class="my-tooltip">
          <h3 class="title">Feature Title</h3>
          <p>Description text</p>
          <a href="https://example.com" target="_blank">Learn More</a>
        </div>
      `,
      onClick: () => console.log('Clicked!'),
    };
  9. Integrate with Cloudimage CDN

    master

    You can enhance performance and image optimization by using the Cloudimage CDN. To set this up, register at cloudimage.io to obtain a token, then include the ciToken in your viewer configuration.

    Benefits:

    • Automatic WebP/AVIF conversion.
    • Responsive image delivery.
    • Global CDN performance.
    • On-the-fly image transformations (resize, crop, filters).
    const config = {
      folder: 'https://your-domain.com/images/',
      filenameX: '{index}.jpg',
      amountX: 36,
      ciToken: 'your-cloudimage-token', // or use data-responsive attribute
    };
  10. Install Cloudimage 360 View via Package Manager

    master

    For modern web development workflows, install the library using npm, yarn, or pnpm. After installation, you must import both the core library and the CSS file.

    # npm
    npm install @cloudimage/360-view
    
    # yarn
    yarn add @cloudimage/360-view
    
    # pnpm
    pnpm add @cloudimage/360-view
    
    # Then import in your JavaScript
    import CI360 from '@cloudimage/360-view';
    import '@cloudimage/360-view/css';
  11. Configure Hotspots

    master

    Hotspots allow you to add interactive markers to highlight specific product features. You define an array of hotspot objects and pass it to the hotspots key in your configuration.

    Key behaviors:

    • Positioning: Use containerSize (e.g., [1200, 800]) to provide reference dimensions for pixel-based positions. If omitted, positions are treated as percentages (0-100) of the image area.
    • Frame Mapping: The positions object maps frame indices to { x, y } coordinates. Setting a coordinate to null causes it to inherit the value from the previous frame.
    • Interactivity: You can provide HTML content for a tooltip and an onClick handler.
    const hotspots = [
      {
        id: 'feature-1',
        orientation: 'x',
        containerSize: [1200, 800], // Reference container size for positioning
        positions: {
          0: { x: 500, y: 300 },
          1: { x: 520, y: 300 },
          2: { x: 540, y: null }, // null inherits from previous frame
          3: { x: 560, y: null },
          // ... positions for frames where hotspot is visible
        },
        content: '<div class="tooltip"><strong>Premium Feature</strong><p>Description here</p></div>',
        onClick: () => {
          console.log('Hotspot clicked!');
        },
      },
    ];
    
    const config = {
      folder: 'https://example.com/images/',
      filenameX: '{index}.jpg',
      amountX: 36,
      hotspots: hotspots,
    };