API Docs for: 7.2
Show:

MQA.Util Class

Module: MQA

Common Utility functions. Consists of DOM helpers and geospatial methods.

Properties

__nextId

Integer private

Id sequence generator used for next id

Methods

_getRandomGUID

() private

Backwards compatible function to return a unique id.

_html

() private

Private html delegate function (non-varargs)

arcDistance

(
  • ll1
  • ll2
  • [unit]
)
Number

Calculate the arc distance between two locations.

Parameters:

  • ll1 MQA.LatLng

    The first lat/lng location.

  • ll2 MQA.LatLng

    The second lat/lng location.

  • [unit] String default = 'm'

    The unit used when calculating the arc distance. Acceptable values include 'm' and 'km'. Defaults to miles ('m').

Returns <Number>

The arc distance between two locations.

Example:

var one = new MQA.LatLng(40.039398, -76.307106);
var two = new MQA.LatLng(39.960333, -76.734671);

var distance = MQA.Util.arcDistance(one, two, 'm');

boundZoomLevel

(
  • level
)
Number private

Takes a given zoom level and bounds it between the max and min zoom level.

Parameters:

  • level Number

    a numerical zoom level

Returns <Number>

the passed zoom level, modifying if it was outside the zoom level bounds

distanceBetween

(
  • ll1
  • ll2
  • [unit]
)
Number

Calculate the distance between two locations.

Parameters:

  • ll1 MQA.LatLng

    The first lat/lng location.

  • ll2 MQA.LatLng

    The second lat/lng location.

  • [unit] String default = 'MI'

    The units used when calculating the distance. Acceptable values include 'MI' and 'KM'. Defaults to miles ('MI').

Returns <Number>

The distance between the two locations.

getComputedStyle

() private

Gets the actual computed value of a style property on a DOM Element.

getDomHeight

() Integer

Get the dom height of an element in pixels

Returns <Integer>

getDomWidth

() Integer

Get the dom width of an element in pixels

Returns <Integer>

getLocalCoords

(
  • element
  • evt
)
Object

Get local coordinates from the event object, relative to a given element.

See http://www.quirksmode.org/js/events_properties.html for the explanation of bizarro mouse coords the W3C inflicted on us.

Parameters:

  • element Element

    the DOM element to use as a reference point for the coords

  • evt Event

    the DOM Event containing the event coords

Returns <Object>

object with "x" and "y" properties, containing the respective pixel offsets.

getParentOffset

(
  • element
)
Object

Gets the X/Y offset of the element in pixels, relative to the top/left of the document.

Parameters:

  • element Element

    the DOM element to get the offset of

Returns <Object>

object with "x" and "y" properties, containing the respective pixel offsets.

html

() DomTree

HTML Dom Builder function. This function takes a packed HTML construct and produces an object which indexes into certain elements defined in the construct.

