-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
37 lines (33 loc) · 925 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var rcom = require('regl-component')
var Nano = require('cache-component')
var Map = require('./lib/map.js')
module.exports = MixMap
function MixMap (regl, opts) {
var self = this
if (!(self instanceof MixMap)) return new MixMap(regl, opts)
Nano.call(self)
if (!opts) opts = {}
self._rcom = rcom(regl, opts)
self._maps = []
window.addEventListener('resize', redraw)
window.addEventListener('scroll', redraw)
function redraw () {
draw()
window.requestAnimationFrame(draw)
}
function draw () {
for (var i = 0; i < self._maps.length; i++) {
self._maps[i].draw()
}
}
}
MixMap.prototype = Object.create(Nano.prototype)
MixMap.prototype._update = function () { return false }
MixMap.prototype._render = function (props) {
return this._rcom.render(props)
}
MixMap.prototype.create = function (opts) {
var m = new Map(this._rcom.create(), opts)
this._maps.push(m)
return m
}