Home Reference Source Test
public class | source

WebGLUtils

Class with static methods that will help with WebGL related stuff(Matrices, web mercator projection and shaders). Always remeber WebGL is column major when reading the matrix code.

See:

Static Method Summary

Static Public Methods
public static

createAndCompileShader(type: string, source_code: string, webgl: _webgl): WebGLShader

Creates and compiles a shader.

public static

createWebGLProgram(webgl: {gl: WebGLRenderingContext, program: WebGLProgram}): void

Initializes: 1)WebGLProgram, 2) Generates shadders, 3) Attaches shaders to the program, 4) links program, 5) uses program.

public static

finalMatrix(scale: number, width: number, height: number, offsetX: number, offsetY: number): Float32Array

This is the result matrix from the multiplication of M1M2M3

public static

generateShadersSourceCode(): {vertexCode: string, fragmentCode: string}

Creates shaders(Vertex + Fragment) source code.

public static

webMercatorProjection(longitudeCenter: number, latitudeCenter: number, zoom: number, tileSize: number, width: number, height: number): {scale: number, offsetX: number, offsetY: number}

Calculates the scale and offset(X and Y) for the Web Mercator projection.

Static Public Methods

public static createAndCompileShader(type: string, source_code: string, webgl: _webgl): WebGLShader source

Creates and compiles a shader.

Params:

NameTypeAttributeDescription
type string

Type of shader. Options are: VERTEX_SHADER or FRAGMENT_SHADER;

source_code string

The shader source code.

webgl _webgl

Webgl object used by the Map class.

Return:

WebGLShader

The shader(vertex of fragment).

public static createWebGLProgram(webgl: {gl: WebGLRenderingContext, program: WebGLProgram}): void source

Initializes: 1)WebGLProgram, 2) Generates shadders, 3) Attaches shaders to the program, 4) links program, 5) uses program.

Params:

NameTypeAttributeDescription
webgl {gl: WebGLRenderingContext, program: WebGLProgram}

Return:

void

public static finalMatrix(scale: number, width: number, height: number, offsetX: number, offsetY: number): Float32Array source

This is the result matrix from the multiplication of M1M2M3

Params:

NameTypeAttributeDescription
scale number

The scale calculated with WebMercator projection.

width number

The width of the canvas.

height number

The height of the canvas.

offsetX number

The offsetX calculated with WebMercator projection.

offsetY number

The offsetY calculated with WebMercator projection.

Return:

Float32Array

The resulting matrix (M1M2M3) in a single matrix to send to WebGL in order to calculate the resulting position.

See:

public static generateShadersSourceCode(): {vertexCode: string, fragmentCode: string} source

Creates shaders(Vertex + Fragment) source code.

Return:

{vertexCode: string, fragmentCode: string}

The code for the vertex and fragment shaders.

public static webMercatorProjection(longitudeCenter: number, latitudeCenter: number, zoom: number, tileSize: number, width: number, height: number): {scale: number, offsetX: number, offsetY: number} source

Calculates the scale and offset(X and Y) for the Web Mercator projection.

Params:

NameTypeAttributeDescription
longitudeCenter number

Longitude of the given position.

latitudeCenter number

Latitude of the given position.

zoom number

Current zoom level of the background map.

tileSize number

The size of each tile in the background map. Usually is 256. If different should be given in the API options.

width number

Width of the current canvas.

height number

Height of the current canvas.

Return:

{scale: number, offsetX: number, offsetY: number}

Returns the scale, offsetX and offsetY of the point given using the Web Mercator projection.

See: