I can add a graphic to a layer and then "blink" it using setInterval. But I can not add a graphic to a layer and search for it later via icon button, click and "blink" it. The graphic.visible does not seem to work in this, latter instance. Any suggesti

1780
3
Jump to solution
05-14-2020 06:24 PM
EugeneStaten
New Contributor III

I am working with esri gis api for js 4.15 typescript in an Angular 9 application.

This works:

     var graphic = new graphic({geometry: point, symbol:sign}):

var layer = new GraphicsLayer({id: 'mylayer'});

view.map.add(layer);

layer.when((layerdone)=>{ 

     setInterval(()=>{

            graphic.visible != graphic.visible;

      }, 1000);

});

layer.add(graphic);

But this does not:

var glayer = view.map.layers.find((layer)=>{ layer.id === 'mylayer'});

var graphic = glayer.graphics.find():// lets say its found

var count = 0;

var pulser = setInterval(()=>{

            graphic.visible != graphic.visible;

if((++count) >= 10){

        clearInterval(pulser);

       pulser = undefined;

      graphic.visible = true;

}

}, 1000);

Tags (3)
0 Kudos
2 Solutions

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Eugene,

   You had a couple of issue in your code. Notice in line 3 I return the boolean value in the find function and again in line 4 I return the boolean value. Then in line 6 I changed the way you were setting the graphics visibility.

        // click event for the button
        flashButton.addEventListener("click", function() {
          var glayer = view.map.layers.find((layer)=>{return layer.id === 'mylayer'});
          var graphic = glayer.graphics.find((gra)=>{return gra.geometry.type === 'polygon'});
          setInterval(()=>{
            graphic.visible = !graphic.visible;
          }, 1000);
        });‍‍‍‍‍‍‍‍

View solution in original post

EugeneStaten
New Contributor III

Thanks Robert,

This works!!!   Thanks!!!

Change from != to = ! did the trick.
Cheers to community brain trust.

View solution in original post

0 Kudos
3 Replies
EugeneStaten
New Contributor III

Im using esri api for js 4.15.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Eugene,

   You had a couple of issue in your code. Notice in line 3 I return the boolean value in the find function and again in line 4 I return the boolean value. Then in line 6 I changed the way you were setting the graphics visibility.

        // click event for the button
        flashButton.addEventListener("click", function() {
          var glayer = view.map.layers.find((layer)=>{return layer.id === 'mylayer'});
          var graphic = glayer.graphics.find((gra)=>{return gra.geometry.type === 'polygon'});
          setInterval(()=>{
            graphic.visible = !graphic.visible;
          }, 1000);
        });‍‍‍‍‍‍‍‍
EugeneStaten
New Contributor III

Thanks Robert,

This works!!!   Thanks!!!

Change from != to = ! did the trick.
Cheers to community brain trust.

0 Kudos