Posted By Charles on 06-22-2009 07:43 AM
I am using custom point and text styles and have run into a problem. I need to set the scale of the item being drawn in the custom style. I have several scale settings that I can get to, but I need to know the current scale of the WinformMap control to which the custom style is drawing. I see a CurrentScale property of the window, but if I have multiple WinformMap controls in my project, I don’t know which is active when drawing inside the custom style. Is there a way around this problem?
My second question is what does the CurrentScale display? The value of CurrentScale when I first open the project is 576749.
Charles
Charles,
Hopefully, my following answers can give you some help.
For your first questions
I want to make myself understood the same page with you. Your idea is that we have one created CustomStyle which will be shared in 2 or more than 2 winformMaps used in the App.
During the drawing of the CustomStyle, you are trying to do is:
If(winformMap1)
{
If(WinformMap1. CurrentScale < SomeSpeficiedScale1)
{
Draw1
}
Else if( WinformMap1.CurrentScale < SomeSpecifiedScale2)
{
Draw2
}
}
Else if( winformMap2)
{
If(WinformMap2. CurrentScale < SomeSpeficiedScale3)
{
Draw3
}
Else if( WinformMap2.CurrentScale < SomeSpecifiedScale4)
{
Draw4
}
}
If I am understanding correctly, my suggestion is Create 2 separate CustomStyle, and ONLY one custom style is used for ONLY one winformMapControl. In the DrawCore override method, GetScale from the Canvas, and then do what you want to do, in this way, it will make things much easier and understood.
protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
{
double scale = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit);
if (scale > 10000)
{
PointStyle pointStyle = new PointStyle(PointSymbolType.Diamond, new GeoSolidBrush(GeoColor.SimpleColors.Red), new GeoPen(GeoColor.SimpleColors.Blue, 5), 10);
pointStyle.Draw(features, canvas, labelsInThisLayer, labelsInAllLayers);
}
else
{
PointStyle pointStyle = new PointStyle(PointSymbolType.Star, new GeoSolidBrush(GeoColor.SimpleColors.Red), new GeoPen(GeoColor.SimpleColors.Blue, 5), 10);
pointStyle.Draw(features, canvas, labelsInThisLayer, labelsInAllLayers);
}
}
For your second questions
TheCurrentScale stands for the Scale of the WinformsMap control, of course, it will introduce some precision when calculation. I think your default value is 5765749 is reasonable somehow, it depends on your MapControl width.
In fact, you can see that this value depends on following 3 parameters:
ExtentHelper.GetScale(CurrentWorldExtent, winformsMap1.Width, winformsMap1.MapUnit);
Any more questions just let me know.
Thanks
Yale