|
24 | 24 |
|
25 | 25 | function init() {
|
26 | 26 |
|
27 |
| - if (!Detector.webgl) { |
28 |
| - Detector.addGetWebGLMessage(); |
29 |
| - return; |
30 |
| - } |
31 |
| - |
32 | 27 | var container = document.getElementById('map-div');
|
33 | 28 |
|
34 | 29 | var map = new google.maps.Map(container, {
|
|
39 | 34 | styles: styles
|
40 | 35 | });
|
41 | 36 |
|
| 37 | + // if you add renderertype:'Canvas' to the options for ThreejsLayer, you can force the usage of CanvasRenderer |
42 | 38 | new ThreejsLayer({ map: map }, function(layer){
|
43 | 39 |
|
| 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 { |
44 | 64 | var geometry = new THREE.Geometry(),
|
45 | 65 | texture = new THREE.Texture(generateSprite()),
|
46 | 66 | material, particles;
|
|
64 | 84 | });
|
65 | 85 |
|
66 | 86 | particles = new THREE.ParticleSystem( geometry, material );
|
| 87 | + } |
67 | 88 | layer.add( particles );
|
68 | 89 |
|
69 | 90 | gui = new dat.GUI();
|
70 | 91 |
|
71 | 92 | function update(){
|
| 93 | + if (layer.renderertype=='Canvas' || !Detector.webgl) material.map = new THREE.Texture(generateSprite(material.size)); |
72 | 94 | layer.render();
|
73 | 95 | }
|
74 | 96 |
|
|
78 | 100 | });
|
79 | 101 | }
|
80 | 102 |
|
81 |
| - function generateSprite() { |
| 103 | + function generateSprite(size) { |
82 | 104 |
|
83 | 105 | var canvas = document.createElement('canvas'),
|
84 | 106 | context = canvas.getContext('2d'),
|
85 | 107 | gradient;
|
86 |
| - |
87 |
| - canvas.width = 20; |
88 |
| - canvas.height = 20; |
| 108 | + size = size || 20; |
| 109 | + canvas.width = size; |
| 110 | + canvas.height = size; |
89 | 111 |
|
90 | 112 | gradient = context.createRadialGradient(
|
91 | 113 | canvas.width / 2, canvas.height / 2, 0,
|
|
0 commit comments