This is a variable argument function:

  • 1 arg form: The argument is either a string (which will be eval'd to form an array or it is already an array of the packed html structure.

  • 2 arg form: The first arg is the string name of the root element. The second arg is the packed array contents of the element.

The packed HTML structure is made of nested arrays which represents the DOM structure. Each element in the array determines how the next element is interpreted such that an array defining an element's content can be considered a sequence of "datum"s. The following datums exist (these have been optimized for compactness):

  • 's' or 'style': The following string is interpreted as CSS text for the style attribute of the parent.

  • 't' or 'text': The following string is appended to the parent as text

  • 0: (number 0) A text node with a single space is appended to the parent
  • '@*': (starts with @) The named attribute is set with the value of the following string

  • {other text} followed by an array: The element named by other text is created, appended to its parent and has its content built from the following array.

Element names follow CSS conventions and have a syntax of: tagName[#id][.className]

Given the above syntax an element with tag of {tagName} will be created. If it's {id} is defined then it will be added to the returned object with key given by {id}. If {className} is defined, then the elements className attribute will be set to {className}.

Returns <DomTree>

domTree of built html

isFunction

(
  • identifier
)
Boolean

determine if a given name is a valid function

Parameters:

Returns <Boolean>

isMouseLeaveOrEnter

() private

Ported from old toolkit in support of zoom control

isMouseLeaveOrEnter

() private

Ported from old toolkit in support of zoom control

isObjectId

(
  • id
)
Boolean

Return true if the given object id (field name) is an objectId

Parameters:

Returns <Boolean>

isUndefined

(
  • target
)
Boolean

determin if an object or variable is undefined

Parameters:

Returns <Boolean>

objectId

() Integer

Id of an object for an MQA.Component

Returns <Integer>

id

parseColorHex

() String private

Parse an input color string and return a proper hex representation (ie. #efefef). If null/undefined, then #000000 is returned.

Returns <String>

subClass

(
  • constructor
  • mixinObj
)

Create a subclass object prototype without actually invoking the constructor. If mixinObj is defined, then it is passed through AOP/mixin and the result is returned.

Parameters:

Example:

RibbonOverlay.prototype=Util_subClass(MQA.LineOverlay, {
    newMethod: ...
});

toDegrees

(
  • val
)
Float

Convert radians into degrees.

Parameters:

  • val Float

    The value in radians.

Returns <Float>

The value in degrees.

toRadians

(
  • val
)
Float

Convert degrees into radians.

Parameters:

  • val Float

    The value in degrees.

Returns <Float>

The value in radians.

unescapeHtml

(
  • str
)

Escape any escaped HTML entities. The packer escapes entities, so they need to be unescaped before being inserted into the page.

Parameters:

Util_addClass

(
  • node
  • classStr
)
private

add a class name to node

Parameters:

  • node DomNode | String

    the dom node or it's identifier that we want to add the class to

  • classStr String

    the class that will be removed

Util_closestPoint

(
  • p
  • points
)
Object

Parameters:

  • p MQA.Point

    point to which a closes on line segments to be found

  • points Array

    (a minimum of two points must be supplied to construct line segment).

Returns <Object>

{'x' : nearX, 'y' : nearY, 'comp' : savedComp, 'shapeIndex' : closestIdx}

Util_getDomHeight

() private

Get the dom height of an element in pixels

Util_getDomWidth

(
  • elt
  • onlyVisible
)
private

Get the dom width of an element in pixels

Parameters:

Util_getElementsByClassName

(
  • node
  • className
)
private

Finds elements with a passed in className, using the given node as a starting point.

Parameters:

  • node HTMLNode

    if null, will use the document body as a starting point

  • className String

Util_ie6Class

() private

If the browser is ie6, add the css class 'mqaie6' to the elements class. return the element.

Util_ie6Image

() private

If ie6 and the image is a png, then return the gif substitute.

Util_isFunction

(
  • obj
)
Boolean

Determine if the given object is a Function

Parameters:

  • obj Object

    the object to test

Returns <Boolean>

true if the object is a Function

Util_isObjectId

()

Return true if the given object id (field name) is an objectId

Util_isUndefined

()

Return true if the given object is undefined.

Util_objectId

(
  • obj
)
String

Generate a unique id for the given object and set it as a property on the object.

{ "$mqa.id$": "$id$1" }

Parameters:

  • obj Object

    the object to generate the id for

Returns <String>

the unique id

Util_pointInEllipse

(
  • p
  • ellipse
)
Boolean

Checks if a given point is inside an ellipse

Parameters:

Returns <Boolean>

Util_pointInPolygon

(
  • p
  • polygon
)
Boolean

Checks if a given point is inside polygon

Parameters:

  • p MQA.Point
  • polygon Array

    Array of MQA.Points defining polygon (length >= 3)

Returns <Boolean>

Util_removeClass

(
  • node
  • classStr
)
private

Removes the specified classes from node.

Parameters:

  • node DomNode | String

    the dom node or it's identifier that we want to add the class to

  • classStr String

    the class that will be removed

Util_subClass

() private

Create a subclass object prototype without actually invoking the constructor. If mixinObj is defined, then it is passed through AOP_mixin and the result is returned.

Example:

RibbonOverlay.prototype=Util_subClass(MQA.LineOverlay, {
    newMethod: ...
});