# mapbox-gl-camera

> Camera helper for WebGL custom layers on top of mapbox-gl-js

Latest version **1.0.4** (published 2018-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install mapbox-gl-camera
pnpm add mapbox-gl-camera
yarn add mapbox-gl-camera
bun add mapbox-gl-camera
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-12-16 |
| First published | 2018-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Dawid Górny |
| Maintainers | dawidgorny |
| Keywords | mapbox, regl, 3d, webgl |

## Links

- npm: https://www.npmjs.com/package/mapbox-gl-camera
- Repository: https://github.com/dawidgorny/mapbox-gl-camera
- Issues: https://github.com/dawidgorny/mapbox-gl-camera/issues
- npm.io page: https://npm.io/package/mapbox-gl-camera

## Dependencies (1)

- [gl-mat4](https://npm.io/package/gl-mat4.md) ^1.2.0

## Recent versions

- 1.0.4 (latest) — 2018-12-16

## README

# mapbox-gl-camera

Camera helper for WebGL custom layers on top of [mapbox-gl-js](https://github.com/mapbox/mapbox-gl-js).

**WIP**, check Issues

## Installation

```
npm install mapbox-gl-camera
```

## Usage

```
import { Camera } from 'mapbox-gl-camera';

const camera = new Camera();

// ...

mapInstance.on('style.load', () => {
  mapInstance.addLayer({
    id: 'custom_layer',
    type: 'custom',
    onAdd: function (map, gl) {
      // ...
    },
    render: function (gl, matrix) {
      camera.update(mapInstance, matrix);

      camera.view;            // <-- view matrix
      camera.projection;      // <-- projection matrix
      camera.viewProjection;  // <-- projection*view matrix
      camera.world;           // <-- world matrix

      camera.positionFromLngLatAlt([13.418314, 52.49871, 10]) // calculates world position from LngLatAlt coordinates

      mapInstance.triggerRepaint();
    }
  });
});

```


## Example

### Using [regl](https://github.com/regl-project/regl)
![examples/example-regl.gif](examples/example-regl.gif)

source: [examples/regl.js](examples/regl.js)

#### Building the example
```
MAPBOX_TOKEN=your_mapbox_access_token npm run watch
```

## References
 * https://github.com/mapbox/mapbox-gl-js/issues/7395
 * https://github.com/mapbox/mapbox-gl-js/issues/7268
 * https://github.com/peterqliu/threebox

MIT License

---
_Source: https://npm.io/package/mapbox-gl-camera · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
