Select to view content in your preferred language

TOC Scale Dependency, not SFV

872
7
06-16-2010 02:56 PM
MelonyBarrett
Occasional Contributor
I started out using Tom Hill's code for the TOC, and love it, but I really needed to be able to see scale dependency.  I found a lot of threads pertaining to the sample flex viewer and love Robert Scheitlin's implementation on his site for the Sample Flex Viewer.  Robert posted a version that supposedly works on for those of us that started out with Tom Hill's code, but it isn't quite working for me.  I can see the scalebar overlay on some of the scale dependent layers, but it's not obeying all of the rules for extent changes and layer toggling.  I can go into more detail if someone can help me.

The code I am using was posted here by Robert:  http://forums.esri.com/Thread.asp?c=158&f=2421&t=295625&mc=1
Has anyone out there had any issues with this code, did you eventually get it working, and if so, how?

Thanks!
Melony
Tags (2)
0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
Melony,

    Are you having issues with layer that have a minscale and maxscale defined? I have seen this issue and have a fix for it.
0 Kudos
MelonyBarrett
Occasional Contributor
Hi Robert,

I'm not sure.  I'm not quite clear on the minscale maxscale thing.  Do I set that somewhere in the code or is it from the .mxd?  In my case, the scale dependency is set in the .mxd.  And yes, as far as I can tell these are the layers that are behaving badly.

Thanks for the quick reply!
Melony
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Melony,

   It is all controlled by the MXD. If you make changes to the min or max scale in the MXD you will have to republish and clear your REST cache before you will see the changes in the TOC though.
0 Kudos
MelonyBarrett
Occasional Contributor
Okay, Robert, I may have gotten somewhere!  When I zoom in beyond the maximum scale, it is properly reflected in the TOC, however, when I zoom out beyond the minimum scale, the sd_overlay is not shown.  So, the scale dependent code is halfway to working perfectly.  Is this the issue you referred to knowing the fix for?!

I've got my fingers crossed!  🙂
Thanks so much for your time!
Melony
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Melony,

   Yep, I think that you are having the issue I have fixed in the attached code.

TocLayerInfoItem.as
////////////////////////////////////////////////////////////////////////////////
//
// Copyright © 2008 ESRI
//
// All rights reserved under the copyright laws of the United States.
// You may freely redistribute and use this software, with or
// without modification, provided you include the original copyright
// and use restrictions.  See use restrictions in the file:
// <install location>/FlexViewer/License.txt
//
////////////////////////////////////////////////////////////////////////////////

package com.esri.solutions.flexviewer.components.toc.tocClasses
{
 
 import com.esri.ags.events.ExtentEvent;
 import com.esri.ags.layers.LayerInfo;
 import com.esri.solutions.flexviewer.SiteContainer;
 
 /**
  * A TOC item representing a member layer of an ArcGIS or ArcIMS map service.
  * This includes group layers that contain other member layers.
  */
 public class TocLayerInfoItem extends TocItem
 {
  public function TocLayerInfoItem( parentItem:TocItem, layerInfo:LayerInfo)
  {
   super(parentItem);
   
   _layerInfo = layerInfo;
   
   label = layerInfo.name;
   
   // Set the initial visibility without causing a layer refresh
   setVisible(layerInfo.defaultVisibility, false);
   
   SiteContainer.getInstance().controller.map.addEventListener(ExtentEvent.EXTENT_CHANGE,checkExtent);
  }
  
  internal static const DEFAULT_MAX:Number = 0;
  
  private var _maxScale:Number = DEFAULT_MAX;
  
  public function set maxScale( value:Number ):void
  {
   _maxScale = value;
   this.scaledependant = true;
   
   if(_maxScale > 0 && _minScale > 0){
    if ((SiteContainer.getInstance().controller.map.scale >= _maxScale) &&
    (SiteContainer.getInstance().controller.map.scale <= _minScale)){
     this.scaledependant = false;
    }   
   } else if (_maxScale > 0 ){
    if ((SiteContainer.getInstance().controller.map.scale >= _maxScale)){
     this.scaledependant = false;
    }
   } else if (_minScale > 0 ) {
    if ((SiteContainer.getInstance().controller.map.scale <= _minScale)){
     this.scaledependant = false;
    }
   } else {
    this.scaledependant = false;
   }
  }
  
  public function get maxScale():Number
  {
   return _maxScale;
  }
  
  private function checkExtent(evt:ExtentEvent):void{
   this.scaledependant = true;
   
   if(_maxScale > 0 && _minScale > 0){
    if ((SiteContainer.getInstance().controller.map.scale >= _maxScale) &&
    (SiteContainer.getInstance().controller.map.scale <= _minScale)){
     this.scaledependant = false;
    }   
   } else if (_maxScale > 0 ){
    if ((SiteContainer.getInstance().controller.map.scale >= _maxScale)){
     this.scaledependant = false;
    }
   } else if (_minScale > 0 ) {
    if ((SiteContainer.getInstance().controller.map.scale <= _minScale)){
     this.scaledependant = false;
    }
   } else {
    this.scaledependant = false;
   }
  }
  
  internal static const DEFAULT_MIN:Number = 0;
  
  private var _minScale:Number = DEFAULT_MIN;
  
  public function set minScale( value:Number ):void
  {
   _minScale = value;
   this.scaledependant = true;
   
   if(_maxScale > 0 && _minScale > 0){
    if ((SiteContainer.getInstance().controller.map.scale >= _maxScale) &&
    (SiteContainer.getInstance().controller.map.scale <= _minScale)){
     this.scaledependant = false;
    }   
   } else if (_maxScale > 0 ){
    if ((SiteContainer.getInstance().controller.map.scale >= _maxScale)){
     this.scaledependant = false;
    }
   } else if (_minScale > 0 ) {
    if ((SiteContainer.getInstance().controller.map.scale <= _minScale)){
     this.scaledependant = false;
    }
   } else {
    this.scaledependant = false;
   }
  }
  
  public function get minScale():Number
  {
   return _minScale;
  }
  
  //--------------------------------------------------------------------------
  //  Property:  layerInfo
  //--------------------------------------------------------------------------
  
  private var _layerInfo:LayerInfo;
  
  /**
   * The map layer info that backs this TOC item.
   */
  public function get layerInfo():LayerInfo
  {
   return _layerInfo;
  }
  
  //--------------------------------------------------------------------------
  //
  //  Methods
  //
  //--------------------------------------------------------------------------
  
  /**
   * @private
   */
  override internal function setVisible( value:Boolean, layerRefresh:Boolean = true ):void
  {
   // Set the visible state of all children, but defer the layer refresh
   for each (var item:TocItem in children) {
    item.setVisible(value, false);
   }
   
   // Set the visible state of this item, but defer the layer refresh
   super.setVisible(value, false);
   
   // Allow the layer refresh now that all changes have been made
   if (layerRefresh) {
    refreshLayer();
   }
  }
 }
}
0 Kudos
MelonyBarrett
Occasional Contributor
Sorry, it took me so long to get back to you.  With your edits, it works!  Yay!  Thanks so much!

Melony
0 Kudos
FaizanTayyab
Deactivated User
I tried your code however, if the layer loading takes time, the scale dependency code falls apart and doesn't work. For example, it works for layer upto a layer that's slow in loading but then fails on the layer that takes time to load. It then also affects all layer below the slow loading layer.

Any ideas?
0 Kudos