Document Maps JavaScript API Reference Manual General Library Util

Util

AMap.Util

Collection of common library functions

Method

isDOM(obj)

Determine whether the parameter is a DOM element

Parameter: obj (any)

return value: (boolean) Return true if yes, return false if no

Demo:

AMap.Util.isDOM('Parameters for judgment');

colorNameToHex(colorName)

Convert color names to hexadecimal RGB color values

Parameter: colorName (stringColor name

return value: (string) Color value like #FFFFFF

Demo:

AMap.Util.colorNameToHex("red");

rgbHex2Rgba(hex)

Convert hexadecimal RGB to rgba(R,G,B,A)

Parameter: hex (stringHexadecimal RGB color

return value: (string) rgba(R,G,B,A) color format

Demo:

AMap.Util.rgbHex2Rgba('#ff0000');

argbHex2Rgba(hex)

Convert hexadecimal RGBA to rgba(R,G,B,A)

Parameter: hex (stringHexadecimal RGBA color

return value: (string) rgba(R,G,B,A) color

Demo:

AMap.Util.argbHex2Rgba('#b0d412');

isEmpty(obj)

Determine whether an object is empty

Parameter: obj (any)  Object to be judged

return value: (boolean) Return true if empty, otherwise return false

Demo:

AMap.Util.isEmpty({}); //Return true

deleteItemFromArray(array, item)

Remove element from array

Parameter:

array (ArrayArray to be operated on

item (anyElement to be removed from the array

return value: (ArrayNew array after deleting the specified element

Demo:

var myArray = [1, 2, 3];
AMap.Util.deleteItemFromArray(myArray, 3); //Return [1, 2]

deleteItemFromArrayByIndex(array, index)

Delete array element by index

Parameter:

array (ArrayArray to be operated on

index (numberIndex to be deleted from the array

return value: (ArrayNew array after deleting the specified index

Demo:

var myArray = [1, 2, 3];
AMap.Util.deleteItemFromArrayByIndex(myArray, 0); //Return [2, 3]

indexOf(array, item)

Return the element index

Parameter:

array (ArrayArray to operate on

item (anyElement to find in the array

return value: (number) Element index

Demo:

var myArray = [1, 2, 3];
AMap.Util.indexOf(myArray, 3); //Return 2

format(num, digits)

Keep digits after the decimal point

Parameter:

num (numberValue to be operated on

digits (numberNumber of decimal places to retain (rounded)

return value: (number) Retain value with specified digits

Demo:

var myNunber = 3.1415926;
AMap.Util.format(myNunber,3); //Return 3.142

isArray(obj)

Determine if it is an array

Parameter: obj (ArrayArray to be judged

return value: (boolean) Returns true if yes, otherwise false

Demo:

var myArray = [1, 2, 3];
AMap.Util.isArray(myArray) //Return true

includes(array, item)

Determine if the array contains a certain element

Parameter:

array (ArrayArray to be operated on

item (anyElement to be searched for

return value: (boolean) Returns true if included, otherwise false

Demo:

var myArray = [1, 2, 3];
AMap.Util.includes(myArray, 3); //Return true

requestIdleCallback(func)

Same as Native requestIdleCallback

Parameter: func (Function)

return value: (number)

cancelIdleCallback(id)

Same as Native cancelIdleCallback

Parameter: id (number)

requestAnimFrame(func)

Same as Native Util.requestAnimFrame

Parameter: func (Function)

return value: (number)

cancelAnimFrame(id)

Same as Native Util.cancelAnimFrame

Parameter: id (number)