I am developing a Validation Widget that can tell if the free-drawn-polygon is inside the state boundary or not. I have the ArcGIS JavaScript code which run well in the Sandbox. The code is to use button-click to draw a polygon, and pass the polygon geometry into a query, then check the length of result. See the sandbox code (works) attached.
In the widget.js, I have added the jimu/dijit/DrawBox in the widget. I cannot figure out passing the drawn-polygon created by the DrawBox into my query. I tried the code attached and the error message showed “geometry null” and “queryTask.execute is not a function”. I am new to WAB and would appreciate some suggestions. The widget.js (not working) is attached.
Additionally, I know the WAB has a Query Widget. I look at the widget.js, which uses dojo/query, instead of esri/tasks/query. I wonder if I need to replace with dojo/query to make my widget run.
Thanks,
Helen
Solved! Go to Solution.
Thanks for the helpful code. After I add the dependency 'dojo/_base/lang', the widget works very well! Very appreciated!
this.own(on(this.drawBox, 'DrawEnd', lang.hitch(this, this._onDrawComplete)));
is very powerful! It makes the connection between the Draw-box with my query.
I think lang.hitch is kindly like function/event. What does “own” means and why puts “own” inside postCreate?
I found some information below for “own” but do not fully understand.
--most of the things that you define inside .own() are getting correctly removed once the widget itself is destroyed. Using .own() prevents memory leaks in your app.
For your question about "dojo/query" versus "esri/tasks/query", these are two very different things.
dojo/query is for querying the DOM to get at its nodes.
Thank you! I see the difference now.
Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.
Robert,
I’d appreciate your great help. I did click “Mark Correct”.
I wonder if you have a chance to explain “.own()” in your code. I see .own() can use inside both postCreate and startup in other code samples.
Thanks,
Helen
Helen,
.own can be used anywhere in a widgets code as it is something that comes from the _widgetBase. What it does is wraps an event handler so that when the widget is destroyed then the event handler is assured to be remove as well.
The advantage of using own() in the widget infrastructure is that internally, the widget can keep track of all of its handles, and make sure everything is disconnected and/or unsubscribed when the widget is destroyed—preventing any kind of memory leaks.