ThinkGeo.com    |     Documentation    |     Premium Support

The VirtualEarthLayer example throws an exception

Hi ThinkGeo,


I have some problems with the VirtualEarthLayer example found under "Data Providers" in the Map Suite Sample Application.

I have changed the code for accountId, password, clientIpAddress. 

"When I execute the example an exception is thrown:

The argument value must be between 1 and 21.

Parameter name: Options.ZoomLevel

Actual value was 0."


I guess the ZoomLevelSet has to be called for the VirtualEarthLayer, but this method is not found for the class VirtualEarthLayer.

How can this problem be fixed ?


I am using "DesktopEditionFull3.0.415"


Best regrds

Niels O

 


 


 



Niels, 
  
 That seems a very strange problem; could you show us the code you are trying to use?  That would be very helpful. 
  
 Thanks. 
  
 Yale 


Here is the code from the sample application.  I have just changed the accaountId, password, IpAddress. Further I have added LoadVirtualEarthLayer()  in UseMicrosoftMapsLayer_load(). 

I am using Windows Vista X64.


 


 




        private void UseMicrosoftMapsLayer_Load(object sender, EventArgs e)
        {
            //pictureBox1.Image = Properties.Resources.VirtualEarthResult;
            LoadVirtualEarthLayer();
        }

        private void LoadVirtualEarthLayer()
        {
            // Please set your own information about those parameters below.
            string accountId = "xxxxxx";
            string password = "xxxxxxx";
            string clientIpAddress = "10.1.xx.xx";
            string cacheDirectory = @"c:\temp\";

            VirtualEarthLayer worldLayer = new VirtualEarthLayer(accountId, password, clientIpAddress, cacheDirectory);

            LayerOverlay staticOverlay = new LayerOverlay();
            staticOverlay.Layers.Add("WorldLayer", worldLayer); 
            winformsMap1.Overlays.Add(staticOverlay);

            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
            winformsMap1.CurrentExtent = new RectangleShape(-143.4, 109.3, 116.7, -76.3);

            winformsMap1.Refresh();
        }



Niels, 



I think that's because Virtual Earth's ZoomLevelSet is different from the default one. Please add the one line code "winformsMap1.ZoomLevelSet = new GoogleMapZoomLevelSet();" before "winformsMap1.Refresh();" and have another try. If you still have problem,  please change the winformsMap1.MapUnit to MapUnit.Meter, and change winformsMap1.CurrentExtent to "new RectangleShape(-10000000, 10000000, 10000000, -10000000);" and have a try. The VirtualEarthLayer should only support the MapUnit.Meter, but not MapUnit.DecimalDegree. (The HowDoI sample is not using the right unit)  Let us know what you find out. 



Thanks, 



Ben



Hi Ben,

After many iterations I found a work-around. See the source code shown below. The main trick is the call of ZoomToScale.

Please update your "How Do I" test application :-)

 

And now the final question: Do you know which coordinate system VirtualEarthLayer is using ?


Best regards

Niels Olsen 



            // Please set your own information about those parameters below.
            string accountId = "xxxxx";
            string password = "xxxxxx";
            string clientIpAddress = "10.1.xx.xx";
            string cacheDirectory = @"c:\temp\";

            VirtualEarthLayer worldLayer = new VirtualEarthLayer(accountId, password, clientIpAddress, cacheDirectory);

            LayerOverlay staticOverlay = new LayerOverlay();
            staticOverlay.Layers.Add("WorldLayer", worldLayer);
            winformsMap1.Overlays.Add(staticOverlay);

            winformsMap1.MapUnit = GeographyUnit.Meter;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
            winformsMap1.CurrentExtent = new RectangleShape(-10000000, 10000000, 10000000, -10000000);

            GoogleMapZoomLevelSet zoomLevelSet = new GoogleMapZoomLevelSet();
            zoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            winformsMap1.ZoomLevelSet = zoomLevelSet;
            double scale = ExtentHelper.GetScale(winformsMap1.CurrentExtent, (float)winformsMap1.Width, winformsMap1.MapUnit);
            winformsMap1.ZoomToScale(scale);

            winformsMap1.Refresh();



Niels,


Thanks for your kindly help:), we have corrected the HowDoI samples.
 
The coorindate system used in VitrualEarthLayer is Mecator, its projection string should be +proj=merc+a=6378137+b=6378137+lat_ts=0.0+lon_0=0.0+x_0=0.0+y_0=0+k=1.0+units=m+no_defs
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale