Exploring the ArcGIS JavaScript API: Q&A

Document created by Rprosser-esristaff Employee on Apr 8, 2016
Version 1Show Document
  • View in full screen mode

Questions that have come up while learning and teaching the ArcGIS API for JavaScript.


Q: Can the ArcGIS API for JavaScript be used with other JavaScript toolkits and libraries?
A: Yes, the JavaScript API can be used with other JavaScript libraries. You can find several examples of using the API with other libraries on Esri's GitHub pages including bootstrap-map-js, angular-esri-map, and jquery-mobile-map-js. Using the compact version of the API is useful when working with other JavaScript libraries. It minimizes the number of Dojo and Esri modules loaded with the API. The ArcGIS API for JavaScript Web Optimizer can also be useful when working with other libraries by generating custom builds of the JavaScript API.




Q: In the JavaScript API Reference some of the class names are capitalized while others are not. Is this meaningful?
A: In general, the capitalization is meaningful. The naming convention used in the API follows the Dojo Style Guide. Capitalized class names indicate classes which can instantiate as objects. They will have a constructor. Lower-case names indicate modules, which are collections of methods and constants. “Modules are about providing methods that you can use across multiple classes – think about them as ‘libraries’… Classes are about objects, modules are about functions.”




Q: Are ArcGIS JavaScript API modules loaded asynchronously or synchronously?
A: Dojo provides the module loading functionality for the ArcGIS JavaScript API, specifically the AMD loader. By default, the AMD loader is synchronous in order to maintain backwards compatibility. Switching to asynchronous mode is done by adding the following code to the script before loading the ArcGIS JavaScript API:


<!-- Configure dojo for asynchronous module loading -->
  var dojoConfig = {
    async : true


Note: You can only set the async flag before the ArcGIS JavaScript API is loaded.




Q: What does the viewport meta tag do? The JavaScript API samples frequently include the following comment <meta> tag near the beginning of the <head> section of the HTML page:

<!-- The viewport meta tag is used to improve the presentation
     and behavior of the samples on iOS devices -->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">


A: The viewport meta tag allows the developer to control how pages are displayed on mobile devices. The viewport is the virtual page on which content is laid out. It can be larger or smaller than the mobile device's actual screen. Users then pan-and-zoom to see different areas of page. "initial-scale=1" sets the viewport width and height to that of the device. "user-scalable=no" prevents the user from zooming in and out. "maximum-scale=1" also limits the user's ability to zoom.




Q: Does Dojo need to be explicitly referenced when building an application using the ArcGIS API for JavaScript, or is it included in JavaScript API?
A: No, explicitly referencing Dojo is not required. Referencing the JavaScript API also provides access to Dojo.




Q: How much Dojo do you need to know to work with the JavaScript API?
A: How much you need to know depends on what you need to do. You can build full-featured applications using just the JS API. Knowing Dojo is not necessary, but many things you can do with HTML, CSS and JavaScript are simpler using Dojo. If you need to build your own widgets and tasks, then knowing Dojo is essential.



2 people found this helpful