Utils class

The Utils class contains helper functions. You can use it without creating an instance.


require(["jimu/utils"], function(utils) { 
  utils. loadStyleLink()


loadStyleLink (id, href, beforeId)

Loads a CSS file dynamically.


id: The link or style tag ID.

href: The file URL.

beforeId: The element ID that the link or style tag will be inserted before. If not passed in, the tag will be inserted in the header.

Return type: Deferred object. When the load succeeds, the deferred object is resolved.

isEqual (o1, o2)

Compares whether two objects/arrays are equal, recursively.


The object/array that will be compared.

Return type: True or False.

merge(target, source)

Merges the source object/array to the target object/array.


target: The target object/array.

source: The source object/array.

Return type: The merged object/array.

file.readFile (fileEvt, filter, maxSize, cb)

Reads the file by the HTML5 API. If the HTML5 file reader API is not supported, it tries to use Flash to read the file.


fileEvt: Event object, which can be from a file change event.

filter: File type filter. Files that don't match the filter will not be read, such as image/* and image/png.

maxSize: A file size that exceeds maxSize will not be read.

cb: The callback function when the file is read completely. The function has three parameters: err, fileName, and fileData.

Return type: No return.

getDisplayValueForCodedValueOrSubtype (layerDefinition, fieldName, attributes)

Gets the best display value for coded value and subtype fields.


layerDefinition: Object. The structure is the same as the information returned by REST for a layer in a feature service or map service.

fieldName: String. The field name.

attributes: Object. The feature attributes.

Return type: Object. It has two properties: isCodedValueOrSubtype and displayValue. The former is Boolean and the latter is the best display value. If the isCodedValueOrSubtype property is true, the field is either a coded value field or a subtype field.

In this topic
  1. Methods