MapPushpin.Fill Property
In This Article
Overrides the MapPushpin.Fill
property to hide it.
Namespace: DevExpress.XtraMap
Assembly: DevExpress.XtraMap.v24.2.dll
NuGet Package: DevExpress.Win.Map
#Declaration
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public Color Fill { get; set; }
#Property Value
Type | Description |
---|---|
Color | Always the Empty value. |
#Remarks
The Map Control uses an image loaded from the Skin to display map pushpins. To change the pushpin color, specify the Image property - to replace this image with a custom image. You can use the ColorMatrix class to modify the color of the pushpin image. In the example below, a custom image with a red pushpin is updated in the IMapItemFactory.CreateMapItem method.
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraMap;
using System.Drawing.Imaging;
namespace ColorPushpinFactory {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
PopulateTable(10);
listSourceDataAdapter1.SetMapItemFactory(new PushpinFactory((Image)ColorPushpinFactory.Properties.Resources.ResourceManager.GetObject("pushpin_red"), Color.FromArgb(254, 22, 131)));
}
void PopulateTable(int pointCount) {
GeoPoint centerPoint = (GeoPoint)mapControl1.CenterPoint;
Random r = new Random();
for (int i = 0; i < pointCount; i++) {
tablePoints.Rows.Add(new Object[] { centerPoint.Latitude + ( (double)r.Next(600) - 300 )/ 100,
centerPoint.Longitude + ( (double)r.Next(1000) - 500 )/ 100,
"P" + i,
r.Next(3),
Color.FromArgb(r.Next(255),r.Next(255),r.Next(255))
});
}
tablePoints.Rows.Add(new Object[] { centerPoint.Latitude + 1, centerPoint.Longitude - 1,
"R", r.Next(3), Color.Red });
tablePoints.Rows.Add(new Object[] { centerPoint.Latitude + 1, centerPoint.Longitude + 1,
"G", r.Next(3), Color.Green });
tablePoints.Rows.Add(new Object[] { centerPoint.Latitude - 1, centerPoint.Longitude + 1,
"B", r.Next(3), Color.Blue });
tablePoints.Rows.Add(new Object[] { centerPoint.Latitude - 1, centerPoint.Longitude - 1,
"Y", r.Next(3), Color.Yellow });
}
}
public class PushpinFactory : IMapItemFactory {
Image baseImage;
Color baseColor;
public PushpinFactory(Image baseImage, Color baseColor) {
this.baseImage = baseImage;
this.baseColor = baseColor;
}
public MapItem CreateMapItem(MapItemType type, object obj) {
DataRowView rowView = (DataRowView)obj;
Color newColor = (Color)rowView["Color"];
Image image = (Image)baseImage.Clone();
ImageAttributes imageAttributes = GetImageAttributes(newColor);
Rectangle rect = new Rectangle(0, 0, image.Width, image.Height);
Graphics g = Graphics.FromImage(image);
g.DrawImage(image, rect, 0, 0, rect.Width, rect.Height, GraphicsUnit.Pixel, imageAttributes);
MapPushpin pushpin = new MapPushpin();
pushpin.Image = image;
pushpin.RenderOrigin = new MapPoint(0.5, 0.8);
pushpin.TextOrigin = new Point(22, 14);
return pushpin;
}
private ImageAttributes GetImageAttributes(Color newColor) {
ImageAttributes imageAttributes = new ImageAttributes();
float[][] colorMatrixElements = {
new float[] {(float)newColor.R / 255f + 0.5f, (float)newColor.G / 255f + 0.5f, (float)newColor.B / 255f + 0.5f, 0, 0}, // red scaling factor
new float[] {0.5f, 0.5f, 0.5f, 0, 0}, // green scaling factor
new float[] {0.5f, 0.5f, 0.5f, 0, 0}, // blue scaling factor
new float[] {0, 0, 0, 1, 0}, // alpha scaling factor
new float[] {-0.5f, -0.5f, -0.5f, 0, 1}}; // three translations
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
return imageAttributes;
}
}
}
See Also