Skip to content

Commit faa13ba

Browse files
committed
Merge pull request #5 from amenadiel/canvasrenderer
Canvas Renderer
2 parents 0b113d6 + 8e73273 commit faa13ba

File tree

3 files changed

+22229
-20865
lines changed

3 files changed

+22229
-20865
lines changed

examples/index.html

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424

2525
function init() {
2626

27-
if (!Detector.webgl) {
28-
Detector.addGetWebGLMessage();
29-
return;
30-
}
31-
3227
var container = document.getElementById('map-div');
3328

3429
var map = new google.maps.Map(container, {
@@ -39,8 +34,33 @@
3934
styles: styles
4035
});
4136

37+
// if you add renderertype:'Canvas' to the options for ThreejsLayer, you can force the usage of CanvasRenderer
4238
new ThreejsLayer({ map: map }, function(layer){
4339

40+
if (layer.renderertype=='Canvas' || !Detector.webgl) {
41+
texture = new THREE.Texture(generateSprite());
42+
particles = new THREE.Object3D();
43+
material = new THREE.SpriteMaterial({
44+
size: 20,
45+
map: texture,
46+
opacity: 1,
47+
blending: THREE.NormalBlending,
48+
depthTest: false,
49+
transparent: true
50+
});
51+
52+
53+
photos.forEach(function (photo) {
54+
var particle = new THREE.Sprite(material);
55+
var location = new google.maps.LatLng(photo[0], photo[1]),
56+
vertex = layer.fromLatLngToVertex(location);
57+
58+
particle.position.set(vertex.x, vertex.y, 0);
59+
particle.scale.x = particle.scale.y = 20;
60+
particles.add(particle);
61+
material.size = 20;
62+
});
63+
} else {
4464
var geometry = new THREE.Geometry(),
4565
texture = new THREE.Texture(generateSprite()),
4666
material, particles;
@@ -64,11 +84,13 @@
6484
});
6585

6686
particles = new THREE.ParticleSystem( geometry, material );
87+
}
6788
layer.add( particles );
6889

6990
gui = new dat.GUI();
7091

7192
function update(){
93+
if (layer.renderertype=='Canvas' || !Detector.webgl) material.map = new THREE.Texture(generateSprite(material.size));
7294
layer.render();
7395
}
7496

@@ -78,14 +100,14 @@
78100
});
79101
}
80102

81-
function generateSprite() {
103+
function generateSprite(size) {
82104

83105
var canvas = document.createElement('canvas'),
84106
context = canvas.getContext('2d'),
85107
gradient;
86-
87-
canvas.width = 20;
88-
canvas.height = 20;
108+
size = size || 20;
109+
canvas.width = size;
110+
canvas.height = size;
89111

90112
gradient = context.createRadialGradient(
91113
canvas.width / 2, canvas.height / 2, 0,

0 commit comments

Comments
 (0)