Document Maps JavaScript API Advanced Tutorial Auxiliary Library Other auxiliary functions

Other auxiliary functions

1、AMap.Util

AMap.Util is a collection of commonly used library functions, including color format conversion, array operations, requestAnimationFrame animation function calls, etc.

The color format conversion functions are as follows:

var colorStr = 'red';
var colorHex = 'ff0000'; //#RRGGBB
var colorRGBAHex = 'ffff0000'; //#AARRGGBB
  
var colorOut = AMap.Util.colorNameToHex(colorStr); //Convert color names to hexadecimal color codes, resulting in #ff0000
var colorOut2 = AMap.Util.rgbHex2Rgba(colorHex); //Convert ordinary hexadecimal color codes to RGB format with transparency, resulting in rgba(255, 0, 0, 1.00);
var colorOut3 = AMap.Util.argbHex2Rgba(colorRGBAHex); //Convert a hexadecimal color code with transparency to RGB format with transparency, the result is rgba(255, 0, 0, 1.00)

2、AMap.DomUtil

AMap.domUtil is a collection of library functions related to DOM manipulation.

Take the method AMap.DomUtil.getViewport for getting the size of DOM elements as an example:

var body = AMap.DomUtil.getViewport(document.body); //Obtain document viewport information
var width = body.width; //Get the width of the viewport
var height = body.height; //Get the height of the viewport