Graphics layer above WebMap's portlItem order

533
1
Jump to solution
01-16-2023 08:13 PM
julian_svcs
Occasional Contributor

In my custom map application, I would like to use a portalItem in the WebMap and show a graphics layer (for sketch widget) above this portalItem. I want to use the WebMap portalItem as I have specific graphs and custom text in the popups.

I tried changing the order of adding the portalItem and graphic layer but it does not change this in the Layer List.

const webmap = new WebMap({
});
webmap.portalItem = {
    id: "f2e9b762544945f390ca4ac3671cfa72"
};
webmap.layers.add(graphicsLayer);

or

const webmap = new WebMap({
});
webmap.layers.add(graphicsLayer);
webmap.portalItem = {
    id: "f2e9b762544945f390ca4ac3671cfa72"
};

still shows

julian_svcs_2-1673928364085.png

As it is now, when I draw a graphic using the Sketch widget, the features from the portalItem overlays the drawn graphic.

Is there a way to have the graphics layer above the web map (portalItem)?

Sample code is here.

 

0 Kudos
1 Solution

Accepted Solutions
julian_svcs
Occasional Contributor

I managed to sort this out. I added the webmap.layers.add(graphicsLayer); into a view.when() to load only after the webmap's portalItem is loaded.

const graphicsLayer = new GraphicsLayer({
    title: "Sketch Layer"
});
const webmap = new WebMap({
});
webmap.portalItem = {
    // autocasts as new PortalItem()
    id: "f2e9b762544945f390ca4ac3671cfa72"
};
const view = new MapView({
  map: webmap,
  container: "viewDiv"
});
view.when(() => {
  webmap.layers.add(graphicsLayer);
});

 

View solution in original post

0 Kudos
1 Reply
julian_svcs
Occasional Contributor

I managed to sort this out. I added the webmap.layers.add(graphicsLayer); into a view.when() to load only after the webmap's portalItem is loaded.

const graphicsLayer = new GraphicsLayer({
    title: "Sketch Layer"
});
const webmap = new WebMap({
});
webmap.portalItem = {
    // autocasts as new PortalItem()
    id: "f2e9b762544945f390ca4ac3671cfa72"
};
const view = new MapView({
  map: webmap,
  container: "viewDiv"
});
view.when(() => {
  webmap.layers.add(graphicsLayer);
});

 

0 Kudos