Skip to content

Instantly share code, notes, and snippets.

@raykendo
Last active August 29, 2015 14:23
Show Gist options
  • Save raykendo/130e6aca109832d683d1 to your computer and use it in GitHub Desktop.
Save raykendo/130e6aca109832d683d1 to your computer and use it in GitHub Desktop.
ArcGIS JSAPI: Measurement + Popup Combo
/*
* Custom Measurement Widget extension that connects to Popup dijit (esri/dijit/Popup),
* retrieves the selected feature, then passes the geometry to be measured by the Measurement Dijit.
*/
define("custom.Measurement",
[
"dojo/_base/declare",
"dojo/_base/lang",
"esri/dijit/Measurement",
"dojo/query",
"dojo/on",
"dojo/dom-construct"
],
function (declare, lang, Measurement, dojoQuery, dojoOn, domConstruct) {
return declare([Measurement], {
postCreate: function () {
this.inherited(arguments);
// check if the infoWindow exists
if (this.map && this.map.infoWindow) {
// ad
var node;
try {
node = domConstruct.create("a", {
innerHTML: "Measure me",
href: "javascript:void(0);"
}, dojoQuery(".actionList", this.map.infoWindow.domNode)[0]);
} catch(err) {
// probably could not get to the actionList class item.
}
if (node) {
dojoOn(node, "click", lang.hitch(this, this._calculateGraphicItem));
}
}
},
// when link clicked, this gets the selected feature and measure the geometry.
_calculateGraphicItem: function (evt) {
var graphic = this.map.infoWindow.getSelectedFeature();
if (graphic && graphic.geometry) {
this.measure(graphic.geometry);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment