Changing selection color and adding a marker image on shape select in MapWinGis

I have a project in C# Windows Forms using MapWinGis.ocx.

I would like to add a marker (pin.png) and change shape color, when I select a shape (using mouse select or programmatically).

How can I do it in MapWinGis 5.3.0.0?

What I tried for changing the shape highlight/selection color:

    MapLayersHandlerResult ml = new MapLayersHandlerResult();
    foreach (string fileName in fileNames) //for opening multiple files
    {
        ml = _mapLayersHandler.FileOpenHandler(fileName);

        Shapefile sf = ((Shapefile)_mapLayersHandler.CurrentMapLayer.LayerObject);
        sf.SelectionAppearance = tkSelectionAppearance.saSelectionColor;
        sf.SelectionColor = classes.Colors.ColorToUInteger(Color.Red); //tring to change selection color / shape
    }
    if (!ml.success)
    {
        MessageBox.Show(ml.errMsg);
    }

but is not working…the selected shape color is still yellow.

thanks advanced.

Hello Steve.

Try instead using the Utils class, ColorByName method to get the color.

utils = new Utils

sf.SelectionColor = utils.ColorByName(tkMapColor.Red)

Regards,
Jerry.

1. I implemented the code you gave me…I think the problem was that the tkSelectionAppearance.saDrawingOptions, after I set tkSelectionAppearance.saSelectionColor and SelectionColor, the selection color changed from yellow to red.

sf.SelectionAppearance = tkSelectionAppearance.saDrawingOptions;
sf.SelectionDrawingOptions.PointSize = sf.DefaultDrawingOptions.PointSize;
sf.SelectionDrawingOptions.PointRotation = sf.DefaultDrawingOptions.PointRotation;
sf.SelectionDrawingOptions.PointShape = sf.DefaultDrawingOptions.PointShape;

sf.SelectionAppearance = tkSelectionAppearance.saSelectionColor;
sf.SelectionColor = new Utils().ColorByName(tkMapColor.Red); 

2. Now I need to add marker / icon / image / pin to the selected shape(s).
Can you please help me with this question too?

thanks

Hi Steve,

Did you have a look at this example: MapWinGIS: MarkPoints.cs

This example demonstrates how to how to add markers for the points of interest. The marker represented by image loaded from the file will be added on the mouse down event. The markers will be stored in the temporary in-memory shapefile. Here is a screenshot with the results of the code execution.

hi,

I’m very sorry that I did not reply. I managed to successfully implement the marker on shape select.
Here I paste the code:

        public void AddMarker(int LayerHandle)
        {
            MapLayer ml = MapLayersHandler.get_MapLayer(LayerHandle);
            Shapefile shpf = (Shapefile)ml.LayerObject;
            int[] selected = MapInterActionHandler.SelectedShapeIndexes != null ? MapInterActionHandler.SelectedShapeIndexes : new int[] { MapInterActionHandler.SelectedShapeIndex };

            ClearMarkers(sfile);

            sfile = new Shapefile();
            if (!sfile.CreateNewWithShapeID("TemporarySelectFile", ShpfileType.SHP_POINT))
            {
                 MessageBox.Show("Failed to create shapefile: " + sfile.get_ErrorMsg(sfile.LastErrorCode));
                 return;
            }

            MapControl.AddLayer(sfile, true);

            MapWinGIS.Image img = new MapWinGIS.Image();
            if (img.Open(Path.GetDirectoryName(Application.ExecutablePath)+"\\Styles\\Markers\\pin.png", ImageType.PNG_FILE, true, null))
            {

                if (selected.Length <= 0)
                {
                    if (sfile.Close())
                    {
                        DeleteTempLayerFiles();
                    }

                    MapControl.Redraw();
                    return;
                }

                for (int i = 0; i < selected.Length; i++)
                {
                    if (shpf.get_ShapeSelected(selected[i]))
                    {
                        Shape shp = new Shape();
                        shp.Create(ShpfileType.SHP_POINT);
                        MapWinGIS.Point pnt = new MapWinGIS.Point();

                        MapWinGIS.Shape selectedShape = shpf.get_Shape(selected[i]);
                        pnt.x = selectedShape.Extents.Center.x;
                        pnt.y = selectedShape.Extents.Center.y;

                        int index = shp.numPoints;
                        shp.InsertPoint(pnt, ref index);

                        if (!sfile.EditInsertShape(shp, ref index))
                        {
                            MessageBox.Show("Failed to insert shape: " + sfile.get_ErrorMsg(sfile.LastErrorCode));
                            return;
                        }
                       
                        ShapeDrawingOptions options = sfile.DefaultDrawingOptions;
                        options.PointType = tkPointSymbolType.ptSymbolPicture;
                        options.Picture = img;
                        sfile.CollisionMode = tkCollisionMode.AllowCollisions;

                        MapControl.AddLayer(sfile, true);

                        MapControl.Redraw();
                        MapLayersHandler.RefreshMap();
                        RefreshLayerList();
                    }
                }
            }
        }
		
        private void ClearMarkers(Shapefile sfile)
        {
            int[] selected = MapInterActionHandler.SelectedShapeIndexes != null ? MapInterActionHandler.SelectedShapeIndexes : new int[] { MapInterActionHandler.SelectedShapeIndex };
            if (sfile != null)
            {
                if (selected != null)
                    for (int i = 0; i < selected.Length; i++)
                        sfile.EditDeleteShape(selected[i]);

                _layersForm.RefreshLayerList();

                if (sfile.Close())
                {
                    DeleteTempLayerFiles();
                }

                MapControl.Redraw();
            }
        }
		
	 private void DeleteTempLayerFiles()
        {
            try
            {
                File.Delete("TemporarySelectFile");
            }
            catch 
            { 
            }
            try
            {
                File.Delete("TemporarySelectFshx");
            }
            catch 
            { 
            }
            try
            {
                File.Delete("TemporarySelectFdbf.dbf");
            }
            catch 
            { 
	    }
        }
		
        private void AxMap_ShapeSelected(object sender, LayerEventArg e)
        {
            AddMarker(e.LayerHandle);
        }

I hope it helps others too.
Thank you pmeems , jerryfaust for you help.