ThinkGeo.com    |     Documentation    |     Premium Support

Graticule Adornment will not display

Hi,

In v14, this code doesn’t add my image to the bottom right of the map. Right now, I just see powered by MapSuite which I don’t want to be visible

        // Create our GraphicLogAdornmentLayer and specify the graphic we want to use
        GraphicLogoAdornmentLayer graphicLogoAdornmentLayer = new GraphicLogoAdornmentLayer();
        graphicLogoAdornmentLayer.LogoImage = new Bitmap(Properties.Resources.ACTeQ_Logo, new Size(80, 80));
        WinMap.AdornmentOverlay.Layers.Add(graphicLogoAdornmentLayer);

Regards,
Damian

Just do

MapView.MapTools.Logo.Source = new BitmapImage(new Uri(@"YourLogo.png", UriKind.RelativeOrAbsolute));

So is GraphicAdornmentOverlay used for anything now? Why should I be able to set it up if it doesn’t do anything??? It doesn’t say anything about being deprecated.

This code gives me an error because I am not using a URI, but rather an image loaded as a resource. Barring that though, this code gets me this image… which does not even anchor the image to the bottom right (see image 2 where logo is clipped) and clearly does not honor the rendered size of 80x80 pixels.

        WinMap.MapTools.Logo.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(Path.Combine(Application.StartupPath, "ACTeQ-Logo.png")));
        WinMap.MapTools.Logo.RenderSize = new System.Windows.Size(80, 80);
        WinMap.MapTools.Logo.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
        WinMap.MapTools.Logo.VerticalContentAlignment = System.Windows.VerticalAlignment.Bottom;

Which version are you using? I don’t see neither GraphicAdornmentOverlay nor GraphicLogoAdornmentLayer in the current version.

You can also use the URI for a local image. We have a HowDoI sample showing this: HowDoI->Map Tools -> Logo.

In fact, isn’t it easier if just put your image to an image control on top of the map in your application? The HowDoI->Map Navigation->Map Navigation would give you some idea.

Well it seems I got the concept way back from v9 and have an inherited class from AdornmentLayer that overrides the DrawCore method.

Any idea why this code would not work anymore?

    protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
    {
        var logo = new GeoImage(logoImage);
        if (IsVisible)
        {
            ScreenPointF screenPointF = GetDrawingLocation(canvas, logoImage.Width, logoImage.Height);
                            
            // If the canvas happens to be using GDI+ then we can do an optimization and skip
            // the GeoImage.  Otherwise we go the longer route in the else statement
            if (canvas is PlatformGeoCanvas)
            {
                PlatformGeoCanvas PlatformGeoCanvas = canvas as PlatformGeoCanvas;
                PlatformGeoCanvas.DrawScreenImageWithoutScaling(logo, screenPointF.X + logoImage.Width * 0.5f, screenPointF.Y + logoImage.Height * 0.5f, DrawingLevel.LevelOne, -10f, -10f, 0f);
                    
                    //screenPointF.X + logoImage.Width * 0.5f, screenPointF.Y + logoImage.Height * 0.5f, DrawingLevel.LevelOne, -10, -10, 0);
            }
            else
            {
                //  Here we have to convert the stream to a TIFF to be used in the GeoImage
                Stream stream = new MemoryStream();
                logoImage.Save(stream, ImageFormat.Tiff);
                GeoImage geoImage = new GeoImage(stream);

                canvas.DrawScreenImageWithoutScaling(geoImage, screenPointF.X + logoImage.Width * 0.5f, screenPointF.Y + logoImage.Height * 0.5f, DrawingLevel.LevelOne, -10, -10, 0);
            }
        }
    }

I think there is a problem with this code.

        Stream s = new MemoryStream();
        Properties.Resources.ACTeQ_Logo.Save(s, System.Drawing.Imaging.ImageFormat.Tiff);
        var logo = new GeoImage(s);

I thought I would test if the logo object was really being created so I added a Save step and get a null reference exception as follows.

logo.Save(@“C:\users\damian\desktop\testimage.png”, GeoImageFormat.Png);

I think there is an issue with the GeoImage(Stream stream) method.

Hi @Damian_Hite,

To get your code working, the following changes are required:

  1. save with the correct ImageFormat, if your logo image is png, just save it with ImageFormat.PNG
  2. reset the position of the stream before passing it to GeoImage

I uploaded a sample with comments, feel free to have a look.
GraticuleAdornmentSample.zip (18.4 KB)

Regards,
Leo

Thanks Leo. That worked, but I had to set the MapTools.Logo to a blank BitmapImage; otherwise, both were displayed at the same time.

Regards,
Damian

Hi @Damian_Hite,

You could hide the Logo using the following code.

        MapView.MapTools.Logo.Visibility = Visibility.Collapsed;

Regards,
Leo