# Hide Virtual Earth when Zooming to not supported scale

**URL:** <https://community.thinkgeo.com/t/hide-virtual-earth-when-zooming-to-not-supported-scale/842>\
**Category:** WinForms\
**Created:** [November 14, 2009, 2:23pm UTC](https://community.thinkgeo.com/t/hide-virtual-earth-when-zooming-to-not-supported-scale/842 "2009-11-14T14:23:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@Thomas](https://community.thinkgeo.com/u/Thomas)\
**Post date:** [November 14, 2009, 2:23pm UTC](https://community.thinkgeo.com/t/hide-virtual-earth-when-zooming-to-not-supported-scale/842/1 "2009-11-14T14:23:33Z")

</div>

Hello,

we&nbsp;use&nbsp;several&nbsp;shapefile&nbsp;layer&nbsp;on&nbsp;top&nbsp;of&nbsp;virtual&nbsp;earth&nbsp;layer&nbsp;that&nbsp;is&nbsp;used&nbsp;as&nbsp;background&nbsp;map.While&nbsp;we&nbsp;need&nbsp;to&nbsp;zoom&nbsp;in&nbsp;very&nbsp;deep&nbsp;on&nbsp;the&nbsp;shapefile&nbsp;layer&nbsp;we&nbsp;want&nbsp;to&nbsp;increase&nbsp;the&nbsp;zoomlevels&nbsp;by&nbsp;creating&nbsp;our&nbsp;own&nbsp;zoomlevelset&nbsp;that&nbsp;has&nbsp;the&nbsp;virtual&nbsp;earth&nbsp;scale&nbsp;and&nbsp;additional&nbsp;scales&nbsp;to&nbsp;zoom&nbsp;in

.e.g&nbsp;

zoomlevel&nbsp;1&nbsp;(scale&nbsp;=&nbsp;virtualearthzoomlevelset.zoomlevel01)  
  
.  
  
.  
  
&nbsp;  
  
zoomlevel&nbsp;20&nbsp;(scale&nbsp;=&nbsp;virtualearthzoomlevelset.zoomlevel20)  
  
zommlevel&nbsp;21&nbsp;(scale&nbsp;=&nbsp;zoomlevel&nbsp;20&nbsp;\*&nbsp;0.5)  
  
zommlevel&nbsp;22&nbsp;(scale&nbsp;=&nbsp;zoomlevel&nbsp;20&nbsp;\*&nbsp;0.25)  
  
..&nbsp;and&nbsp;so&nbsp;on

Because&nbsp;virtual&nbsp;earth&nbsp;can&nbsp;not&nbsp;zoom&nbsp;in&nbsp;higher&nbsp;than&nbsp;zommlevel20&nbsp;we&nbsp;want&nbsp;to&nbsp;hide&nbsp;virtual&nbsp;earth&nbsp;layer.&nbsp;Is&nbsp;there&nbsp;an&nbsp;property&nbsp;on&nbsp;zoomlevel&nbsp;we&nbsp;can&nbsp;tell&nbsp;the&nbsp;virtual&nbsp;earth&nbsp;layer&nbsp;to&nbsp;be&nbsp;only&nbsp;shown&nbsp;on&nbsp;zoomlevel&nbsp;1-20&nbsp;or&nbsp;how&nbsp;can&nbsp;we&nbsp;achieve&nbsp;this?

Thanks&nbsp;Thomas&nbsp;&nbsp;&nbsp;

&nbsp;  
  
&nbsp;

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [November 15, 2009, 6:10pm UTC](https://community.thinkgeo.com/t/hide-virtual-earth-when-zooming-to-not-supported-scale/842/2 "2009-11-15T18:10:55Z")

</div>

Thomas,  
  
  
  
&nbsp;&nbsp;I&nbsp;think&nbsp;I&nbsp;understand&nbsp;what&nbsp;you&nbsp;need&nbsp;so&nbsp;let&nbsp;me&nbsp;put&nbsp;this&nbsp;forward.&nbsp;&nbsp;What&nbsp;we&nbsp;want&nbsp;to&nbsp;do&nbsp;is&nbsp;to&nbsp;allow&nbsp;you&nbsp;to&nbsp;control&nbsp;then&nbsp;the&nbsp;VirtualEarthLayer&nbsp;is&nbsp;shown&nbsp;or&nbsp;not.&nbsp;&nbsp;Currently&nbsp;in&nbsp;its&nbsp;default&nbsp;form&nbsp;it&nbsp;will&nbsp;always&nbsp;show&nbsp;but&nbsp;for&nbsp;reasons&nbsp;you&nbsp;mentioned&nbsp;this&nbsp;is&nbsp;not&nbsp;always&nbsp;desirable.  
  
  
  
&nbsp;&nbsp;What&nbsp;I&nbsp;am&nbsp;doing&nbsp;in&nbsp;the&nbsp;code&nbsp;below&nbsp;is&nbsp;to&nbsp;inherit&nbsp;from&nbsp;the&nbsp;VirtualEarthLayer&nbsp;and&nbsp;the&nbsp;adding&nbsp;some&nbsp;properties&nbsp;that&nbsp;will&nbsp;bound&nbsp;the&nbsp;drawing.&nbsp;&nbsp;We&nbsp;then&nbsp;override&nbsp;the&nbsp;DrawCore&nbsp;method&nbsp;which&nbsp;is&nbsp;called&nbsp;when&nbsp;the&nbsp;layer&nbsp;draws.&nbsp;&nbsp;Inside&nbsp;of&nbsp;here&nbsp;we&nbsp;check&nbsp;to&nbsp;see&nbsp;if&nbsp;the&nbsp;current&nbsp;scale&nbsp;is&nbsp;what&nbsp;we&nbsp;have&nbsp;bounded&nbsp;in&nbsp;the&nbsp;properties.&nbsp;&nbsp;If&nbsp;it&nbsp;is&nbsp;ok&nbsp;then&nbsp;we&nbsp;call&nbsp;the&nbsp;base&nbsp;method,&nbsp;if&nbsp;not&nbsp;then&nbsp;we&nbsp;do&nbsp;not&nbsp;call&nbsp;the&nbsp;base&nbsp;method&nbsp;and&nbsp;nothing&nbsp;happens.&nbsp;&nbsp;The&nbsp;code&nbsp;should&nbsp;be&nbsp;fairly&nbsp;straight&nbsp;forward.&nbsp;&nbsp;  
  
  
  
Let&nbsp;me&nbsp;know&nbsp;if&nbsp;this&nbsp;does&nbsp;what&nbsp;you&nbsp;need.&nbsp;BTW&nbsp;I&nbsp;was&nbsp;not&nbsp;able&nbsp;to&nbsp;test&nbsp;this&nbsp;before&nbsp;posting&nbsp;but&nbsp;you&nbsp;can&nbsp;put&nbsp;breakpoints&nbsp;in&nbsp;and&nbsp;debug&nbsp;it.&nbsp;&nbsp;Any&nbsp;changes&nbsp;should&nbsp;be&nbsp;minor,&nbsp;I&nbsp;am&nbsp;fairly&nbsp;certain&nbsp;about&nbsp;the&nbsp;logic&nbsp;and&nbsp;structure&nbsp;of&nbsp;what&nbsp;needs&nbsp;to&nbsp;happen.  
  
  
  
David  
  
  
  
`    public class BoundedVirtualEarthLayer : VirtualEarthLayer    {        double upperScale;        double lowerScale;        // This constructor is the default and it just calls the main one with default values        public BoundedVirtualEarthLayer()            : this(double.MaxValue, 0)        { }        // This is the mian constructor and allows you to pass in the upper and lower        // scales the layer will be bounded to        public BoundedVirtualEarthLayer(double upperScale, double lowerScale)        {            this.upperScale = upperScale;            this.lowerScale = lowerScale;        }        // This is the upper scale.  Above this scale the layer will not draw        public double UpperScale        {            get { return upperScale; }            set { upperScale = value; }        }        // This is the lower scale.  Below this scale the layer will not draw        public double LowerScale        {            get{return lowerScale;}            set{lowerScale = value;}        }        // Here we override the DrawCore methos and we check the current scale.  If it is within our        // bounderies then we draw it by calling into the base, if not then we just ignore the call.        protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)        {            double currentScale = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit);            if (currentScale >= lowerScale && currentScale <= upperScale)            {                base.DrawCore(canvas, labelsInAllLayers);            }        }    }`&nbsp;
