2

I am highlighting graphic using graphic.setSymbol(pictureSymbol). It is working fine. But, when map is zoomed the symbol graphic is reset to default. If anyone has come over the issue, please help! Below is the sample code which I'm using for zooming.

searchGraphic(e){
   var map = this.get('map');
   var layers = this.get('layers');
    var searchTerm = document.querySelector('.searchitem-node input').value;
   this.set('searchTerm', searchTerm);
   var selectedPictureSymbol = null;
   var pictureSymbol = null;
   var i = null;
   var j = null;
   var k = null;
   //if search button clicked
   if(searchTerm && e){
      e.preventDefault();
      searchTerm = searchTerm.toLowerCase();
   }
   for(i in layers){
      for(j in layers[i]){
         for(k in layers[i][j].graphics){
            if(layers[i][j].graphics[k].attributes.name){
               if(layers[i][j].graphics[k].attributes.name.toLowerCase() === searchTerm){
                  selectedPictureSymbol = this.highlightGraphics(layers[i][j].graphics[k], true);
                  this.set('graphic', layers[i][j].graphics[k]);
                  this.set('lineG', layers[i][j].graphics[k]);
               }else{
                  console.log('graphics ! found');
                  pictureSymbol = this.highlightGraphics(layers[i][j].graphics[k], false);
               }
            }
         }
      }
   }
   //if graphics not found then set graphics to blank for unselecting selected item
   if(searchTerm && e){
      if(!selectedPictureSymbol){
         console.log('set graphics blank');
         this.set('formClass', 'circuit-form');
         this.set('graphic', '');
         this.closeForm();
  }else{
      var graphic = this.get('graphic');
      if (graphic.geometry.type === 'point') {
         var maxZoom = map.getMaxZoom();
         map.centerAndZoom(graphic.geometry, maxZoom - 4);
      }else{
         var extent = GraphicsUtils.graphicsExtent([graphic]);
         console.log(extent);
         extent.xmax = extent.xmax + 50;
         extent.ymax = extent.ymax + 50;
         extent.xmin = extent.xmin - 50;
         extent.ymin = extent.ymin - 50;
         map.setExtent(extent);
      }
   }
}
5
  • Could you please clarify "when map is zoomed the graphic symbol is reset" - do you mean that any time the user zooms the map manually (not through code) the graphic symbol is reset? I can't see anything in your code snippet which would cause this to happen, so is it possible there is other code running? What causes the above code to run - is it on page load or another event? Commented Feb 9, 2016 at 5:42
  • Both, at the time of manual zoom and by code 'centerAndZoom'. I have a input field, I type in the name to search an object. If the object is found it is centered and zoomed. Commented Feb 9, 2016 at 6:15
  • In which step you are affetcing the style ? graphic.setSymbol(pictureSymbol) Commented Feb 9, 2016 at 8:05
  • this.resetHighlight(); this.activateItemForm(selectedPictureSymbol); } The above lines are missing in the code. The 'activateItemForm' has graphic.setSymbol(pictureSymbol) Commented Feb 9, 2016 at 9:58
  • Please use the edit button beneath your question to provide any additional information. There is a 2-minute Tour that every user of this site is expected to take so that they begin to be familiar with the site's protocols.
    – PolyGeo
    Commented Sep 28, 2016 at 9:11

0

Browse other questions tagged or ask your own question.