config
require(["esri/config"], function(esriConfig) { /* code goes here */ });
esri/config
Configure global properties of the library.
The value of this module is an object with the following properties.
require(["esri/config"], function(esriConfig) {
esriConfig.request.proxyUrl = "/resource-proxy/Java/proxy.jsp";
});
Property Overview
Name | Type | Summary | Object | |
---|---|---|---|---|
String | The URL for font resources used by the Font class in FeatureLayer and CSVLayer labels. more details | more details | config | |
String | The default GeometryService used by widgets and other operations, such as on-the-fly projections. more details | more details | config | |
String | The URL for the utility service used by GeoRSSLayer to convert GeoRSS documents. more details | more details | config | |
String | The URL for the utility service used by KMLLayer to convert KML documents. more details | more details | config | |
String | The default URL of new portal instances. more details | more details | config | |
Object | An object with properties that control various aspects of communication between the library and web servers. more details | more details | config | |
Object | The AMD loader's configuration object, which is loaded with each worker. more details | more details | config |
Property Details
- fontsUrl StringSince: ArcGIS API for JavaScript 4.8
The URL for font resources used by the Font class in FeatureLayer and CSVLayer labels. To use your own hosted fonts, the font files need to be in
.pbf
format, and you must follow the kebab-case naming convention (e.g. "arial-unicode-ms-bold").- Default Value:"https://static.arcgis.com/fonts"
- See also:
Example:esriConfig.fontsUrl = "https://myserver.com/fonts";
- geometryServiceUrl String
The default GeometryService used by widgets and other operations, such as on-the-fly projections.
- Default Value:"https://utility.arcgisonline.com/arcgis/rest/services/Geometry/GeometryServer"
Example:esriConfig.geometryServiceUrl = "https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer";
- geoRSSServiceUrl String
The URL for the utility service used by GeoRSSLayer to convert GeoRSS documents.
- Default Value:"https://utility.arcgis.com/sharing/rss"
Example:esriConfig.geoRSSServiceUrl = "http://servername.domain.suffix/arcgis/sharing/rss";
- kmlServiceUrl StringSince: ArcGIS API for JavaScript 4.5
The URL for the utility service used by KMLLayer to convert KML documents.
- Default Value:"https://utility.arcgis.com/sharing/kml"
Example:esriConfig.kmlServiceUrl = "http://servername.domain.suffix/arcgis/sharing/kml";
- portalUrl String
The default URL of new portal instances. If using an on-premise portal, this value should be set to the portal instance, for example:
https://www.example.com/arcgis
- Default Value:"https://www.arcgis.com"
- See also:
Example:// Set the hostname to the on-premise portal esriConfig.portalUrl = "https://myHostName.esri.com/arcgis"
- request Object
An object with properties that control various aspects of communication between the library and web servers.
- Properties:
optional List of domain suffixes known to support https. This will automatically upgrade requests made to such domains to use https instead of http when the application is not running on http. Note that port numbers should not be included in the domain suffix to be matched.
If no
httpsDomains
list exists , the API redirects all calls using https. If the list exists and a domain of a required http resource is not listed, the API sends the URL as it is specified within the code. Likewise, if the list exists and the domain of a required http resource is listed in it, the API sends an https request to that resource.The list includes the following domain suffixes by default:
arcgis.com
arcgisonline.com
optionalinterceptors RequestInterceptor[]Since: 4.8
Allows developers to modify requests before or after they are sent. The first interceptor that matches the request URL will be used.Example:
const featureLayerUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"; esriConfig.request.interceptors.push({ // set the `urls` property to the URL of the FeatureLayer so that this // interceptor only applies to requests made to the FeatureLayer URL urls: featureLayerUrl, // use the BeforeInterceptorCallback to check if the query of the // FeatureLayer has a maxAllowableOffset property set. // if so, then set the maxAllowableOffset to 0 before: function(params) { if (params.requestOptions.query.maxAllowableOffset) { params.requestOptions.query.maxAllowableOffset = 0; } }, // use the AfterInterceptorCallback to check if `ssl` is set to 'true' // on the response to the request, if it's set to 'false', change // the value to 'true' before returning the response after: function(response) { if (!response.ssl) { response.ssl = true; } } });
optionalmaxUrlLength NumberDefault Value:2000Maximum number of characters allowed in the URL for HTTP GET requests made by request. If this limit is exceeded, HTTP POST method will be used.
optional A proxy rule defines a proxy for a set of resources with an identical URL prefix. When using esriRequest, if a target URL matches a rule, then the request will be sent to the specified proxy. Rather than populating this array directly, use the urlUtils.addProxyRule() method. Rule objects have the following properties:
optionalproxyUrl StringDefault Value:nullResource proxy for your application. It is used by the library when communicating with a web server hosted on a domain that is different from the domain where your application is hosted.
The library may or may not use the proxy depending on the type of request made, whether the server support CORS, whether the application is being run on older versions of browsers etc. To keep it simple, it is recommended that you always configure a resource proxy for your application.
You can download the resource proxy from this GitHub repo.
require(["esri/config"], function(esriConfig) { esriConfig.request.proxyUrl = "/resource-proxy/Java/proxy.jsp"; });
optionaltimeout NumberDefault Value:60000Number of milliseconds request will wait for response from a server. If a server fails to respond before this time expires, then the request is considered to have encountered an error.
optional Since: 4.9
Indicates whether cross origin requests made to the associated server should include credentials such as cookies and authorization headers.require(["esri/config"], function(esriConfig) { esriConfig.request.trustedServers.push("[<protocol>//]<hostname>.<domain>[:<port>]"); });
optionaluseIdentity BooleanDefault Value:trueSince: 4.5
Indicates whetheresri/request
will request a credential fromIdentityManager
.- See also:
- workers Object
The AMD loader's configuration object, which is loaded with each worker. Modify the configuration to specify locations of packages to be loaded with the workers framework or to define a feature detection.
- Properties:
- optionalloaderUrl Object
The absolute url to the AMD loader used in the worker. The default url points to the AMD loader used by the API.
optionalloaderConfig ObjectThe configuration parameters for the workers framework.
- Specification:
- optionalbaseUrl String
The AMD loader loads all code relative to the baseUrl.
optionalhas ObjectDetermines if the specified feature capabilities are supported.
optionalpaths ObjectMap of module id fragments to file paths.
optionalmap ObjectMap paths in module identifiers to different paths.
optional An array of objects which provide the package name and its location.
Example:// Set worker's AMD loader configuration to set up // a path to folder called workersFolder. esriConfig.workers.loaderConfig = { paths: { myWorkers: window.location.href.replace(/\/[^/]+$/, "/workersFolder"), dojo: "https://ajax.googleapis.com/ajax/libs/dojo/1.11.2/dojo/" } }; // load myWorkers/Calculator.js in the workers framework // and invoke its "getMaxNumber" method workers.open(this, "myWorkers/Calculator") .then(function(connection) { return connection.invoke("getMaxNumber", [0, 1, 2, 3, 4]); }) .then(function(result) { console.log(result); }); //********************************************************* // module: workerFolder/Calculator.js //********************************************************* define([], function (promiseUtils) { return { // this function can be invoked from the main thread getMaxNumber: function (number) { return Math.max.apply(null, numbers); } }; });
Type Definitions
- AfterInterceptorCallback(response)
Makes changes to the response after the request is sent, but before it's returned to the caller.
Parameter:response RequestResponseThe response object.
Example:const featureLayerUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"; esriConfig.request.interceptors.push({ // set the `urls` property to the URL of the FeatureLayer so that this // interceptor only applies to requests made to the FeatureLayer URL urls: featureLayerUrl, // use the AfterInterceptorCallback to check if `ssl` is set to 'true' // on the response to the request, if it's set to 'false', change // the value to 'true' before returning the response after: function(response) { if (!response.ssl) { response.ssl = true; } } });
- BeforeInterceptorCallback(params){Object}
Makes changes to the request URL or options before the request is sent. A returned value will be used as the response data, which would prevent the request from being sent.
If
null
orundefined
is returned, the request is sent with whatever changes were made to the parameters. If an Error is returned, the request is rejected with an esriError. If any other type is returned, the request is resolved with the returned value as the response data (request will not be sent).Parameters:Specification:params ObjectParameters object that specifies the two properties that can be set.
Specification:url StringThe request URL.
requestOptions RequestOptionsThe options specified by the user in the data request. See RequestOptions for available properties.
Returns:Type Description Object Returns: null
,undefined
, Error, response data, or a Promise that resolves to any one of these object types.Examples:// modifying the query parameters const featureLayerUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"; esriConfig.request.interceptors.push({ // set the `urls` property to the URL of the FeatureLayer so that this // interceptor only applies to requests made to the FeatureLayer URL urls: featureLayerUrl, // use the BeforeInterceptorCallback to check if the query of the // FeatureLayer has a maxAllowableOffset property set. // if so, then set the maxAllowableOffset to 0 before: function(params) { if (params.requestOptions.query.maxAllowableOffset) { params.requestOptions.query.maxAllowableOffset = 0; } } });
// fetching the data in place of the requests const wmsLayerUrl = "https://sampleserver6.arcgisonline.com/arcgis/services/911CallsHotspot/MapServer/WMSServer"; esriConfig.request.interceptors.push({ urls: wmsLayerUrl, before: function(params) { if (params.url === url && params.requestOptions.responseType === "xml") { if ("fetch" in window && "TextDecoder" in window) { // decode the response as ISO-8859-1 if it's not UTF-8 as expected return fetch(url + "?SERVICE=WMS&REQUEST=GetCapabilities") .then(function(response) { return response.arrayBuffer(); }) .then(function(buffer) { var textDecoder = new TextDecoder("ISO-8859-1"); // specified in the Capabilities XML declaration var xmlText = textDecoder.decode(buffer); var parser = new DOMParser(); xml = parser.parseFromString(xmlText, "application/xml"); return xml; }); } } } });
- RequestInterceptor
Specifies the object used for intercepting and modifying requests made via esriRequest.
- Properties:
- optionalafter AfterInterceptorCallback
Makes changes to the response after the request is sent, but before it's returned to the caller.
optionalbefore BeforeInterceptorCallbackMake changes to the request URL or options before the request is sent. A returned value will be used as the response data, which would prevent the request from being sent.
optionalerror FunctionWhen an error occurs during the request processing, this function is called with an Error object giving the details about what happened. For example, this could be used to log specific errors occurring with layers or services.
optionalheaders ObjectSets or adds headers into
requestOptions.headers
. See also: requestOptions.optionalquery ObjectSets or adds query parameters into
requestOptions.query
. See also: requestOptions.optionalresponseData ObjectHardcodes the response. The request will not be sent. This is resolved as the response
data
.optional Specifies the URL(s) to apply to the interceptors. If the value is type
String
, then it matches if the request URL starts with that string. If null or undefined, the interceptor will apply to all relevant requests.
Examples:const featureLayerUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"; esriConfig.request.interceptors.push({ // set the `urls` property to the URL of the FeatureLayer so that this // interceptor only applies to requests made to the FeatureLayer URL urls: featureLayerUrl, // use the BeforeInterceptorCallback to check if the query of the // FeatureLayer has a maxAllowableOffset property set. // if so, then set the maxAllowableOffset to 0 before: function(params) { if (params.requestOptions.query.maxAllowableOffset) { params.requestOptions.query.maxAllowableOffset = 0; } }, // use the AfterInterceptorCallback to check if `ssl` is set to 'true' // on the response to the request, if it's set to 'false', change // the value to 'true' before returning the response after: function(response) { if (!response.ssl) { response.ssl = true; } } });
const featureLayer = new FeatureLayer({ url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/3" }); esriConfig.request.interceptors.push({ urls: featureLayer.url, // set the error function and check if an error occurs, and if it's name is "AbortError" // if so, display a useful error about the layer, if not, ignore the error error: function(error) { if (error.name == "AbortError") { // we're only interested in aborted request errors console.error(`An error happened with layer ${featureLayer.title}`, error); } return; } });