Seungwoo,
Here is the sample of a custom layer. I hope you find it useful. You can create this Layer just like any other in the system and use it. If you still want to draw on the event just catch the LayerDrawing or LayerDrawn and then use the Canvas parameter on the event arguments to draw using the method like in the sample. You will see we use the Canvas and there are four methods to draw an image onto it. I highly suggest you go with the custom Layer route though.
David
public class CustomLayer : Layer
{
protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
{
double scale = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit);
// Here you set the scales at which you want to draw.
// If you also know the bounding box of your data set then I
// suggest you uncomment our the last two methods and change the
// sample bounidng box I provided. If you do not know then leave them
// commented or remove them
if (scale >= 0 && scale <= 1000000)
{
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);
// Here we draw the image you generated to the canvas.
canvas.DrawWorldImageWithoutScaling(canvas.ToGeoImage(customImage), canvas.CurrentWorldExtent.GetCenterPoint().X, canvas.CurrentWorldExtent.GetCenterPoint().Y, DrawingLevel.LevelOne);
customImage.Dispose();
// You can also use any one of these kinds fo draw depending on if you
// have world or screen coordinates and if you need scaling or
// not.
//canvas.DrawScreenImage();
//canvas.DrawScreenImageWithoutScaling();
//canvas.DrawWorldImage();
//canvas.DrawWorldImageWithoutScaling();
}
}
private Bitmap GetImage(double upperLeftX, double upperLeftY, double lowerRightX, double lowerRightY, int screenWidth, int screenHeight)
{
// In here you would get your image and return it.
// I am just returning an image with some text so you can verify it works..
Bitmap customImage = new Bitmap(screenWidth, screenHeight);
Graphics g = Graphics.FromImage(customImage);
g.DrawString("SimpleCustomLayer Test", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new PointF(screenWidth / 2, screenHeight / 2));
g.Dispose();
return customImage;
}
//// If you know the bounding box then you need
//// set this to true as I have. If you do not know
//// then leave all of this commented out.
//public override bool HasBoundingBox
//{
// get
// {
// return true;
// }
//}
//// Here is where you would return what the extent of you data is
//// in whatever coordinate system it is. I entered som decimal degree
//// numbers but that is just a sample.
//protected override RectangleShape GetBoundingBoxCore()
//{
// return new RectangleShape(-180.0, 83.0, 180.0, -90.0);
//}
}