This is something kind of puzzle me. Hope someone can help.
I have a queried feature set that I want to add to the map as a graphic layer.
I have a cope of codes that seems in the right scope with lang.hitch included in the function queryfeatures. but somehow I couldn't get rid of the this.map.addLayer(myGraphicLayer) with 'TypeError: this.map.addLayer is not a function error. I checked community. The error is most like caused by out of scope. But it seems it is not the issue. Thanks for you help.
-------------------------------------------------------------------------------------------------------------
Solved! Go to Solution.
Since it's being called within the showResult function, you'll have to add the lang.hitch here
queryTask.execute(query, lang.hitch(this, showResults));
Are you calling that inside another function? If so, you probably don't have lang.hitch when calling that higher function.
Are you using that snippet inside of another then statement? As an example, I have to use lang.hitch several times in this code that does authentication
esriId
.getCredential(info.portalUrl, {
oAuthPopupConfirmation: true
})
.then(
lang.hitch(this, function () {
this._portal = new arcgisPortal.Portal(this._portalUrl);
this._portal
.signIn()
.then(
lang.hitch(this, function (portalUser) {
this.welcomeNote.innerHTML =
this.nls.welcome + portalUser.firstName + "!";
const portal = portalUser.portal;
const queryParams = {
num: 100,
q: 'owner: ' + this._ownerName + ' AND type: "Feature Service" AND title: "' + this._baseGridLayerName + '"'
};
portal.queryItems(queryParams).then(
lang.hitch(this, function (result) {
if (result.total > 0) {
if (
array.some(
result.results,
lang.hitch(this, function (item) {
if (item.url !== null) {
Actually, it is not called in another then statement or function. Just inside that layer.queryFeatures function. The layer.queryFeatures function is in a ELSE statement.
Thanks again
Can you post the entire function?
This seems has issue with a post. Tried several times to post the whole function but doesn
Since it's being called within the showResult function, you'll have to add the lang.hitch here
queryTask.execute(query, lang.hitch(this, showResults));