This repository has been archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (54 loc) · 1.44 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var mixtiles = require('mixmap-tiles')
var tilexhr = require('mixmap-tiles/xhr')
var createMesh = require('earth-mesh')
var zoomTo = require('mixmap-zoom')
module.exports = Map
function Map (mix, opts) {
if (!(this instanceof Map)) return new Map(mix, opts)
if (!opts) opts = {}
this.map = mix.create()
this.tiles = mixtiles(this.map, {
layers: opts.layers || [],
path: opts.path,
load: tilexhr
})
this.draw = {}
this.draw.triangle = this.map.createDraw({
frag: `
void main () {
gl_FragColor = vec4(1,0,0,0.2);
}
`,
uniforms: {
zindex: 100
},
blend: {
enable: true,
func: { src: 'src alpha', dst: 'one minus src alpha' }
},
attributes: {
position: this.map.prop('positions')
},
elements: this.map.prop('cells')
})
}
Map.prototype.display = function (geometry) {
var mesh = createMesh(geometry)
this.draw.triangle.props = [mesh.triangle]
this.map.draw()
var bbox = [180,90,-180,-90]
for (var i = 0; i < mesh.triangle.positions.length; i++) {
bbox[0] = Math.min(bbox[0], mesh.triangle.positions[i][0])
bbox[1] = Math.min(bbox[1], mesh.triangle.positions[i][1])
bbox[2] = Math.max(bbox[2], mesh.triangle.positions[i][0])
bbox[3] = Math.max(bbox[3], mesh.triangle.positions[i][1])
}
zoomTo(this.map, {
viewbox: bbox,
duration: 500,
padding: 1
})
}
Map.prototype.render = function (opts) {
return this.map.render(opts)
}