My widget code runs well with the correct result. But I see the reference error in Console Window – it says countyFeatureLayer is not defined.
My widget is to show the query result in Attribute table. I use two queries – the first query is to check if the drawbox-polygon is inside the state boundary. The second query is to intersect with countyFeatureLayer to get the county attribute info. Reading questions in the forum, I use SelectFeatures and show the query result in attribute table.
I define countyFeatureLayer in postCreate. In _onDrawComplete function, I just countyFeatureLayer.selectFeatures. My code does not have the error before using SelectFeatures. Also, I checked my reference, which is same as my sandbox code. I do not know why I get the reference error. See the screenshot.
I also attach my widget zip files.
Thanks,
Helen
Solved! Go to Solution.
Helen,
So on this line you are missing the "this." portion:
console.log("countyFeatureLayer " + countyFeatureLayer.name);
it should be:
console.log("countyFeatureLayer " + this.countyFeatureLayer.name);
Helen,
I can't tell you much without seeing your code but it sounds like a scope issue where the countyFeatureLayer var is not available in the scope of the function you are trying to use it in.
Robert,
I add var countyFeatureLayer; But it can not remove the undefined error. I do not need to define var in my Sandbox code , which runs well with no error.
Though the error does not impact my result, I can receive correct results. But I would like to fix the error. I wonder if you have any suggestions.
My widget code (zipped) is attached in the previous message.
Thanks,
Helen
Helen,
So on this line you are missing the "this." portion:
console.log("countyFeatureLayer " + countyFeatureLayer.name);
it should be:
console.log("countyFeatureLayer " + this.countyFeatureLayer.name);
Robert,
Yes, this is the problem. Thank you for solving my issue. I thought it was some reference or variable problems, never check console.log.
I am kind of new to custom-widget. The forum is very helpful. By reading questions in the forum, I found the way to show query results in attribute table by using SelectFeatures. Much appreciated!
Best,
Helen