Giter Club home page Giter Club logo

google-panorama-equirectangular's Introduction

google-panorama-equirectangular

experimental

2d

webgl demo - source

Stitches Google Street View and Photo Sphere tiles into an equirectangular image. For use in the browser, with Webpack or Browserify.

Also includes an intermediate mode for higher quality WebGL rendering on low-end devices.

Install

npm install google-panorama-equirectangular

Example

For full examples, see the demo/ folder, or running from source for details.

Make sure to include the Google Client library first:

  <script src="http://maps.google.com/maps/api/js?sensor=false"></script>

Then, in JavaScript:

var load = require('google-panorama-equirectangular')
var panoID = 'dXZfBMex9_L7jO2JW3FTdA'

load(panoID, { zoom: 2 })
  .on('start', function (data) {
    console.log('canvas size: ', data.width, data.height)
  })
  .on('progress', function (ev) {
    console.log('progress: ', ev.count / ev.total)
  })
  .on('complete', function (image) {
    document.body.appendChild(image)
    console.log('canvas image: ', image)
  })

Usage

NPM

emitter = load(id, [opt])

Creates a new StreetView stitcher with id and optional settings. opt can be:

  • zoom an integer between 0 and 5 (inclusive), defaults to 1
  • canvas a HTMLCanvasElement to re-use, defaults to creating a new element
  • tiles is the tile dimensions from getPanoramaByLocation or getPanoramaById, defaults to assuming StreetView image dimensions
  • crossOrigin crossOrigin String for image loading, defaults to undefined

Here is an example using google-panorama-by-id.

It's recommended you specify tiles for an accurate result across different image types (panorama, photo sphere, etc).

var load = require('google-panorama-equirectangular')
var panoData = require('google-panorama-by-id')
var id = 'dXZfBMex9_L7jO2JW3FTdA'

panoData(id, function (err, result) {
  var tiles = result.tiles
  load(id, { tiles: tiles, zoom: 2, canvas: myCanvas })
})

events

emitter.on('start', fn)

Called when the stitching process begins, with data parameter that includes the output of google-panorama-tiles:

{
  columns: Number,    // x tile count
  rows: Number,       // y tile count
  tileWidth: Number,  // tile size
  tileHeight: Number, // tile size
  width: Number,      // canvas size
  height: Number      // canvas size
}

emitter.on('progress', fn)

Called after a new tile has been loaded and drawn to the canvas.

{
  count: Number,    // current # of tiles loaded
  total: Number,    // total number of tiles
  image: Number,    // an image for this tile, might be null
  position: [x, y], // the pixel position of the tile in the full image
}

In intermediate mode, the image might be an Image or a Canvas, depending on crop.

emitter.on('not-found', fn)

Called when an image is skipped due to it not being found. The url is passed.

emitter.on('complete', fn)

Called when the stitching is complete. The resulting canvas is passed as the parameter.

In intermediate mode, no parameters are passed to the function.

Intermediate Mode

The default export stitches all tiles into a single Canvas element. This is convenient, but not ideal for low-end devices like iOS Safari. In some browsers, there is a maximum size for canvas elements, and no way to query this value.

For example, in a 256MB RAM iPhone, the full canvas size must be less than 1024 * 1024 * 3 (3 MP).

WebGL applications can leverage "intermediate rendering" mode which keeps no more than a single 512x512 canvas in memory at a time. This allows higher quality panoramas to be stitched on low-end devices. The interface is the same, and can be required like this:

var equirect = require('google-panorama-equirectangular/intermediate')

You will need to stitch and upload sub-images yourself to WebGL. See demo/gpu.js for an example.

Running From Source

To run the demos from source:

git clone https://github.com/mattdesl/google-panorama-equirectangular.git
cd google-panorama-equirectangular
npm install

Now run one of the demos:

# the simple WebGL demo
npm run webgl

# the simple 2D DOM demo
npm run 2d

# the GPU stitching demo
npm run gpu

And open http://localhost:9966/. Changing the source will re-load the browser page.

Also See

Credits

Thanks to @thespite's prior work on PanomNom.js, which was used as a reference while building these modules.

License

MIT, see LICENSE.md for details.

google-panorama-equirectangular's People

Contributors

mattdesl avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.