Pass DrawBox polygon into a query

1552
16
Jump to solution
01-30-2018 08:39 AM
Helenpeng
New Contributor III

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

Tags (1)
0 Kudos
16 Replies
Helenpeng
New Contributor III

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.

0 Kudos
KenBuja
MVP Esteemed Contributor

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.

Helenpeng
New Contributor III

Thank you! I see the difference now. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos
Helenpeng
New Contributor III

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

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

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. 

Helenpeng
New Contributor III

Robert,

Thank you for providing the useful information. Your answer also helps me to understand the structure of other sample widgets. Very appreciated!

Helen

P.S. I would like to attach my widget.html so the future user can have all the files for draw box and query.

0 Kudos