custom marker problem

Topics: Windows Forms
Mar 5, 2012 at 10:44 AM

Hi!

I create my own marker, but when i add marker to map it's not show properly.

Code of custom marker OnRender function:

public override void OnRender(Graphics g)
        {
            Icon icon= WindowsFormsApplication1.Properties.Resources.truck;
            Image image = icon.ToBitmap();
            Size = new System.Drawing.Size(image.Width, image.Height);
            Offset = new Point(-image.Width / 2, - image.Height / 2);
            g.DrawImage(image, LocalPosition.X , LocalPosition.Y, Size.Width, Size.Height);
        }

Picture example of problem

 

I figured, when i clicked button for maximize form, then marker moved to the correct place

Picture example after maximize form

 

Have anyone that similar problems?



Coordinator
Mar 5, 2012 at 11:06 AM

first move these to constructor:

Icon icon= WindowsFormsApplication1.Properties.Resources.truck;
Image image = icon.ToBitmap();
Size = new System.Drawing.Size(image.Width, image.Height);
Offset = new Point(-image.Width / 2, - image.Height / 2); 

Mar 5, 2012 at 11:30 AM

tnx ;)

Apr 6, 2012 at 5:16 PM
Edited Apr 6, 2012 at 5:18 PM

Hi;

I create a marker and I add it to my map, when I compile I have no error but the map show this:

https://dl-web.dropbox.com/get/mapError.PNG?w=1979c28f

This is the class of the marker

 

[NonSerialized]
        public Image image;

        public GMapMarkerCam(PointLatLng p)
            : base(p)
        {           
            Image image = WindowsFormsApplication1.Properties.Resources.cam;
            Size = new System.Drawing.Size(image.Width, image.Height);
            Offset = new Point(-image.Width / 2, -image.Height / 2);
        }

        public override void OnRender(Graphics g)
        {
            //base.OnRender(g);
            g.DrawImage(image, LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);
        }

        public override void Dispose()
        {

            if (image != null)
            {
                image.Dispose();
                image = null;
            }
            if (InnerMarker != null)
            {
                InnerMarker.Dispose();
                InnerMarker = null;
            }

            base.Dispose();
        }

        #region ISerializable Members

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
        }

        protected GMapMarkerCam(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        #endregion

 

The size of image is 130x69 .png

Any help please?

Coordinator
Apr 6, 2012 at 8:22 PM

can't see the picture, try 4shared.com or something...

Apr 6, 2012 at 8:45 PM

http://www.4shared.com/photo/tyWZyvmc/mapError.html

it shows me

Coordinator
Apr 6, 2012 at 8:57 PM

hm, well strange error, it doesn't happen for me or anyone else ;/

Apr 6, 2012 at 9:25 PM
Edited Apr 6, 2012 at 9:25 PM

so? do you think there is error in custom class?

Coordinator
Apr 7, 2012 at 9:29 AM

just noticed:

 Image image = WindowsFormsApplication1.Properties.Resources.cam; // remove first keyword ;}

Apr 7, 2012 at 10:40 AM
Edited Apr 7, 2012 at 10:42 AM

which keyword? if do you mean Image, even if  I remove it it don't change anything!!

Coordinator
Apr 7, 2012 at 11:04 AM

public Image image;

public GMapMarkerCam(PointLatLng p)
: base(p)
{
Image image = WindowsFormsApplication1.Properties.Resources.cam;
Size = new System.Drawing.Size(image.Width, image.Height);
Offset = new Point(-image.Width / 2, -image.Height / 2);
}

Apr 7, 2012 at 11:08 AM

ok, thanks very much, it works ;)

Coordinator
Apr 7, 2012 at 11:10 AM

;]