What is Dojo and why is it important to ArcGIS users?
Recently Alex Russell and
Neil Roberts from SitePen were here
in Redlands showing us some of the capabilities of
the Dojo toolkit and how it can greatly simplify your life if you're a
JavaScript developer. We anticipate that a lot of you will be encountering Dojo
soon because the ArcGIS JavaScript API is built on top of it. This post gives
an overview of what Dojo is and what you need to know about it to be successful
when building ArcGIS JavaScript applications.
What is Dojo?
Dojo is a toolkit that helps you write more robust and performant JavaScript
code. JavaScript is a language that runs within the Web browser, and there are
various flavors of Web browser that interpret the JavaScript in slightly
different ways. Toolkits such as Dojo, YUI,
Prototype, and many others are designed
to abstract away the browser idiosyncrasies so that you don't have to learn
them all and handle them in your code.
Additionally, there are often several ways to code the same thing using
JavaScript. Toolkits like Dojo provide functions you can use to do things in
easier or more efficient ways. Using libraries from a toolkit can reduce the
lines of code you write and make your JavaScript applications quicker and more
stable.
What does it mean that the ArcGIS JavaScript API is built on top of Dojo?
The ESRI developers who created the ArcGIS JavaScript API used Dojo to simplify
their development process (Why reinvent things that work?) and to ensure that
the applications you build behave the same in different browsers. For example,
the map zoom and panning animations use Dojo, as does the graphics layer.
Furthermore, the zoom level slider and info windows that you see in your
JavaScript API maps are Dojo widgets (dijits). The slider dijit is provided
with Dojo, and the info window is a custom dijit created by ESRI for the ArcGIS
JavaScript API.
How much Dojo do I need to know in order to use the ArcGIS JavaScript API?
The amount of Dojo you use when you work with the ArcGIS JavaScript API is up to
you, but at a minimum you'll need to use several common functions:
-
dojo.require() – Similar to the <script> include tag on an HTML page. It
imports resources into your JavaScript page.
-
dojo.addOnLoad() - Similar to <body onload="">. It registers an
initializing block called after the page has finished loading and the dijits
have been initialized.
-
dojo.connect() - Similar to the Element.addEventListener and
Element.attachEvent JavaScript functions. It registers a listener to listen to
specific events on an Object or element on the page and returns results from a
function.
-
dojo.byId() - Similar to the document.getElementById(id) JavaScript function.
The function searches and returns the first HTML element with the argument ID.
When writing your ArcGIS JavaScript applications, you can take advantage of the
full Dojo toolkit, which includes buttons, grids, tree views, charts, and other
widgets. The toolkit is divided into three parts:
Core – Essential functions like those listed above
Dijit - Themeable widgets such as trees, menus, and buttons
DojoX- Extension projects in various stages of development, such as graphics,
grids, and charts
How do I get Dojo? Do I have to install it?
Dojo is included with the ArcGIS JavaScript API. When you include this script
tag referencing the ArcGIS JavaScript API, you get access to the full Dojo
tookit version 1.1.0:
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1"></script>
Many Dojo users download Dojo and host it themselves, or they reference the
publicly available Dojo hosted on the AOL Content Delivery Network (CDN). When
building ArcGIS JavaScript applications, there is no need to download or host
Dojo, and you should use the Dojo included with the ArcGIS JavaScript API.
How do I get help with Dojo?
The Dojo Web site, www.dojotoolkit.org
contains the official Dojo documentation. Documentation may be sparse,
especially for projects in DojoX. Various
books have recently become available that describe working with Dojo in
more detail than you'll find on the web site. The
Dojo forums and the #dojo chat room on the
IRC server irc.freenode.net are other good ways to get help.
Do the ESRI Web ADFs use Dojo?
At 9.3, ESRI's .NET Web Application Developer Framework (ADF) contains a
JavaScript library which should not be confused with the ArcGIS JavaScript API.
The .NET Web ADF JavaScript library is dependent on the ASP.NET AJAX JavaScript
Library and does not use Dojo.
The Java Web ADF also provides a JavaScript library, which was not written with
a toolkit and consequently does not use Dojo.
-Sterling Quinn