requireUtils
require(["esri/core/requireUtils"], function(requireUtils) { /* code goes here */ });
Object:
esri/core/requireUtils
Since: ArcGIS API for JavaScript 4.3
Provides a convenience function that allows you to dynamically load required modules.
Method Overview
Name | Return Type | Summary | Object | |
---|---|---|---|---|
Promise | Dynamically requires one or more modules and returns a promise that resolves when all the specified modules have loaded. more details | more details | requireUtils |
Method Details
Dynamically requires one or more modules and returns a promise that resolves when all the specified modules have loaded.
Parameters:moduleRequire requireThe
require
function used to load the modules. This is the AMD alias (e.g. themoduleRequire
reference in the snippets below) used to reference therequire
module.The names of the modules to load.
Returns:Type Description Promise A promise which resolves with an array containing the loaded modules, or a single module when moduleNames
is a string.Examples:// Load multiple modules conditionally require([ "esri/core/requireUtils", "require", "dojo/domReady!" ], function( requireUtils, moduleRequire ){ // load modules based on whether a user selects // a UI option to apply class breaks to a layer if (classBreaksSelected){ { requireUtils.when(moduleRequire, [ "esri/renderers/ClassBreaksRenderer", "esri/symbols/PolygonSymbol3D", "esri/symbols/ExtrudeSymbol3DLayer", ]).then(function([ ClassBreaksRenderer, PolygonSymbol3D, ExtrudeSymbol3DLayer ]) { // Create renderer and apply it to the desired layer }); } });
// Load a single module conditionally require([ ... // load other modules as needed "esri/core/requireUtils", "require", "dojo/domReady!" ], function(..., requireUtils, moduleRequire) { if (basemapUrl && view) { // if basemapUrl is provided then // load customBasemap module and set up and // custom basemap with provided layers. requireUtils.when(moduleRequire, "./customBasemap") .then(function(Basemap) { var customBasemap = new Basemap({ baseLayers: [layers], title: "Custom Basemap", id: "myBasemap" }); }); } });
Loading...