Select to view content in your preferred language

Add feature layers with @arcgis/map-components-react

141
2
Monday
jvpelt
by
New Contributor

Hi,

I'm migrating our react application from @ArcGIS/core to @ArcGIS/map-components-react and got most of it working. But I can't seem to figure out how to add a feature layer using these new components. I used to invoke the map.add() function but I no longer have a reference to a map object and don't see a component which represents what I need.

Is there some documentation on the subject that I'm missing or someone can point me to.

Thanks, John

0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor II

The map and scene components have methods to add layers, addLayer and add layers.

https://developers.arcgis.com/javascript/latest/references/map-components/?path=/docs/component-refe...

So you can create a layer like you normally would and add it to the component.

Here's a sample adding a graphics layer and using sketch

https://codepen.io/odoe/pen/eYwzRER

jvpelt
by
New Contributor

Thanks @ReneRubalcava your refs pointed me in the right direction. For those wondering how to make it work with the @arcgis/map-components-react package this is what I came up with:

 

      <ArcgisMap
        itemId={process.env.NX_ArcGISPortalItem}
        basemap="topo-vector"
        spatialReference={SpatialReference.WebMercator}
        zoom={buildZoom({centerLoc, zoom})}
        center={centerPoint}
        onArcgisViewReadyChange={event => setMapRef(event.target.map)} // This is the magic where we get a ref to the map which makes everything possible again :)
        onArcgisViewClick={onArcGISViewClick}
      >