AnsweredAssumed Answered

Problem - SketchViewModel Create() fires Legend update

Question asked by Digriz77 on Oct 13, 2019
Latest reply on Feb 10, 2020 by Jorge.Monge



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.