og/utils/shared

Source: shared.ts:5


Instance Methods

isUndef(obj: Object): boolean

Returns true if the object pointer is undefined.

Parameters

  • obj (Object) — Object pointer.

Returns

  • boolean — Returns true if object is undefined.

htmlColorToRgba(htmlColor: string, opacity?: number): Vec4

Convert html color string to the RGBA number vector.

Parameters

  • htmlColor (string) — HTML string("#C6C6C6" or "#EF5" or "rgb(8,8,8)" or "rgba(8,8,8)") color.
  • opacity (number, optional) — Opacity for the output vector.

Returns

htmlColorToRgb(htmlColor: string): Vec3

Convert html color string to the RGB number vector.

Parameters

  • htmlColor (string) — HTML string("#C6C6C6" or "#EF5" or "rgb(8,8,8)" or "rgba(8,8,8)") color.

Returns

stringTemplate(template: string, params: Object): string

Replace template substrings between '{' and '}' tokens.

Parameters

  • template (string) — String with templates in "{" and "}"
  • params (Object) — Template named object with subsrtings.

Returns

  • string

Example

Example from og.terrain that replaces tile indexes in url:

CODE
var substrings = {
      "x": 12,
      "y": 15,
      "z": 8
}
og.utils.stringTemplate("http://earth3.openglobus.org/{z}/{y}/{x}.ddm", substrings);
//returns http://earth3.openglobus.org/8/15/12.ddm

stringTemplate2(template: string, params: Object): string

Replace template substrings between '${...}' tokens. Also supports escaped '${...}' tokens emitted by GLSL bundlers.

Parameters

  • template (string) — String with templates in "${" and "}"
  • params (Object) — Template named object with subsrtings.

Returns

  • string

Example

Example from og.terrain that replaces tile indexes in url:

CODE
var substrings = {
      "x": 12,
      "y": 15,
      "z": 8
}
og.utils.stringTemplate2("http://earth3.openglobus.org/${z}/${y}/${x}.ddm", substrings);
//returns http://earth3.openglobus.org/8/15/12.ddm

createScaleByDistance( v?: NumberArray3 | NumberArray4, def: NumberArray4, ): NumberArray4

Normalizes [near, far, vanish, scale], defaulting scale to 1. near <= 0 disables world scaling. It is set to far so the shader scale remains 1. If far <= 0, both use a small epsilon to avoid division by zero without affecting fading.

Parameters

  • v (NumberArray3 | NumberArray4, optional) — Source parameters.
  • def (NumberArray4) — Default parameters.

Returns

  • NumberArray4 — Normalized parameters.

binarySearch( ar: Array.<any>, el: any, compare_fn: function, ): number

Finds an item in a sorted array.

Parameters

  • ar (Array.<any>) — The sorted array to search.
  • el (any) — The item to find in the array.
  • compare_fn (function) — comparator The function to use to compare the item to elements in the array.

Returns

  • number — a negative number if 'a' is less than 'b'; 0 if 'a' is equal to 'b'; 'a' positive number of 'a' is greater than 'b'.

Example

CODE
// Create a comparator function to search through an array of numbers.
function comparator(a, b) {
    return a - b;
};
var numbers = [0, 2, 4, 6, 8];
var index = og.utils.binarySearch(numbers, 6, comparator); // 3

binaryInsert( ar: Array.<any>, el: any, compare_fn: function, ): number

Parameters

  • ar (Array.<any>) — The sorted array to insert.
  • el (any) — The item to insert.
  • compare_fn (function) — comparator The function to use to compare the item to elements in the array.

Returns

  • number — Array index position in which item inserted in.

throttle(func: any, limit: Number, skip?: boolean)

Callback throttling

Parameters

  • func (any)
  • limit (Number)
  • skip (boolean, optional, default: false)

blerp( x: Number, y: Number, fQ11: Number, fQ21: Number, fQ12: Number, fQ22: Number, x1?: Number, x2?: Number, y1?: Number, y2?: Number, )

y2-----Q12--------------Q22--- | | | | | | | | y-------|-----P----------|---- | | | | | | | | | | | | | | | | | | | | y1-----Q11----|---------Q21--- | | | | | | x1 x x2

Parameters

  • x (Number)
  • y (Number)
  • fQ11 (Number)
  • fQ21 (Number)
  • fQ12 (Number)
  • fQ22 (Number)
  • x1 (Number, optional, default: "0.0")
  • x2 (Number, optional, default: "1.0")
  • y1 (Number, optional, default: "0.0")
  • y2 (Number, optional, default: "1.0")

concatTypedArrays(a: TypedArray, b: TypedArray | Array.<number>)

Concatenates two the same type arrays

Parameters

  • a (TypedArray)
  • b (TypedArray | Array.<number>)

appendFloat32Array(a: Float32Array, b: ArrayLike.<number>)

Appends b to a and returns an exact-length view. Grows the backing buffer by doubling, so repeated appends are amortized O(1). The caller must own a.buffer exclusively, including the unused space after a, which is overwritten. The result may share a's buffer.

