Problem - SketchViewModel Create() fires Legend update

535
3
10-13-2019 05:46 PM
DavidDoyle
New Contributor

HI,

My setup -

  • Javascript api 4.13
  • I have around 40 layers.  Mainly MapImageLayers.
  • I use the LayerList widget and have added the Legend in a container. using listItemCreatedFunction.
  • Im using the SketchViewModel to create a Polygon, Point and Polyline tools.  
  • I have a Graphic Layer that the drawings go into, this is added to the view. but is hidden on the layer list

My Problem.

  • When i click on the Polygon tool which fires the create method of the sketchviewmodel.  I get around a 5-8 seconds lag before I can start drawing.
  • the lag disapears if i have the graphic layer hidden aswell as legend off.  if i do graphic visible in LayerList i get the lag even with legend off.
  • I found that when I click Create the layerlists listItemCreateFunction fires  as well as the legend update which then goes through and regrabs every layers legend again.  however this only fires if i have legend in the layerlist container with the GraphicLayer hidden.
  • Another stange thing which i dont know if its normal is that the listItemCreatedFunction runs 9 times (even on startup)  So if i put a watch on the listItemCreatedFunction and log the layers.  I see my 40 layers list out 9 times.
    • I have checked and my operational layers are only there once.I dont have multiple instances of LayerList.
  • The same issue happens on sketchviewmodel Complete.  So completing a polygon i get 8 second lag while the legend repopulates and the listItemCreatedFunction runs for all layers.

I have made sure my legend isnt enabled for my graphic layer.  i cant understand why the legend is refreshing for all my layers.

I have also tried the Sketch widget.  It has the same lag.

Is there a way to disable that?

My Code

The following is in view.when:

var layerList = new LayerList({
view: view,
listItemCreatedFunction: defineActions
});

function defineActions(event) {

var item = event.item;
item.panel = {
content: "legend",
open: false
};
}

here is where i tested the sketch widget that has the same lag

var sketch = new Sketch({
layer: tmp_Cosmetic,
view: view
});

 view.ui.add(sketch, "top-right");

tmp_Cosmetic is my graphic layer.

0 Kudos
3 Replies
Jorge_LuisMonge_Blanco
New Contributor

I have observed the same behavior. In my case, the Select tool and the Measure tool, both fire the function declared for 'listItemCreatedFunction'. Also, when the LayerList is created (for the first time), it executes the function declared for 'listItemCreatedFunction' 4 times. This even happens in the example for this feature in the Esri website (LayerList widget with actions | ArcGIS API for JavaScript 4.14 )

0 Kudos
NilsBabel1
Occasional Contributor

Any update on this?  I believe I'm having the exact same problem.

0 Kudos
NilsBabel1
Occasional Contributor

Any update on this?  I believe the issue is more pronounced in the 4.19 release.  I create a legend in the item panel of the layerlist with the list item created function.  I have multiple layers in my map and the performance is terrible.  As soon as I disable the legend the performance increases.  Sketch and measure tools work better too.  

0 Kudos