Namespace: utils

og.utils

Openglobus utility functions namespace.

Classes

TextureAtlas
TextureAtlasNode

Methods

staticog.utils.binaryInsert()

TODO
  • NEEDS TESTING

staticog.utils.binarySearch(ar, el, comparator){Number}

Finds an item in a sorted array.
Name Type Description
ar Array The sorted array to search.
el Object The item to find in the array.
comparator og.utils.binarySearch~compare_fn The function to use to compare the item to elements in the array.
Returns:
Type Description
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
// 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

staticog.utils.getLinesIntersection2v(start1, end1, start2, end2, isSegments){og.math.Vector2}

Returns two segment lines intersection coordinate.
Name Type Description
start1 og.math.Vector2 First line first coordinate.
end1 og.math.Vector2 First line second coordinate.
start2 og.math.Vector2 Second line first coordinate.
end2 og.math.Vector2 Second line second coordinate.
isSegments boolean optional Lines are segments.
Returns:
Type Description
og.math.Vector2 - Intersection coordinate.

staticog.utils.getLinesIntersectionLonLat(start1, end1, start2, end2, isSegments){og.math.Vector2}

Returns two segment lines intersection coordinate.
Name Type Description
start1 og.math.Vector2 First line first coordinate.
end1 og.math.Vector2 First line second coordinate.
start2 og.math.Vector2 Second line first coordinate.
end2 og.math.Vector2 Second line second coordinate.
isSegments boolean optional Lines are segments.
Returns:
Type Description
og.math.Vector2 - Intersection coordinate.

staticog.utils.htmlColorToRgb(htmlColor, opacity){og.math.Vector3}

Convert html color string to the RGB number vector.
Name Type Description
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:
Type Description
og.math.Vector3

staticog.utils.htmlColorToRgba(htmlColor, opacity){og.math.Vector4}

Convert html color string to the RGBA number vector.
Name Type Description
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:
Type Description
og.math.Vector4

staticog.utils.readTextFile(fileUrl){string}

Synchronous text file loading. Returns file text.
Name Type Description
fileUrl string File name path.
Returns:
Type Description
string

staticog.utils.stringTemplate(template, params)

Replace template substrings between '{' and '}' tokens.
Name Type Description
template string String with templates in "{" and "}"
params Object Template named object with subsrtings.
Example

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

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

staticog.utils.xmlToJson(xml){Object}

Converts XML to JSON
Name Type Description
xml Object Xml object
Returns:
Type Description
Object - Json converted object.