Parameters

  • a (Float32Array)
  • b (ArrayLike.<number>)

concatArrays( a?: TypedArray | Array.<number>, b?: TypedArray | Array.<number>, ): TypedArray | Array.<number>

Concatenates two the same arrays

Parameters

  • a (TypedArray | Array.<number>, optional, default: "[]") — First array
  • b (TypedArray | Array.<number>, optional, default: "[]") — Second array

Returns

  • TypedArray | Array.<number>

makeArrayTyped( arr: Array.<number>, ctor: Float32Array, ): TypedArray

Convert simple array to typed

Parameters

  • arr (Array.<number>)
  • ctor (Float32Array)

Returns

  • TypedArray

makeArray(arr: TypedArray | Array.<number>): Array.<number>

Convert typed array to array

Parameters

  • arr (TypedArray | Array.<number>)

Returns

  • Array.<number>

spliceArray( arr: TypedArray | Array, starting: Number, deleteCount: Number, out?: Object, )

Parameters

  • arr (TypedArray | Array)
  • starting (Number)
  • deleteCount (Number)
  • out (Object, optional)

spliceTypedArray( arr: TypedArray, starting: Number, deleteCount: Number, out?: Object, )

Parameters

  • arr (TypedArray)
  • starting (Number)
  • deleteCount (Number)
  • out (Object, optional)

getMatrixSubArrayBoundsExt()

Returns two float32 triangle coordinate arrays from inside of the source triangle array, with their bounds and squared geocentric radii.

loadImage(url: string): Promise.<Image>

Promise for load images

Parameters

  • url (string) — link to image.

Returns

  • Promise.<Image> — Returns promise.

isImageLoaded(image: HTMLImageElement): boolean

Gets image is loaded

Parameters

  • image (HTMLImageElement)

Returns

  • boolean — Returns true is the image is loaded

getTileImageResolution(x, y, z, imageSize, ellipsoid)

Parameters

  • x
  • y
  • z
  • imageSize (default: 256)
  • ellipsoid — console.log(1, getTileImageResolution(0, 0, 1)); console.log(7, getTileImageResolution(66, 44, 7)); console.log(10, getTileImageResolution(536, 358, 10)); console.log(12, getTileImageResolution(2149, 1446, 12)); console.log(13, getTileImageResolution(4301, 2892, 13)); console.log(14, getTileImageResolution(8582, 5736, 14)); console.log(15, getTileImageResolution(17205, 11569, 15)); console.log(16, getTileImageResolution(34419, 23138, 16)); console.log(17, getTileImageResolution(68661, 45892, 17)); console.log(18, getTileImageResolution(137650, 92555, 18));

Static Methods

getLinesIntersection2v( start1: Vec2, end1: Vec2, start2: Vec2, end2: Vec2, isSegment?: boolean, ): Vec2

Returns two segment lines intersection coordinate.

Parameters

  • start1 (Vec2) — First line first coordinate.
  • end1 (Vec2) — First line second coordinate.
  • start2 (Vec2) — Second line first coordinate.
  • end2 (Vec2) — Second line second coordinate.
  • isSegment (boolean, optional) — Lines are segments.

Returns

getLinesIntersectionLonLat( start1: Vec2, end1: Vec2, start2: Vec2, end2: Vec2, isSegment?: boolean, ): Vec2

Returns two segment lines intersection coordinate.

Parameters

  • start1 (Vec2) — First line first coordinate.
  • end1 (Vec2) — First line second coordinate.
  • start2 (Vec2) — Second line first coordinate.
  • end2 (Vec2) — Second line second coordinate.
  • isSegment (boolean, optional, default: false) — Lines are segments.

Returns

xmlToJson(xml: Object): Object

Converts XML to JSON

Parameters

  • xml (Object) — Xml object

Returns

  • Object

getMatrixSubArray64( srcArr: TypedArray | Array.<number>, gridSize: number, i0: number, j0: number, size: number, ): Float64Array

Returns 64-bit triangle coordinate array from inside of the source triangle array.

Parameters

  • srcArr (TypedArray | Array.<number>) — Source array
  • gridSize (number) — Source array square matrix size
  • i0 (number) — First row index source array matrix
  • j0 (number) — First column index
  • size (number) — Square matrix result size.

Returns

  • Float64Array — Triangle coordinates array from the source array.

getMatrixSubArray32( sourceArr: TypedArray | Array.<number>, gridSize: number, i0: number, j0: number, size: number, ): Float32Array

Returns 32-bit triangle coordinate array from inside of the source triangle array.

Parameters

  • sourceArr (TypedArray | Array.<number>) — Source array
  • gridSize (number) — Source array square matrix size
  • i0 (number) — First row index source array matrix
  • j0 (number) — First column index
  • size (number) — Square matrix result size.

Returns

  • Float32Array — Triangle coordinates array from the source array.