concept widget in category arcgis

appears as: widgets, A widget, widget, widgets, widget
ArcGIS Web Development

This is an excerpt from Manning's book ArcGIS Web Development.

Dojo has a library called Dijit, which is used to build the JavaScript components that provide an interface in a web application. The interface could be a form to enter information or it could be a calendar date-picker. A process is in place for building these custom components, commonly referred to as widgets. Using Dojo, a developer can create custom widgets using the Dijit library’s base set of tools, which simplifies the process and makes writing reusable widgets much easier as an application grows. I’ll cover custom widgets in chapters 3 and 4.

You positioned the Measurement widget in a location on the page that’s convenient with respect to other elements such as the map and header. During use, the widget grows in width to accommodate the drop-down menu of measurement units, and it also grows in height, downward, to accommodate displaying the results. Realistically, the upper-left corner of the page is the only area that provides the widget with the room it needs during use. But you may not want the widget to be visible at all times. Wouldn’t it be neat if you could hide or show the widget with a button click? That’s exactly what you’ll do next.

The steps to add the BasemapToggle widget to the application are similar to adding the Measurement widget. Note that because you’ve already added a widget, the base is already there, so for this widget, you only need to add the reference, pass it options, and add a DOM element to bind it to.

Styling and positioning the widget

Then add some CSS to css/main.css to position the widget correctly on the page:

#basemap-div {
  position: absolute;
  top: 55px;
  right: 5px;
  z-index: 1;
}

With everything in place, if you refresh the browser, you should see the BasemapToggle widget. To change the basemap of the map on the application, click the widget (see figure 6.11).

Listing 7.6. config.json—updated options for widget