Custom Marker for GMap. Net Development

Source: Internet
Author: User

You can add Overlay (layers) on the Map control. You can add multiple layers. The layers added first are displayed below. You can add GMapMarker or GMapPolygon and GMapRoute to the layer. You can add custom icons to a map. You can click the icon, delete the icon, drag the icon, and highlight the icon. The following describes the implementation of these functions (mainly based on WinForm, WPF can be implemented by referring to the official Demo): 1. custom icons, using the official Marker: Bitmap bitmap = Bitmap. fromFile ("F: \ Projects \ GMapDemo \ Image \ A.png") as Bitmap; GMapMarker marker = new GMarkerGoogle (point, bitmap); Use GMap directly. NET. windowsForms. in Markers, GMarkerGoogle transmits a Bitmap to use a custom image as an icon. 2. inherit from GMapMarker, custom Marker: using System; using System. collections. generic; using System. linq; using System. text; using GMap. NET; using GMap. NET. windowsForms; using System. drawing; namespace GMapWinFormDemo {class GMapMarkerImage: GMapMarker {private Image image; public Image {get {return Image;} set {image = value; if (image! = Null) {this. size = new Size (image. width, image. height) ;}} public Pen {get; set;} public Pen OutPen {get; set;} public GMapMarkerImage (GMap. NET. pointLatLng p, Image image): base (p) {Size = new System. drawing. size (image. width, image. height); Offset = new System. drawing. point (-Size. width/2,-Size. height/2); this. image = image; Pen = null; OutPen = null;} public override void OnRe Nder (Graphics g) {if (image = null) return; Rectangle rect = new Rectangle (LocalPosition. x, LocalPosition. y, Size. width, Size. height); g. drawImage (image, rect); if (Pen! = Null) {g. DrawRectangle (Pen, rect);} if (OutPen! = Null) {g. DrawEllipse (OutPen, rect) ;}} public override void Dispose () {if (Pen! = Null) {Pen. Dispose (); Pen = null;} if (OutPen! = Null) {OutPen. Dispose (); OutPen = null;} base. Dispose () ;}} describes the functions of the three attributes of GMapMarkerImage: Image: Save the Image of the icon. Pen: Draw a DrawRectangle Pen on the periphery of the image. If it is not null, a rectangle is drawn on the periphery of the image to achieve a highlighted effect. OutPen: Draw a DrawEllipse Pen on the periphery of the image. If it is not null, it will draw an elliptic on the periphery of the image. This value can be set to flash. 3. Implement the Move icon: Add the following Event Response to MapControl: mapControl. mouseDown + = new MouseEventHandler (mapControl_MouseDown); mapControl. mouseUp + = new MouseEventHandler (mapControl_MouseUp); mapControl. mouseMove + = new MouseEventHandler (mapControl_MouseMove); mapControl. onMarkerClick + = new MarkerClick (mapControl_OnMarkerClick); mapControl. onMarkerEnter + = new MarkerEnter (mapControl_OnMarkerEnter); mapControl. O NMarkerLeave + = new MarkerLeave (mapControl_OnMarkerLeave); In MouseDown and MouseUp, determine whether the left button is pressed (move the icon with the left button ). Set the selected Marker in OnMarkerEnter, and set the Pen value to highlight. Remove the selected Marker from OnMarkerLeave, deselect the Pen value, and deselect the highlighted value. Update the Position of the selected Marker in MouseMove. 4. Implementation of icon flashing: a Timer is required: the Timer under the Form is used, and the Timer responds to the event void blinkTimer_Tick (object sender, EventArgs e) {foreach (GMapMarker m in objects. markers) {if (m is GMapMarkerImage) {GMapMarkerImage marker = m as GMapMarkerImage; if (marker. outPen = null) marker. outPen = new Pen (Brushes. red, 2); else {marker. outPen. dispose (); marker. outPen = null ;}} mapControl. refresh ();}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.