Panorama on web pages

From Publication Station
Jump to navigation Jump to search

Panorama images for the Web can be easily be created using a Equirectangular panorama image.

Here are two ways of doing it using A-frame Mozilla framework for VR and Pannellum a Javascript library for displaying panorama images.


A-Frame is a web framework for building virtual reality experiences. It was started by Mozilla VR to make WebVR content creation easier, faster, and more accessible. It spares you having to use a complex JavaScript libraries like ThreeJS and presents a simple HTML like language to build VR projects.

A-frame allows interaction with rotation sensors and stereo images (for VR goggles) out of the box, without having to write any code

One of the examples that is present in Aframe website is of a Panoranama .

What do you need:

      <a-sky src="puydesancy.jpg" rotation="0 -130 0"></a-sky>

See it running in:

Source code:

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="description" content="Panorama — A-Frame">

    <script src=""></script>

      <a-sky src="Mars.jpg" rotation="0 -130 0"></a-sky>



Pannellum is JavaScript library for displaying and navigate panorama images on web pages. In order to use Pannellum you must:

  • Download Pannellum:
  • Place the downloaded files: pannellum.css, pannellum.htm, pannellum.js in a folder
  • Save a panorama image in the same folder
    • Wikimedia commons is a good source of panoramic images under free licenses
    • Pannellum images with a maximum of 8000px wide, so you might need to resize the panorama image file
  • Use the API example in Pannellum documentation to write your HTML page. An example of the change code can be seen below
  • Set the pannellum.viewer with the settings for your image, most important parameters are:
    • "panorama": defines the image file to use
    • "type": the type of the image: equirectangular, cubemap, or multires
    • A full list of Pannellum parameters and methods can is available in its API documentation

To run it you will need to store the folder with the library, html page and images in webserver.


See live example in

HTML code

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>A simple example</title>
    <link rel="stylesheet" href="pannellum.css"/>
    <script type="text/javascript" src="pannellum.js"></script>

      html {
      height: 100%;

      body {
      margin: 0;
      padding: 0;
      overflow: hidden;
      position: fixed;
      cursor: default;
      width: 100%;
      height: 100%;
      #panorama {
      width: 600px;
      height: 400px;

    <div id="panorama"></div>

     viewer =  pannellum.viewer('panorama', {
      "type": "equirectangular",
      "panorama": "Mars.jpg",
      "autoLoad": true,



Programmatic interaction with the panorama can be achieved by using Pannellum API

  • viewer.getYawBounds() returns the boundaries ( minimum and maximum) allowed pitches (in degrees)
  • viewer.setYaw(10) set Yaw to 10
  • viewer.setYaw(viewer.getYaw()-100) get current yaw and move -100 from it

Example in