HI m making use of the drawbox dijit but I dont want my users to have access to all the drawing options.
After looking at the drawbox dijit it seems I just want to call "this.drawBox.activate('EXTENT')" then I can do stuff _onDrawComplete.
but Im not sure why I cant call my function from the HTML.
Hers my js, Im trying to call the grabArea function from my HTML
define(['dojo/_base/declare',
'jimu/BaseWidget',
'dijit/_WidgetsInTemplateMixin',
'dojo/_base/html',
'dojo/_base/lang',
'dojo/on',
'jimu/dijit/drawbox',
],
function(declare, BaseWidget, _WidgetsInTemplateMixin, html, lang, on, Drawbox) {
var clazz = declare([BaseWidget, _WidgetsInTemplateMixin], {
baseClass: 'jimu-widget-JimDrawbox',
name: 'JimDrawbox',
drawBox: null,
_initStuff: function(){
this.drawBox = new Drawbox;
},
postCreate: function() {
this.inherited(arguments);
this._initStuff();
this.drawBox.setMap(this.map);
this.drawBox.types = ["EXTENT"];
this.drawBox.keepOneGraphic = true;
this.own(on(this.drawBox, 'DrawEnd', lang.hitch(this, this._onDrawComplete)));
console.log(this.drawBox.types)
//this.drawBox.activate('EXTENT')
},
grabArea: function() {
this.drawBox.activate('EXTENT')
},
_onDrawComplete: function(graphic) {
var geometry = graphic.geometry;
console.log(geometry);
}
});
And here's my HTML
<div>
<button class ="button" onclick="this.grabArea()">Click to draw extent</button>
</div>
I just keep getting
Uncaught TypeError: this.grabArea is not a function
at HTMLButtonElement.onclick
So it seems my grabArea function isnt visible to the HTML at that point, but I'm not sure why.
JS isnt my main language so Im struggling a bit to resolve it.
Finding WAB one of the hardest frameworks I've come across to decipher so far...
Solved! Go to Solution.
James,
Now you are mixing declarative and programmatic creation of the DrawBox dijit. You already have declarative creation of the dijit in your html so you do Not create it in your code as well.
define(['dojo/_base/declare',
'jimu/BaseWidget',
'dijit/_WidgetsInTemplateMixin',
'dojo/_base/html',
'dojo/_base/lang',
'dojo/on',
'jimu/dijit/DrawBox'
],
function (declare, BaseWidget, _WidgetsInTemplateMixin, html, lang, on, Drawbox) {
var clazz = declare([BaseWidget, _WidgetsInTemplateMixin], {
baseClass: 'jimu-widget-JimDrawbox',
name: 'JimDrawbox',
postCreate: function () {
this.inherited(arguments);
this.drawBox.setMap(this.map);
this.drawBox.keepOneGraphic = true;
this.own(on(this.drawBox, 'DrawEnd', lang.hitch(this, this._onDrawComplete)));
},
_onDrawComplete: function (graphic) {
var geometry = graphic.geometry;
console.log(geometry);
}
});
});
<div>
<div data-dojo-attach-point="drawBox" data-dojo-type="jimu/dijit/DrawBox" data-dojo-props="types:['extent'],showClear:false" style="margin-top:5px;"></div>
<div data dojo attach point="selectionmenu"></div>
</div>
But another thing to consider is there is no need for a seperate dijit/widget to be created by you anymore. You should just be adding the drawBox html portion to your widgets html code directly and all the logic to your actual widgets.js
I dont get it, this code doesnt work for me because we havent gor drawbox initiated. So I ended up adding this.drawBox = new Drawbox; again but I end up with a blank widget wioth no button to start the extent.
Im most confused, I thought I was getting there but now Im confused again. At what point is my widget being inserted in the dojo attach point and what peice of code does it as it looks like that just doesnt happen?
So I have realised the name of the dojo attach point was different to the references to it in the code. So my attachpoint is drawBox again, this removed the undefined errors so I didnt need a this.drawBox = new Drawbox; but this still just leaves me with a blank panel with no controls in it.
I was expecting the draw extent dijit so I could click it and draw an extent. The code works without errors but there are no dijits in the panel, its just blank. Thats why I ended up trying the HTML place to get it in the widget.
define(['dojo/_base/declare',
'jimu/BaseWidget',
'dijit/_WidgetsInTemplateMixin',
'dojo/_base/html',
'dojo/_base/lang',
'dojo/on',
'jimu/dijit/DrawBox',
'dojo/dom'
],
function(declare, BaseWidget, _WidgetsInTemplateMixin, html, lang, on, Drawbox, dom) {
var clazz = declare([BaseWidget, _WidgetsInTemplateMixin], {
baseClass: 'jimu-widget-JimDrawbox',
name: 'JimDrawbox',
drawBox: null,
postCreate: function() {
this.inherited(arguments);
this.drawBox.setMap(this.map);
this.drawBox.keepOneGraphic = true;
this.own(on(this.drawBox, 'DrawEnd', lang.hitch(this, this._onDrawComplete)));
},
_onDrawComplete: function(graphic) {
var geometry = graphic.geometry;
this.drawBox.deactivate();
console.log(geometry);
}
});
return clazz;
});
<div>
<div data-dojo-attach-point="drawBox" data-dojo-type="jimu/dijit/DrawBox" data-dojo-props="types:['EXTENT'],showClear:false" style="margin-top:5px;"></div>
<div data-dojo-attach-point="selectionmenu"></div>
</div>
So I have created 2 drawbox in my code now to test this.
One declarative as described above, drawBox and also one created programatic, db2.
The declarative drawBox results in nothing in my widget panel.
And the programatic db2, does appear in my widget panel but is not limited to only the extent button, I get all the geo types even though types is set to ['EXTENT'].
define(['dojo/_base/declare',
'jimu/BaseWidget',
'dijit/_WidgetsInTemplateMixin',
'dojo/_base/html',
'dojo/_base/lang',
'dojo/on',
'jimu/dijit/DrawBox',
'dojo/dom'
],
function(declare, BaseWidget, _WidgetsInTemplateMixin, html, lang, on, Drawbox, dom) {
var clazz = declare([BaseWidget, _WidgetsInTemplateMixin], {
baseClass: 'jimu-widget-JimDrawbox',
name: 'JimDrawbox',
drawBox: null,
db2: null,
postCreate: function() {
this.inherited(arguments);
this.drawBox.setMap(this.map);
this.drawBox.keepOneGraphic = true;
this.own(on(this.drawBox, 'DrawEnd', lang.hitch(this, this._onDrawComplete)));
this._createtestingwidget();
},
_createtestingwidget: function(){
this.db2 = new Drawbox;
this.db2.setMap(this.map);
this.db2.types=['EXTENT'];
this.db2.keepOneGraphic = true;
this.own(on(this.db2, 'DrawEnd', lang.hitch(this, this._onDrawComplete)));
html.place(this.db2.domNode, this.testing);
},
_onDrawComplete: function(graphic) {
var geometry = graphic.geometry;
this.drawBox.deactivate();
console.log(geometry);
}
});
return clazz;
});
<div><div>declarative</div>
<div data-dojo-attach-point="drawBox" data-dojo-type="jimu/dijit/DrawBox" data-dojo-props="types:['EXTENT'],showClear:false" style="margin-top:5px;"></div>
<div>programatic</div>
<div data-dojo-attach-point="testing"></div>
</div>
Im not sure why setting the first one doesnt appear at all, and I dont know whay the second one shows all types not just extent.
These are the problems I encountered before that led me try creating my own button that calls
this.drawBox.activate('EXTENT')
I've kind of gone full circle! But I would like to get this declarative method to work with only extent available...
Whats causing the first attempt to not show anything at all (drawBox)?
How do I limit it to only show extent in the second method (db2)?
James,
So digging into the DrawBox dijit I now see if you only want the extent option to be avaialabel you need to use "geoTypes" not "types" on the dijit. Also I am not sure why your declarative of DrawBox is not working for you but here is a zip of the way I would build this widget from scratch that works using the declarative method.
hi Robert, thank again for taking a look.
I have tried types, geoTypes and setting both but I always get all the options not just the extent option.
Im not sure how to access the zip you mentioned, I cant see it.
James,
You have to open the repy (click on the title inside your inbox) . You can not see attachments inside you inbox. Also the geoTypes values have to be in all caps (i.e. "EXTENT")
Hi Robert,
I am unable to find the zip in my inbox, I can see a single entry in there for all the replies in this thread but I cant see any attachments or files.
I have used ['EXTENT'] for types and geoTypes but it seems to have no effect.
Heres my code where I have tried 3 methods to get just an extent drawbox thing:
<div>
<div>declarative</div>
<div data-dojo-attach-point="drawBox" data-dojo-type="jimu/dijit/DrawBox" data-dojo-props="types:['EXTENT'],showClear:false" style="margin-top:5px;"></div>
<div>programatic</div>
<div data-dojo-attach-point="testing"></div>
<div>Make my own button!</div>
<button class="button" data-dojo-attach-point="drawBtn">Extent</button>
</div>
define(['dojo/_base/declare',
'jimu/BaseWidget',
'dijit/_WidgetsInTemplateMixin',
'dojo/_base/html',
'dojo/_base/lang',
'dojo/on',
'jimu/dijit/DrawBox',
'dojo/dom'
],
function(declare, BaseWidget, _WidgetsInTemplateMixin, html, lang, on, Drawbox, dom) {
var clazz = declare([BaseWidget, _WidgetsInTemplateMixin], {
baseClass: 'jimu-widget-JimDrawbox',
name: 'JimDrawbox',
db2: null,
postCreate: function() {
this.inherited(arguments);
//this is the declarative method, the drawBox is declared in the HTML
//But nothing appears in the widget panel...
this.drawBox.setMap(this.map);
this.drawBox.keepOneGraphic = true;
this.own(on(this.drawBox, 'DrawEnd', lang.hitch(this, this._onDrawComplete)));
this.drawBox.enable();
//This is the programatic method, unable to restrict drawing options...
//I have set types and geoTypes to no effect.
this._createtestingwidget();
//attach a function that calls this.drawBox.activate('EXTENT')
//this works but Im not really making use of the dijit and its preset icons etc.
//could this method using the same drawBox object be the reason it doesnt
//display for the first method? doesnt seem likely
this._buttonsetup();
},
_createtestingwidget: function(){
this.db2 = new Drawbox;
this.db2.setMap(this.map);
this.db2.types=['EXTENT'];
this.db2.geoTypes=['EXTENT'];
this.db2.keepOneGraphic = true;
this.own(on(this.db2, 'DrawEnd', lang.hitch(this, this._onDrawComplete)));
html.place(this.db2.domNode, this.testing);
},
_onDrawComplete: function(graphic) {
var geometry = graphic.geometry;
this.drawBox.deactivate();
console.log(geometry);
},
_buttonsetup: function(){
this.own(on(this.drawBtn, "click", lang.hitch(this, this._grabArea)))
},
_grabArea: function() {
this.drawBox.activate('EXTENT')
},
});
return clazz;
});
The only one that worked was the 3rd one but I know this isnt the way Im supposed to do it.
Id really like to get the declarative one displaying but have no idea why it isnt...
Declarative: no display
Programatic : not limited to extent
Button: Works but Im not really using the dijit properly.
James,
In my attachment I have a fully functioning declarative example widget.
So you need to open the thread as I mentioned earlier you Can Not see attachments inside your inbox.
You can just click on the threads title in your inbox or right click it and choose to open in new tab.
Thanks robert, I finally have my declarative method wroking. I was only using types not geoTypes in the HTML, which I completely missed as I was looking in the js for the error.
I still have no idea why the second one doesn't restrict to extent but Im not going to worry about it.
Thanks for all the help, Im just hoping the query and selection gives me less issues!