ArcGIS JavaScript API Hack: Measure Selected Features

For those of you who develop using the ArcGIS JavaScript API, have you ever wanted to measure a feature selected on the map?

Measuring the world with ArcGIS Measurement dijit
Measure the world with ArcGIS Measurement dijit

By extending the Measurement dijit, we can add a link to the map.infoWindow object, then add a click event handler to make the measurement dijit to measure the selected feature. The code for adding a link button to the infoWindow is pulled from the Geoprocessing tool link in popup example.  Note: This assumes that the map is loaded with the default Popup dijit. If you’re using a mobile popup, or anything that doesn’t have an actionList class HTML item, this won’t work.

I’ve added a codepen example to show the hack in action. When you click on one of the features, it will have a “Measure me” link at the bottom. Click that, and the measurement dijit will display the area, length, or GPS point of the feature.


The correct measurement geometry type (polygon, line, or point) doesn’t need to be set.  Apparently, the widget picks up the geometry type and gets the appropriate measurement. I was kinda shocked how well it worked the first time.

1 thought on “ArcGIS JavaScript API Hack: Measure Selected Features

  1. Hey, this looks great Ken. What else do I need to do to get it to work, other than place your js file in the measurement widget folder, assuming everything else is default? Thanks, cob

Leave a Reply

Your email address will not be published. Required fields are marked *