Error adding graphicslayer to map (@arcgis/core 4.20)

1531
4
09-09-2021 01:27 AM
FreddyBroring
New Contributor III

Hi,

I'm getting an error when adding a graphiclayer to the map with view.map.add(graphiclayer). When I use view.map.addMany([graphiclayer]) the error doesn't show up.

The console error is:

[esri.support.LayersMixin] #add() The item being added is not a Layer or a Promise that resolves to a Layer.

import GraphicsLayer from '@arcgis/core/layers/GraphicsLayer';
 
const gl = new GraphicsLayer()
view.map.add(gl);   ===> error
 
Is this a bug or is it me doing something wrong?
Tags (1)
0 Kudos
4 Replies
RitikaManderwal
New Contributor III

hi,

i think you need not to write view.map.add(gl) instead of this you can directly do map.add(gl)

0 Kudos
FreddyBroring
New Contributor III

Thanks for the suggestion, but the map is a property of the MapView and is an instance of Map. 

0 Kudos
jauhari_mani
New Contributor III

Hello @FreddyBroring,

I'm experiencing the same issue. Have you found a solution to this problem?

0 Kudos
FreddyBroring
New Contributor III

Hi @jauhari_mani, I can't remember the exact cause of the problem (been a long time). It had something to do with package versions if I recall correcltly. If I were you, then migrate directly to the latest version of the API  and use the latest packages in your package.json if you are using npm and a build tool like webpack.

Also, consult the jsapi resources for examples how to build: https://github.com/Esri/jsapi-resources/tree/main/esm-samples

0 Kudos