基于地图开发控件GMap.Net 使用 (五) 原创 用户自定义标签图片

最近看到 fangping朋友的提问问是否可以自定义标签,相信大家对此问题都挺关注。回头看看Gmap动态库还真没提供此功能。自己添加一个!打开开源源码创建一个类名为GMapMarkerImage的类。此类功能:用户可添加自定义图片标签。

添加源码如下:

View Code
   
     
public class GMapMarkerImage : GMapMarker
{
public float ? Bearing;

private Image userImage = null ;

public GMapMarkerImage(PointLatLng p)
:
base (p)
{
Size
= new System.Drawing.Size(Resources.bigMarkerGreen.Width, Resources.bigMarkerGreen.Height);
Offset
= new Point( - 10 , - 34 );
}

public GMapMarkerImage(PointLatLng p , string imageFile)
:
base (p)
{
Size
= new System.Drawing.Size(Resources.bigMarkerGreen.Width, Resources.bigMarkerGreen.Height);
Offset
= new Point( - 10 , - 34 );
try
{
userImage
= Bitmap.FromFile(imageFile);
userImage
= new Bitmap( 0 , 0 );
}
catch
{

}
}

public GMapMarkerImage(PointLatLng p, Image imageFile)
:
base (p)
{
Size
= new System.Drawing.Size(Resources.bigMarkerGreen.Width, Resources.bigMarkerGreen.Height);
Offset
= new Point( - 10 , - 34 );
userImage
= imageFile;
}

static readonly Point[] Arrow = new Point[] { new Point( - 7 , 7 ), new Point( 0 , - 22 ), new Point( 7 , 7 ), new Point( 0 , 2 ) };

public override void OnRender(Graphics g)
{
#if !PocketPC

g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);

g.ResetTransform();

if ( ! Bearing.HasValue)
{
g.DrawImageUnscaled(userImage, LocalPosition.X, LocalPosition.Y);
}
#else
DrawImageUnscaled(g, Resources.shadow50, LocalPosition.X, LocalPosition.Y);
DrawImageUnscaled(g, Resources.marker, LocalPosition.X, LocalPosition.Y);
#endif
base .OnRender(g);
}

基于地图开发控件GMap.Net 使用 (五) 原创 用户自定义标签图片

喜洋洋同学就到地图上面了

你可能感兴趣的:(自定义标签)