This namespace contains definitions of static functions for common tasks.
- Source:
- bu/util/util.jsdoc
Namespaces
Members
-
<static> randomColor
-
Returns a random color as string rgba(r,g,b). Maintains an internal value that ensure that new color returned is the best random color possible. We maintain a small cache of color strings. To provide cheap LRU-like semantics, whenever the cache grows too large we simply delete an arbitrary 25% of the entries. Based in: https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/ and also based in
ol.color.fromString
.- Source:
- bu/util/util.js
-
<static> uniqueNumber
-
Returns a unique number that be used to identify unique objects or events. Based in: http://qnimate.com/generate-unique-number-in-javascript/
- Source:
- bu/util/util.js
Methods
-
<static> anyItemHasValue(obj)
-
Checks if any key in object has a value or is an empty array.
Parameters:
Name Type Description obj
Object Object to check.
- Source:
- bu/util/util.js
Returns:
- Type
- boolean
-
<static> anyMatchInArray(source, target)
-
Checks if any value in target array exists in source array.
Parameters:
Name Type Description source
Array Array to check.
target
Array Array with values to find in source.
- Source:
- bu/util/util.js
Returns:
True if any value found.
- Type
- boolean
-
<static> createDoubleArray(rows, cols)
-
Creates a new 2D array of the given dimensions.
Parameters:
Name Type Description rows
number The Y dimension.
cols
number The X dimension.
- Source:
- bu/util/util.js
Returns:
- Type
- Array
-
<static> createElement(parent, elName [, attNames] [, attValues] [, html])
-
Creates and returns a HTML element and populates its attributes. Optionally it appends result to a given node.
Parameters:
Name Type Argument Description parent
HTMLElement Parent to append to.
elName
string Element name.
attNames
Array.<string> <optional>
Attribute names.
attValues
Array.<string> <optional>
Attribute values. Length MUST match attNames.
html
string <optional>
HTML content
- Source:
- bu/util/util.js
Returns:
- Type
- HTMLElement
-
<static> dataURItoBlob(dataURI)
-
Convert a Base64 image to binary.
Parameters:
Name Type Description dataURI
* - Source:
- bu/util/util.js
Returns:
- Type
- Blob
-
<static> decriptUserData(data)
-
Encript user data.
Parameters:
Name Type Description data
string Data.
- Source:
- bu/util/util.js
Returns:
Encripted string.
- Type
- string
-
<static> defaults(obj, defaultsObj)
-
Return object with default values if values do not exist.
Parameters:
Name Type Description obj
Object Object to set.
defaultsObj
Object Object with defaults.
- Source:
- bu/util/util.js
Returns:
Object with defaults if values not exist.
- Type
- Object
-
<static> encodeUrlXhr(url, data)
-
Encodes a URL.
Parameters:
Name Type Description url
string URL.
data
Object Object with params.
- Source:
- bu/util/util.js
Returns:
- Type
- string
-
<static> encriptUserData(user, pwd)
-
Encript user data.
Parameters:
Name Type Description user
string User name.
pwd
string Password.
- Source:
- bu/util/util.js
Returns:
Encripted string.
- Type
- string
-
<static> encriptUserData2(user, pwd)
-
Encript user data.
Parameters:
Name Type Description user
string User name.
pwd
string Password.
- Source:
- bu/util/util.js
Returns:
Encripted string.
- Type
- string
-
<static> equalCoordinates(coord1, coord2)
-
Returns true if two coordinates are equal. A tolerance in the number of decimals is set through the global param bu.COORDINATE_DECIMALS_TOLERANCE.
Parameters:
Name Type Description coord1
bu.Coordinate First coordinate to compare.
coord2
bu.Coordinate Second coordinate to compare.
- Source:
- bu/util/util.js
Returns:
- Type
- boolean
-
<static> equalResolutions(res1, res2)
-
Returns true if two resolutions are equal. A tolerance in the number of decimals is set through the global param bu.RESOLUTION_DECIMALS_TOLERANCE.
Parameters:
Name Type Description res1
number First resolution to compare.
res2
number Second resolution to compare.
- Source:
- bu/util/util.js
Returns:
- Type
- boolean
-
<static> equalRotations(rot1, rot2)
-
Returns true if two rotations are equal. A tolerance in the number of decimals is set through the global param bu.ROTATION_DECIMALS_TOLERANCE.
Parameters:
Name Type Description rot1
number First rotation to compare.
rot2
number Second rotation to compare.
- Source:
- bu/util/util.js
Returns:
- Type
- boolean
-
<static> extractProviders(serviceProviders)
-
Extract Map, Routing and Geocoding service providers.
Parameters:
Name Type Description serviceProviders
Array.<string> Array with service provider names.
- Source:
- bu/util/util.js
Returns:
- Type
- Object
-
<static> fieldToHTML(field, value)
-
Returns a HTML fragment for a given field and value.
Parameters:
Name Type Description field
string The field.
value
string The value.
- Source:
- bu/util/util.js
Returns:
- Type
- string
-
<static> findLayers(layers, layerType, sourceType [, onlyFirst], conditionFunc)
-
Search inside a
ol.Collection.<ol.layer.Base>
with some filters and return the firstol.layer.Base
found or null (when param onlyFirst is true) or all the layers found in an array (when param onlyFirst is false).Parameters:
Name Type Argument Description layers
ol.Collection.<ol.layer.Base> The collection of layers.
layerType
Object The layer type to search for.
sourceType
Object The source type to search for.
onlyFirst
boolean <optional>
If return only first found or all found. By default the value is true.
conditionFunc
function | undefined An optional condition the layer and the source must comply with. Any function that receives a
ol.layer.Base
and returns a boolean.- Source:
- bu/util/util.js
Returns:
- Type
- ol.layer.Base | Array.<ol.layer.Base>
-
<static> formatFeature(feature)
-
Returns an HTML fragment with the properties of a feature.
Parameters:
Name Type Description feature
ol.Feature Feature.
- Source:
- bu/util/util.js
Returns:
- Type
- string
-
<static> getComputedSize(element)
-
Gets the computed size of the element using the computed style.
Parameters:
Name Type Description element
Element HTML element.
- Source:
- bu/util/util.js
Returns:
The pair of numbers with width and height.
- Type
- Array.<number>
-
<static> getCoordinateFromID(id)
-
Gets the lonlat coordinate of a Blom image extracting it from the ID of the image. Blom images follow the pattern: Xs000.000000n00.000000_YYMMDD where: X is a letter representing the type of image; s is '+' or '-', for positive or negative longitudes; 0 are digits for longitude and latitude; n is '_' (meaning positive) or '-' (meaning negative) latitude; _ is a separator; YYMMDD is a date.
Parameters:
Name Type Description id
string Image ID.
- Source:
- bu/util/util.js
Returns:
- Type
- bu.Coordinate
-
<static> getDefaultStyleWithRandomColor(key)
-
Returns a default style with a random color.
Parameters:
Name Type Description key
string Key value to reuse existing style in a cache of styles.
- Source:
- bu/util/util.js
Returns:
- Type
- ol.style.Style
-
<static> getFormatReader(file)
-
Returns the correct
reader
for the file.Parameters:
Name Type Description file
File | string A file object or the extension of the file.
- Source:
- bu/util/util.js
Returns:
The correct format reader for the file or null if fail.
- Type
- bu.format.local.File | null
-
<static> getLayerColor(layer)
-
Returns the main color of the layer, if anyone found, or null.
Parameters:
Name Type Description layer
ol.layer.Layer Layer.
- Source:
- bu/util/util.js
Returns:
- Type
- string
-
<static> getNDC(clientX, clientY, target)
-
Gets Normalized Device Coordinates for a given Mouse or Touch event client coords and target.
Parameters:
Name Type Description clientX
Number X.
clientY
Number Y.
target
Element Expected to be a canvas element.
- Source:
- bu/util/util.js
Returns:
X and Y coordinates.
- Type
- Array.<Number>
-
<static> getNewLayerName(layerList)
-
Returns a unique layer name for a new layer to be added to the list.
Parameters:
Name Type Description layerList
ol.Collection.<ol.layer.Base> - Source:
- bu/util/util.js
Returns:
- Type
- string
-
<static> getOverlayElementToRender(overlay)
-
Returns the correct HTML element of an overlay to render. The element must exist, must be visible and have a non-zero size. Also the element must have a className with one of these values:
- bu.css.CLASS_MEASUREMENT_TOOLTIP_STATIC
- bu.css.CLASS_FEATUREINFO_POPUP If not found then returns null.
Parameters:
Name Type Description overlay
ol.Overlay The overlay to render.
- Source:
- bu/util/util.js
Returns:
- Type
- Element | null
-
<static> getOverlayPosition(overlay, viewportRect)
-
Returns a coordinate position in pixels [left, top] for an
ol.Overlay
object.Parameters:
Name Type Description overlay
ol.Overlay Overlay object.
viewportRect
DOMRect DOMRect of the viewport.
- Source:
- bu/util/util.js
Returns:
- Type
- bu.Coordinate
-
<static> getWorldFileData(map)
-
Returns the data of the world file. Each value in the returned array is a line for the world file. The world file is a text file that contains the following content: Line 1: A: pixel size in the x-direction in map units/pixel Line 2: B: rotation about y-axis Line 3: C: rotation about x-axis Line 4: D: pixel size in the y-direction in map units Line 5: E: x-coordinate of the center of the upper left pixel Line 6: F: y-coordinate of the center of the upper left pixel
Parameters:
Name Type Description map
ol.Map The map object for which obtain the world file.
- Source:
- bu/util/util.js
Returns:
- Type
- Array.<number>
-
<static> getXMLDoc(xml)
-
Returns the XMLDoc object from a XML text.
Parameters:
Name Type Description xml
string XML text
- Source:
- bu/util/util.js
Returns:
XMLDoc object.
- Type
- Object
-
<static> hash(arguments)
-
Jenkins one-at-a-time hash http://www.burtleburtle.net/bob/hash/doobs.html
Parameters:
Name Type Description arguments
Array.<number> An array of integers.
- Source:
- bu/util/util.js
Returns:
An integer.
- Type
- number
-
<static> htmlEscape(str)
-
Escapes special html chars.
Parameters:
Name Type Description str
string String to escape.
- Source:
- bu/util/util.js
Returns:
- Type
- string
-
<static> htmlformat(html, obj)
-
Formats an html string with object values and escapes html chars. Each key in object can be referenced in the template using {key_name}. Example: htmlformat('{street}', {street: 'Main St.'}) returns: '<span>Main St.</span>'
Parameters:
Name Type Description html
string Template to use.
obj
Object Object wih data.
- Source:
- bu/util/util.js
Returns:
- Type
- string
-
<static> isBaseLayer(layer)
-
Returns if layer is base layer. Base layers are always of type
ol.layer.Tile
and must have a baselayer attribute set to true.Parameters:
Name Type Description layer
ol.layer.Base Layer to check.
- Source:
- bu/util/util.js
Returns:
- Type
- boolean
-
<static> isElement(obj)
-
Returns true if the element is an HTML element.
Parameters:
Name Type Description obj
Object Object to check.
- Source:
- bu/util/util.js
Returns:
True if object is an element.
- Type
- boolean
-
<static> jsonp(url, key, callback)
-
Executes a JSONP call and calls the callback. https://github.com/Fresheyeball/micro-jsonp
Parameters:
Name Type Description url
string URL to execute.
key
string Name of the callback parameter.
callback
function The callback function where data will be accepted.
- Source:
- bu/util/util.js
-
<static> pixelRatio()
-
Returns the current pixel ratio of the viewport.
- Source:
- bu/util/util.js
Returns:
The pixel ratio from 0 to 1.
- Type
- number
-
<static> pointsToCoordinates(coordinates)
-
Get a plain array of numbers and transform them to a coordinates array.
Parameters:
Name Type Description coordinates
Array.<Number> Numbers array.
- Source:
- bu/util/util.js
Returns:
Coordinates array.
- Type
- Array.<bu.Coordinates>
-
<static> removeChilds(elements)
-
Removes elements from DOM.
Parameters:
Name Type Description elements
Array.<Element> Element array.
- Source:
- bu/util/util.js
-
<static> strformat(params)
-
Formats a string using the '{x}' pattern where x is a 0..n number. First argument must be the string to format, and the rest the values.
Parameters:
Name Type Argument Description params
string <repeatable>
Strings.
- Source:
- bu/util/util.js
-
<static> to3DGeometry(geometry, z)
-
Returns a new fixed geometry with a given Z value if geometry has no Z, or the same geometry object but with a fixed Z if it has Zs.
Parameters:
Name Type Description geometry
ol.geom.Geometry The input geometry.
z
number The Z value to use to fix the input geometry.
- Source:
- bu/util/util.js
Returns:
The returned geometry always have Z values.
- Type
- ol.geom.Geometry
-
<static> toBuffer(b)
-
Converts an ArrayBuffer to Node.js Buffer object. This is a function copied here from shpjs for convenience.
Parameters:
Name Type Description b
ArrayBuffer ArrayBuffer.
- Source:
- bu/util/util.js
Returns:
- Type
- Buffer
-
<static> toGeometryLatLon(geometry, projection)
-
Returns a new geometry with coordinates in EPSG:4326 if projection is different or the same passed if not.
Parameters:
Name Type Description geometry
ol.geom.Geometry The geometry.
projection
ol.ProjectionLike The projection.
- Source:
- bu/util/util.js
Returns:
- Type
- ol.geom.Geometry
-
<static> toGeometryWithoutHoles(geom)
-
Returns a new geometry without holes in case Polygon or return the same otherwise.
Parameters:
Name Type Description geom
ol.geom.Geometry Geometry.
- Source:
- bu/util/util.js
Returns:
- Type
- ol.geom.Geometry
-
<static> toQueryString(obj)
-
Creates a URL query string.
Parameters:
Name Type Description obj
Object Object with params.
- Source:
- bu/util/util.js
Returns:
- Type
- string
-
<static> urlParser()
-
Gets the URL parameters
- Source:
- bu/util/util.js
Returns:
Object with a parameters and its values.
- Type
- Object