ThinkGeo.com    |     Documentation    |     Premium Support

GeoCanvas out of Sync with Map

Hi, 


I've created a custom layer that extends from Layer and overrides the DrawCore method.  Within that method, I use the current extent of the map, and also the width and height.  However... I've noticed that the extent of the GeoCanvas, along with the width and height are not the same as my map.  I have reproduced this in the attached application which prints out the information to the console.



I'm not sure if I'm not understanding the GeoCanvas or how to create custom layers correctly, or if this is a bug.



345-MapTest.zip (11.9 KB)

Steve,  
  
 Very glad you are trying to extend the layer, you will see the framework is very extensible and you can integrate your code very easily. 
  
 You are right that the extent, width and height are not identical with what you set in the application, that’s because as we use tiling in desktop, when first load the map, we will modify map’s extent and generate a bigger tile, split it into small tiles then display it. In that way, we don’t need to regenerate the entire image when we do the panning, instead we just generate the “new tiles” showed up.  So you can see in DrawCore(), the size and extent are the real one for drawing, which is not the same with what you get in your application. 
  
 Hope that makes sense, just let me know for more queries. 
  
 Ben.

Hi,


I created a custom layer as well and overrided DrawCore().  My desktop application gets the map in bitmap format from a centralized server which hosts the map data.  The GeoCanvas size is smaller than the size of my map control.  What do I need to do to make my map occupies the full extent of the map control? 


 



using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections.ObjectModel;
using MapApplication.MapWebService;

using System.IO;

// What this sample does is creates your own layer.  You can use this layer just like any other layers 
// in the system.  The advantage is that you can place it where you want and it will seamlessly integrate
// with the rest of the system.  As you can see it is really easy to create your own layers.

// The basic flow of events is that when the map needs to draw it will first call the OpenCore.
// This is where you do anything special to get your source ready.  Then it will call the GetBoundingBox
// method to make sure the current extent of the map is within the are you have data.  If not then it will
// never call the DrawCore because there is no need.  Then if you are int he extent it wil call the DrawCore.
// The DrawCore is where you place your code that need to do the drawing on the canvas.  As you can see below
// it is faily simple.

namespace ThinkGeo.MapSuite.Core
{
    class SimpleCustomLayer : Layer
    {
        private Service1SoapClient imageServiceSoapClient = new Service1SoapClient();

        protected override void OpenCore()
        {

        }

        protected override void CloseCore()
        {
  
        }

        protected override RectangleShape GetBoundingBoxCore()
        {

            return new RectangleShape(-143.4, 109.3, 116.7, -76.3);
        }

        protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labeledInLayers)
        {

            Bitmap customImage = GetImage(canvas.CurrentWorldExtent.UpperLeftPoint.X, canvas.CurrentWorldExtent.UpperLeftPoint.Y, canvas.CurrentWorldExtent.LowerRightPoint.X, canvas.CurrentWorldExtent.LowerRightPoint.Y, (int)canvas.Width, (int)canvas.Height);
 
            canvas.DrawWorldImageWithoutScaling(canvas.ToGeoImage(customImage), canvas.CurrentWorldExtent.GetCenterPoint().X, canvas.CurrentWorldExtent.GetCenterPoint().Y, DrawingLevel.LevelOne);
            
            customImage.Dispose();
        }

        private Bitmap GetImage(double upperLeftX, double upperLeftY, double lowerRightX, double lowerRightY, int screenWidth, int screenHeight)
        {
            byte[] byteArray = imageServiceSoapClient.GetMapImage(upperLeftX, upperLeftY, lowerRightX, lowerRightY, screenWidth, screenHeight, "Overlay1");
            MemoryStream memoryStream = new MemoryStream(byteArray);

            Bitmap customImage = new Bitmap(memoryStream);
            Graphics g = Graphics.FromImage(customImage);

            g.Dispose();

            return customImage;
        }
    }
}

Thanks



Tracy,  
  
 Thanks for your post! 
  
 Make sure you are using the latest public release version of Desktop Edition (3.0.307 RC version)? 
  
 In our latest version, it is build based on the Grid based tile cache system. So you can see it is very often that the MapControl Size did not match exactly with the GeoCanvas Size. 
  
 In your case, you did not deal with anything, it should work as we expected. 
  
 If you have any more questions just let me know. 
  
 Thanks. 
  
 Yale 


Hi,


I am using the desktop evaluation edition 3.0 (Beta) and the version for DesktopEdition.dll is 3.0.307.0.  I believe I have the correct version?


I used the code I posted above to override the DrawCore().  However, when I starts my appliction, it displays the map in the center but is surrounded by a lot of blank space.  Attached is the image of my map display.  I'd like my map to occupy the whole map control as the ones in the samples provided in the evaluation package.  The following is how I created my map. 



        private void Form1_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

            LayerOverlay staticOverlay = new LayerOverlay();
            SimpleCustomLayer customLayer = new SimpleCustomLayer();
            staticOverlay.Layers.Add("CustomeLayer", customLayer);
            winformsMap1.Overlays.Add(staticOverlay);

            winformsMap1.CurrentExtent = new RectangleShape(-143.4, 109.3, 116.7, -76.3);
            winformsMap1.Refresh();
        }

Thanks!



Hi, 
  
 I have figured out the answer.  It’s the points I specified in the RectangleShape assigned to the currentExtent and the background color to make me think that the map was not displaying completely in the map control.   
  
 Thanks!

Tracy, 
  
 You are using the correct version as we are talking about. 
  
 Thanks for your posts and sharing! 
  
 Any more questions just let me know. 
  
  
 Thanks. 
  
 Yale