Skip To Content
ArcGIS Developer
Dashboard

Utils class

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

Example:

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

Methods

loadStyleLink (id, href, beforeId)

Loads a CSS file dynamically.

Parameters:

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.

Parameters:

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.

Parameters:

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.

Parameters:

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.

getCodedValuesOrTypesCount (fieldInfo, layerInfo)

Gets the length of coded value or subtype of one fieldInfo of a layer in which the layer definition includes domain or subtype.

Parameters:

fieldInfo: Object. Information about each field in a layer. Refer to Class:Field.

layerInfo: Object. The layerInfo obj. Refer to LayerInfo class.

Return Type: Number.

getDisplayValueForCodedValueOrSubtype (layerDefinition, fieldName, attributes)

Gets the display value for a coded value or a subtype field by fieldName and attributes. The attributes field is an object. When a field in attributes is a domain field or a subtype field, its value could be a number that doesn't make sense. This value can be replaced by text that is easy to understand. The result is related to its layer definition and layer data.

Parameters:

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. Refer to Class: Graphic - Attributes.

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

For example: {isCodedValueOrSubtype: true, displayValue: "code0", value: 0}

getDisplayValueForCodedValueOrSubtypeBatch (layerDefinition, fieldName, attributesList)

Gets the display value for a coded value or a subtype field in batch by fieldName and attributes. The attributes field is an object. When a field in attributes is a domain field or a subtype field, its value could be a number that doesn't make sense. This value can be replaced by text that is easy to understand. The result is related to its layer definition and layer data.

Parameters:

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.

attributesList: Array. An array of the feature attributes. Refer to Class: Graphic - Attributes.

Return type: Array. Every item is an object, and it has two properties: isCodedValueOrSubtype, value and displayValue. The former is Boolean and the latter is the display value. If the isCodedValueOrSubtype property is true, the field is either a coded value field or a subtype field.

For example:

[ {isCodedValueOrSubtype: true, displayValue: "code0", value: 0},

{isCodedValueOrSubtype: true, displayValue: "code five", value: 5},

{isCodedValueOrSubtype: true, displayValue: "code six", value: 6},

{isCodedValueOrSubtype: true, displayValue: "code2", value: 2} ]

getCodedValueListForCodedValueOrSubTypes(layerDefinition, fieldName, attributes)

Gets coded value list for coded value field or subtype list for subtype field by fieldName and attributes.

The result list is only related to its layer definition, not layer data. If the attributes parameter doesn't exist or it doesn't have a subtype field, it returns all the coded value list. If attributes has a subtype field, it returns all the coded value list of the current subtype value.

Parameters:

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 (optional). The feature attributes. Refer to Class: Graphic - Attributes.

Return type: Array. Every item is an object, and it has two properties: value and label. The value is used to query in SQL, and the label is used to display in the UI.

For example:

[

{value: 0, label: "code0"},

{value: 1, label: "code1"}

]

In this topic
  1. Methods