ThinkGeo.com    |     Documentation    |     Premium Support

Hide Virtual Earth when Zooming to not supported scale

Hello,


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


.e.g 


zoomlevel 1 (scale = virtualearthzoomlevelset.zoomlevel01)

.

.

 

zoomlevel 20 (scale = virtualearthzoomlevelset.zoomlevel20)

zommlevel 21 (scale = zoomlevel 20 * 0.5)

zommlevel 22 (scale = zoomlevel 20 * 0.25)

.. and so on



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


Thanks Thomas   


 

 



Thomas,



  I think I understand what you need so let me put this forward.  What we want to do is to allow you to control then the VirtualEarthLayer is shown or not.  Currently in its default form it will always show but for reasons you mentioned this is not always desirable.



  What I am doing in the code below is to inherit from the VirtualEarthLayer and the adding some properties that will bound the drawing.  We then override the DrawCore method which is called when the layer draws.  Inside of here we check to see if the current scale is what we have bounded in the properties.  If it is ok then we call the base method, if not then we do not call the base method and nothing happens.  The code should be fairly straight forward.  



Let me know if this does what you need. BTW I was not able to test this before posting but you can put breakpoints in and debug it.  Any changes should be minor, I am fairly certain about the logic and structure of what needs to 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);
            }
        }
    }