Skip to content
This repository was archived by the owner on Sep 3, 2019. It is now read-only.
This repository was archived by the owner on Sep 3, 2019. It is now read-only.

System.NullReferenceException in MapControl at design time #277

@OgreTransporter

Description

@OgreTransporter

I want to display an OSM map on a control, so I've downloaded OsmShap daily build. If I drag and drop a new MapControl to a WinForm, I'll get the following message:

System.NullReferenceException: Object reference not set to an instance of an object
at OsmSharp.WinForms.UI.MapControl.OnPaint(PaintEventArgs e) in D:\OsmSharp\OsmSharp.UI\OsmSharp.WinForms.UI\MapControl.cs:205
at

The error appears because there is no map at design time, so a check for a valid map is needed. I've downloaded the source and created a workaround:

        protected override void OnPaint(PaintEventArgs e)
        {
            long ticksBefore = DateTime.Now.Ticks;

            var g = e.Graphics;

            if(this.Map == null)
            {
                g.FillRectangle(Brushes.White, 0, 0, this.Width, this.Height);
                Pen wred = (Pen)Pens.Red.Clone();
                wred.Width = 3.0f;
                g.DrawRectangle(wred, 1, 1, this.Width - 3, this.Height - 3);
                g.DrawLine(wred, 1, 1, this.Width - 3, this.Height - 3);
                g.DrawLine(wred, 1, this.Height - 3, this.Width - 3, 1);
                return;
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions