Skip to content

Commit 2f361ae

Browse files
committed
docs: Add a short tutorial for quad textures
1 parent 48a8a6c commit 2f361ae

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

tutorials/texture_quad/index.pug

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
extends ../common/index.pug
2+
3+
block mainTutorial
4+
:markdown-it
5+
# Tutorial - Texture Quads
6+
The "map" can contain quads that are set via textures rather than images or videos.
7+
8+
+codeblock('javascript', 1, undefined, true).
9+
// the pixelCoordinateParams function creates the parameters necessary for
10+
// showing an image, video, or texture in pixel coordinates rather than in
11+
// a map projection. This is the conceptual size of the map space
12+
var mapWidth = 720, mapHeight = 360;
13+
var params = geo.util.pixelCoordinateParams('#map', mapWidth, mapHeight);
14+
params.map.max += 3; // allow zooming up to 8x beyond the pixel space specified
15+
// create a map with the pixel-space parameters
16+
var map = geo.map(params.map);
17+
// create a feature layer to place some texture quads
18+
var layer = map.createLayer('feature', {
19+
features: ['quad.texture']
20+
});
21+
22+
var width = 72, height = 72;
23+
var lumData = new Uint8Array(width * height);
24+
// Fill with a checkerboard pattern
25+
for (var i = 0; i < lumData.length; i++) {
26+
var x = i % width;
27+
var y = Math.floor(i / width);
28+
lumData[i] = ((x + y) % 2) * 255;
29+
}
30+
// make an rgba texture, too
31+
var rgbaData = new Uint8Array(width * height * 4);
32+
for (var i = 0; i < rgbaData.length; i++) {
33+
var x = Math.floor((i % (width * 4)) / 4);
34+
var y = Math.floor(i / (width * 4));
35+
// make five colors of stripes, each 4 pixels wide
36+
var stripe = Math.floor((x + y) / 4) % 5;
37+
switch (i % 4) {
38+
case 0:
39+
rgbaData[i] = (stripe === 1 || stripe === 4) * 255;
40+
break;
41+
case 1:
42+
rgbaData[i] = (stripe === 2 || stripe === 4) * 255;
43+
break;
44+
case 2:
45+
rgbaData[i] = (stripe === 3 || stripe === 4) * 255;
46+
break;
47+
case 3:
48+
// full alpha
49+
rgbaData[i] = 255;
50+
break;
51+
}
52+
53+
}
54+
55+
var textureData = [{
56+
ul: [0, 0],
57+
lr: [mapWidth, mapHeight],
58+
texture: {
59+
data: lumData,
60+
type: 'Luminance',
61+
width: width,
62+
height: height
63+
}
64+
}, {
65+
ul: [mapWidth / 2, 0],
66+
lr: [mapWidth, mapHeight],
67+
texture: {
68+
data: rgbaData,
69+
type: 'RGBA',
70+
width: width,
71+
height: height
72+
}
73+
}];
74+
75+
// create a quad feature with the textures.
76+
var quads = layer.createFeature('quad');
77+
quads.data(textureData);
78+
quads.draw();
79+
80+
+codeblock_test('map has a single feature layer', [
81+
'map.layers().length === 1',
82+
'map.layers()[0] instanceof geo.featureLayer',
83+
'map.layers()[0].features().length === 1',
84+
'map.layers()[0].features()[0] instanceof geo.quadFeature'
85+
])

tutorials/texture_quad/thumb.jpg

133 KB
Loading
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"title": "Texture Quads",
3+
"hideNavbar": true,
4+
"level": 1,
5+
"tutorialCss": [],
6+
"tutorialJs": [],
7+
"about": {
8+
"text": "Use data arrays as the texture of a quad."
9+
}
10+
}

0 commit comments

Comments
 (0)