ThinkGeo.com    |     Documentation    |     Premium Support

FeatureLayer DrawingQuality

Hi Guys,


As we run really big screens here we need to wring every last bit of speed out of TG3 to get it anywhere near acceptable speed.


To help to do this we have the DrawingQuality of the form control set to HighSpeed.  One draw back with this is that labels look lousy.  it would appear from the help that you can control the DrawingQuality of individual layers, help has the following:-


<Quote>


The DrawingQuality enumeration allows you to control, in a macro sense, the drawing quality that will be used in the GeoCanvas. Each GeoCanvas, which is responsible for drawing of the features, may have its own specialized drawing quality properties. What the DrawingQuality enumeration does is define some general guidelines for each GeoCanvas. For example, if you set the DrawingQuality to HighSpeed, then inside of the GdiPlusGeoCanvas there is a profile for HighSpeed. This profile sets specific properties, such as the smoothing mode and composing drawing mode of the GdiPlusGeoCanvas. As each GeoCanvas may have different drawing quality properties, this offers a general way to control drawing quality and speed.



If you need complete control over how a specific GeoCanvas will draw, then you can set the DrawingQuality to Custom. This will tell the specific GeoCanvas to use the properties on its own object instead of one of the pre-defined profiles. If one of the profiles -- such as HighSpeed or HighQuality -- is set, then the specific GeoCanvas ignores its own properties for drawing quality.


<Unquote>


The last paragraph looks like the solution we are looking for but how do you set the DrawingQuality to Custom when the enumeration does not have Custom in it?


To put it another way, what we are trying to do is to have only certain overlays draw at HighQuality, the rest at HighSpeed.


Any help would be appreciated.


John



John,


I think you have fully understand what is going on inside ghe drawing quality, while here I just pick up a few items you mentioned to make sure what we can do and what we cannot do in current framework:
1) The control of the DrawingQuality will only in two levels: MapControl level which control all the layers and Layer level which will be applied into individual layer. So I think up to now, we have no way to apply it to Overlay level, you have to loop all the layer in it for its setting.
 
2)There is a item to set the customized setting, while as you said, when you apply this item, you have to set the SmoothingMode, ComposingMode etc in GdiPlusGeocanvas, in this way, it is very likely to are going to use the ServiceEdition directly.

worldLayer.DrawingQuality = DrawingQuality.CanvasSettings;

 
If you are using Desktop Edtiion, it is impossible for your to set it customized as you want up to now, because we did not expose the drawing canvas out. While a possible way is , you could rewrite your own layer and override the DrawCore, change its parameter Cavans settings.
 
Any way, ServiceEdtion is a very expandable framework, while it may lose some flexibity in Desktop Editon, hope my explanations make sense.
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Hi Yale. 
  
 So if I undertsnad you correctly, the help is worng and youy can’t set the DrawingQuality of an individual LAYER? 
  
 If that it so, why do Layers have a DrawingQuality and why does it not work? 
  
 John

 


John,
 
You can override DrawCore method in LayerOverlay to achieve you want.
 
public class CustomLayerOverlay : LayerOverlay
{
    protected override void DrawCore(GeoCanvas canvas)
    {
        Collection<SimpleCandidate> labelingInAllLayers = new Collection<SimpleCandidate>();
        foreach (Layer layer in Layers)
        {
            lock (layer)
            {
                if (!layer.IsOpen)
                {
                    layer.Open();
                }
                canvas.Flush();

                FeatureLayer featureLayer = layer as FeatureLayer;
                if (featureLayer != null && canvas.DrawingQuality != DrawingQuality.Default )
                {
                    featureLayer.DrawingQuality = canvas.DrawingQuality;
                }

                layer.Draw(canvas, labelingInAllLayers);
            }
        }
    }
}

// test code
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;

winformsMap1.CurrentExtent = new RectangleShape(-180.0, 83.0, -20.0, -20.0);
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");
worldLayer.Name = "Countries02";
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
worldLayer.DrawingQuality = DrawingQuality.HighQuality;

ShapeFileFeatureLayer citiesLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\MajorCities.shp");
citiesLayer.Name = "MajorCities";
citiesLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
citiesLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.City1("areaname");
citiesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
citiesLayer.DrawingQuality = DrawingQuality.HighSpeed;

CustomLayerOverlay staticOverlay = new CustomLayerOverlay();
staticOverlay.Layers.Add("WorldLayer", worldLayer);
staticOverlay.Layers.Add("CitiesLayer", citiesLayer); 
winformsMap1.Overlays.Add(staticOverlay);

winformsMap1.Refresh();

 
Please let me know if you have more questions
 
Thanks
James

Hi James, 
  
 Nice one, works beautifully. 
  
 John

John,



  Another thing you can do there is to check if the Layer has it set to CanvasSettings.  Inside the code we can then check to see if the Canvas is a GdiPlusGeoCanvas which most likely it is and if so we have full control.  On the GdiPlusGeoCanvas we expose the smoothing mode, text rendering hint etc from GDI+.



David




   public class CustomLayerOverlay : LayerOverlay
    {
        protected override void DrawCore(GeoCanvas canvas)
        {
            Collection<SimpleCandidate> labelingInAllLayers = new Collection<SimpleCandidate>();
            foreach (Layer layer in Layers)
            {
                lock (layer)
                {
                    if (!layer.IsOpen)
                    {
                        layer.Open();
                    }
                    canvas.Flush();

                    FeatureLayer featureLayer = layer as FeatureLayer;
                    if (featureLayer != null && canvas.DrawingQuality != DrawingQuality.Default)
                    {
                        if (canvas is GdiPlusGeoCanvas)
                        {
                            if (featureLayer.DrawingQuality == DrawingQuality.CanvasSettings)
                            {
                                GdiPlusGeoCanvas gdiPlusGeoCanvas = (GdiPlusGeoCanvas)canvas;                                
                                gdiPlusGeoCanvas.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                                gdiPlusGeoCanvas.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                            }
                        }                        
                    }
                    layer.Draw(canvas, labelingInAllLayers);
                }
            }
        }
    }