Namespace: esriE-mail This Topic Printable Version Give Us Feedback

Description

The esri namespace has several utility methods associated with it. These methods are convenience methods that are not associated with any class.

Properties

Property Type Description
config Object ArcGIS JavaScript API default configurations that can be overridden programatically. For details, see Default API configurations.
documentBox Object Represents the size of the client side window or document at first load. The size contains width and height properties, and these do not change on window resize.
version Number Current version of the JavaScript API.

Methods

Method Return Value Description
esri.filter(object, callback, thisObject) Object Creates a new object with all properties that pass the test implemented by the filter provided in the function.
esri.graphicsExtent(graphics) Extent Utility function that returns the extent of an array of graphics. If the extent height and width are 0, null is returned.
esri.hide(element) none Hides an HTML element such as a DIV or TABLE.
esri.request(request, useProxy?) Object A wrapper around dojo.io.script.get and dojo.xhrPost. To request data from a server, this method handles sending requests when esriConfig.defaults.io.proxyURL and esriConfig.defaults.io.alwaysUseProxy are set. This method includes a default error handler in cases when the server response is an error. The returned object is dojo.Deferred.
esri.show(element) none Shows an HTML element such as a DIV or TABLE.
esri.substitute(data, template?, first?) String A wrapper around dojo.string.substitute that can also handle wildcard substitution. A wildcard uses the format of ${*}. If no template is provided, it is assumed to be a wildcard. This method is useful if you are not using Graphic or an InfoTemplate, but you want to embed result values in HTML, for example.
esri.toggle(element) none If an HTML element is currently visible, the element is hidden. If the element is hidden, it becomes visible.
esri.urlToObject(url) Object Converts the URL arguments to an object representaion. The object format is
{path: <String>, query:{key:<Object>}}
esri.valueOf(array, value) Object Iterates through the argument array and searches for the identifier to which the argument value matches. Returns null if no matching identifier is found.
Properties Detail

<Object> config

ArcGIS JavaScript API default configurations that can be overridden programatically. For details, see Default API configurations.

<Object> documentBox

Represents the size of the client side window or document at first load. The size contains width and height properties, and these do not change on window resize. (As of v1.3)

<Number> version

Current version of the JavaScript API. (As of v1.2)
Methods Detail

esri.filter(object, callback, thisObject)

Creates a new object with all properties that pass the test implemented by the filter provided in the function. (As of v1.2)
Return value: Object
Input Parameters:
<Object> object Required Object to filter.
<Function> callback Required Function or string implementing the filtering.
<Object> thisObject Required Optional object used to scope the call to the callback.
Code snippets:
      function showResults(results) {
        var filterFunction = function(value) {
          if ((value !== ' ') & (Number(value) !== 0)) {
            return true;
          }
        };

        var filteredResults = esri.filter(results.features[0].attributes, filterFunction);
        var s = "";
        for (att in filteredResults) {
          s = s + "" + att + ":  " + filteredResults[att] + "
"; } dojo.byId("info").innerHTML = s; }

esri.graphicsExtent(graphics)

Utility function that returns the extent of an array of graphics. If the extent height and width are 0, null is returned. (As of v1.3)
Return value: Extent
Input Parameters:
<Graphics> graphics Required The input graphics array.
Code snippets:
var myFeatureExtent = esri.graphicsExtent(myFeatureSet.features);

esri.hide(element)

Hides an HTML element such as a DIV or TABLE.
Return value: none
Input Parameters:
<Element> element Required The name of the HTML element.
Code snippets:
esri.hide(myTable);

See also:
toggle   show  

esri.request(request, useProxy?)

A wrapper around dojo.io.script.get and dojo.xhrPost. To request data from a server, this method handles sending requests when esriConfig.defaults.io.proxyURL and esriConfig.defaults.io.alwaysUseProxy are set. This method includes a default error handler in cases when the server response is an error. The returned object is dojo.Deferred.
Return value: Object
Input Parameters:
<Object> request Required The request object.
<Boolean> useProxy Optional When true, it forces a request to be posted through the proxy even if the content length is less than 2k. (As of v1.3)
Code snippets:

The following example sends a request and calls back the 'load' function on completion.

esri.request({
  url:"", 
  content:{},
  callbackParamName:"callback",
  load:function(response, io) {...}, 
  error:esriConfig.defaults.io.errorHandler
});

esri.show(element)

Shows an HTML element such as a DIV or TABLE.
Return value: none
Input Parameters:
<Element> element Required The name of the HTML element.
Code snippets:
esri.show(myDiv);

See also:
hide   toggle  

esri.substitute(data, template?, first?)

A wrapper around dojo.string.substitute that can also handle wildcard substitution. A wildcard uses the format of ${*}. If no template is provided, it is assumed to be a wildcard. This method is useful if you are not using Graphic or an InfoTemplate, but you want to embed result values in HTML, for example.
Return value: String
Input Parameters:
<Object> data Required The data object used in the substitution.
<String> template Optional The template used for the substitution. Can be any valid HTML. If no template is included, the wildcard template is used.
<Boolean> first Optional When true, returns only the first property found in the data object. The default is false.
Code snippets:

Example 1: no wildcard is included but is assumed.

esri.substitute({state_name: "Arizona", state_capital: "Phoenix"});

Returns: state_name = Arizona <br/> state_capital = PHoenix

Example 2: no wildcard is included and only the first property is displayed.

esri.substitute({state_name: "Arizona", state_capital: "Phoenix"},null,true);

Returns: state_name = Arizona <br/>

Example 3: a template is included for display.

esri.substitute({state_name: "Arizona", state_capital: "Phoenix"},"The capital of ${state_name} is ${state_capital}.");

Returns: The capital of Arizona is Phoenix.


esri.toggle(element)

If an HTML element is currently visible, the element is hidden. If the element is hidden, it becomes visible.
Return value: none
Input Parameters:
<Element> element Required The name of the HTML element.
See also:
show   hide  

esri.urlToObject(url)

Converts the URL arguments to an object representaion. The object format is
{path: <String>, query:{key:<Object>}}
Return value: Object
Input Parameters:
<String> url Required The input URL.
Code snippets:
var myObject = esri.urlToObject("http://www.myworld.com?state_name=Ohio&city_name=Akron");

Returns: { path: "http://www.myworld.com", query: {state_name: "Ohio", city_name: "Akron"} }

If there are no query parameters the return value for query will be null: {path:"http://www.myworld.com",query:null}

The following snippet shows how to check for null or undefined values.

var myObject =  esri.urlToObject("http://www.myworld.com");
if(myObject.query){
  var query = myObject.query;
}

esri.valueOf(array, value)

Iterates through the argument array and searches for the identifier to which the argument value matches. Returns null if no matching identifier is found.
Return value: Object
Input Parameters:
<Array> array Required The argument array for testing.
<Object> value Required The value used in the search. If the value is a String, the value is case sensitive.
Code snippets:

Example 1:

esri.valueOf([firststring: "Oregon", secondstring: "Washington"], "Washington");

Returns: secondstring

Example 2:

esri.valueOf([firststring: "Oregon", secondstring: "Washington"], "Virginia");

Returns: null