Skip to content

Instantly share code, notes, and snippets.

@odoe
Created May 11, 2015 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/da7a0ba4033a3e711bda to your computer and use it in GitHub Desktop.
Save odoe/da7a0ba4033a3e711bda to your computer and use it in GitHub Desktop.
Sample measurement widget
define([
'dojo/_base/declare',
'dojo/topic',
'dojo/dom',
'dojo/dom-construct',
'esri/dijit/Measurement',
'dijit/_WidgetBase',
'dijit/_TemplatedMixin',
'dojo/text!./templates/Template.html'
], function(
declare, topic,
dom, domConstruct,
Measurement,
_WidgetBase, _TemplatedMixin,
template
) {
return declare([_WidgetBase, _TemplatedMixin], {
templateString: template,
constructor: function() {
this.toolHidden = true;
},
postCreate: function() {
var target = dom.byId('map_root');
var node = domConstruct.create('div', {
className: 'measurement-container'
}, target);
this.measure = new Measurement({
map: this.get('map')
}, node);
this.measure.startup();
this.measure.hide();
this.own(topic.subscribe('widget-tool-show', function(a) {
if (a.type !== 'measurement' && !this.toolHidden) {
this.toggle();
}
}.bind(this)));
},
toggle: function(e) {
if (e) e.preventDefault();
if (this.toolHidden) {
topic.publish('widget-tool-show', { tool: 'measurement' });
this.measure.show();
} else {
topic.publish('widget-tool-hide', { tool: 'measurement' });
this.measure.hide();
}
this.toolHidden = !this.toolHidden;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment