Select to view content in your preferred language

Try to add a graphic layer but got 'TypeError: this.map.addLayer is not a function

1534
10
Jump to solution
05-20-2023 09:04 AM
chunguangWayneZhang
New Contributor III

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.

-------------------------------------------------------------------------------------------------------------

layer.queryFeatures(featureQuery, lang.hitch(this, function (featureSet) {             //there is a lang.hitch here

                  if (featureSet && featureSet.features.length > 0) {
                    var parcelSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
                      new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                        Color.fromArray([0, 255, 255]),
                        //new Color([0, 255, 255]),
                        4))
                    var marketgraphics = new GraphicsLayer({
                      graphics: featureSet.features
                    });

                    this.map.addLayer(marketgraphics);  //here is the error
0 Kudos
10 Replies
chunguangWayneZhang
New Contributor III

Hi KenBuja,

That did remove the error. So it is the top of the function that is way back up that needs a LANG.HITCH. It has two three nested functions. Thanks again

0 Kudos