Yale, thank you for the right idea. Here is the code which I made with your help, may be somebody has the same problem as me:
EditInteractiveOverlay editInteractiveOverlay = new EditInteractiveOverlay();
editInteractiveOverlay.DragControlPointsLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.IsActive = false;
editInteractiveOverlay.DragControlPointsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.IsActive = false;
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.IsActive = false;
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.IsActive = false;
ValueStyle valueStyle = new ValueStyle();
valueStyle.ColumnName = "Type";
//valueStyle.ColumnName = "Label";
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();
int i = 0;
foreach (DataRow drShip in shipSet.Tables[0].Rows)
{
MemoryStream ms = new MemoryStream((byte[])drShip["Ico"]);
ScalingImageStyle scalingImageStyle = new ScalingImageStyle(GeographyUnit.DecimalDegree, new GeoImage(ms), 100000000, 1000000, 50, 10);
Collection<Style> iconPointStyle = new Collection<Style>();
iconPointStyle.Add(scalingImageStyle);
valueStyle.ValueItems.Add(new ValueItem(Convert.ToString(drShip["1"]) + " " + Convert.ToString(drShip["2"]) , iconPointStyle));
i = i + 1;
}
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
editInteractiveOverlay.EditShapesLayer.Open();
editInteractiveOverlay.EditShapesLayer.Columns.Add(new FeatureSourceColumn("Type"));
editInteractiveOverlay.EditShapesLayer.Columns.Add(new FeatureSourceColumn("Label"));
ScalingTextStyle scalingTextStyle = new ScalingTextStyle(GeographyUnit.DecimalDegree, "[Type]", 100000000, 1000000, 12, 6);
scalingTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
scalingTextStyle.DuplicateRule = LabelDuplicateRule.OneDuplicateLabelPerQuadrant;
scalingTextStyle.YOffsetInPixel = 30;
ScalingTextStyle scalingTextStyle1 = new ScalingTextStyle(GeographyUnit.DecimalDegree, "[Label]", 100000000, 1000000, 12, 6);
scalingTextStyle1.OverlappingRule = LabelOverlappingRule.NoOverlapping;
scalingTextStyle1.DuplicateRule = LabelDuplicateRule.OneDuplicateLabelPerQuadrant;
scalingTextStyle1.YOffsetInPixel = 45;
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(scalingTextStyle);
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(scalingTextStyle1);
editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
editInteractiveOverlay.EditShapesLayer.Close();
Collection<Feature> iconFeature = new Collection<Feature>();
i = 0;
foreach (DataRow drShip in shipSet.Tables[0].Rows)
{
iconFeature.Add(new Feature(new PointShape()));
iconFeature[i].ColumnValues["Type"] = Convert.ToString(drShip["1"]) + " " + Convert.ToString(drShip["2"]);
iconFeature[i].ColumnValues["Label"] = Convert.ToString(drShip["3"]);
editInteractiveOverlay.EditShapesLayer.InternalFeatures.Add(Convert.ToString(drShip["1"]) + " " + Convert.ToString(drShip["2"]), iconFeature[i]);
i = i + 1;
}
editInteractiveOverlay.CanAddVertex = false;
editInteractiveOverlay.CanDrag = true;
editInteractiveOverlay.CanRemoveVertex = false;
editInteractiveOverlay.CanResize = false;
editInteractiveOverlay.CanRotate = false;
editInteractiveOverlay.CalculateAllControlPoints();
winformsMap1.EditOverlay = editInteractiveOverlay;
winformsMap1.Refresh(winformsMap1.EditOverlay);
But can I ask one more question?
How determine if I click on feature?
if (e.MouseButton == MapMouseButton.Right)
{
PointShape clickedPointShape = ExtentHelper.ToWorldCoordinate(winformsMap1.CurrentExtent, e.ScreenX, e.ScreenY, winformsMap1.Width, winformsMap1.Height);
Collection<Feature> clickedFeatures = winformsMap1.EditOverlay.EditShapesLayer.QueryTools.GetFeaturesNearestTo(clickedPointShape, GeographyUnit.Meter, 1,
ReturningColumnsType.AllColumns);
//winformsMap1.EditOverlay.EditShapesLayer.Close();
if (clickedFeatures.Count > 0)
{
//Gets the dimension of the icon and checks if the clicked point is inside it.
ValueStyle valueStyle = (ValueStyle)winformsMap1.EditOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles[0];
//we loop thru the different ValueItem to get the appropriate icon according to the "Type".
GeoImage geoImage = null;
string text = clickedFeatures[0].ColumnValues["Type"].Trim();
foreach (ValueItem valueItem in valueStyle.ValueItems)
{
if (text == valueItem.Value)
{
geoImage = (GeoImage)valueStyle.ValueItems[0].DefaultPointStyle.Image;
break;
}
}
//We check to see if we clicked inside the icon itself.
ScreenPointF screenPointF = ExtentHelper.ToScreenCoordinate(winformsMap1.CurrentExtent, clickedFeatures[0], winformsMap1.Width, winformsMap1.Height);
RectangleF rectangleF = new RectangleF(screenPointF.X - (geoImage.GetWidth() / 2), screenPointF.Y - (geoImage.GetHeight() / 2),
geoImage.GetWidth(), geoImage.GetHeight());
bool IsInside = rectangleF.Contains(new PointF(e.ScreenX, e.ScreenY));
//If inside, removes the feature from the EditShapesLayer of the EditOverlay.
if (IsInside == true)
{
}
}
The line
geoImage = (GeoImage)valueStyle.ValueItems[0].DefaultPointStyle.Image;
doesn't return geoImage and it is understandable, but I can't find out how do this. How determine Image of CustomStyle?
Thank you.