ShapeFillColor !?? (resolved)

Jul 28, 2011 at 8:40 AM

Hello,

I would like to change the color of  entities selected (polygon) of a layer. I am looking to identify the entities selected by using the event "SelectBoxDrag". Yet I followed the documentation, but "ShapeFillColor" does not work!? The color of the selected entities are the same as the default layer. The following code does not work, any ideas? thank you

Private Sub ctrlMap_SelectBoxDrag(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_SelectBoxDragEvent) Handles ctrlMap.SelectBoxDrag
        Dim sf As MapWinGIS.Shapefile
        Dim myExtents As New MapWinGIS.Extents()
        Dim selectedShapes() As Integer
        Dim i As Integer, hndl As Integer
        Dim pxMin As Double, pxMax As Double, pyMin As Double, pyMax As Double, pzMin As Double, pzMax As Double
        Dim col As System.Drawing.Color
        'Check if the map is in selection mode
        If ctrlMap.CursorMode = MapWinGIS.tkCursorMode.cmSelection Then
            'Get the handle of the layer at position 0
            hndl = ctrlMap.get_LayerHandle(1)
            'Get the shapefile in the specified layer
            sf = ctrlMap.get_GetObject(hndl)
            'Convert the boundaries of the selection box from pixel units to projected map coordinates
            ctrlMap.PixelToProj(e.left, e.bottom, pxMin, pyMin)
            ctrlMap.PixelToProj(e.right, e.top, pxMax, pyMax)
            'Set the extents object to be used to find shapes that have been selected in the shapefile
            myExtents.SetBounds(pxMin, pyMin, 0, pxMax, pyMax, 0)
            'Check if there are any shapes with in the shapefile that intersect with the selection box
            If sf.SelectShapes(myExtents, 0, MapWinGIS.SelectMode.INTERSECTION, selectedShapes) Then
                'Get the System.Drawing.Color which is being used as the fill color for the shapes in the layer
                col = ctrlMap.get_ShapeLayerFillColor(hndl)
                'Set all shapes in the shapefile back to their original color
                ctrlMap.set_ShapeLayerFillColor(hndl, System.Convert.ToUInt32(RGB(col.R, col.G, col.B)))
                'For each of the selected shapes in the shapefile, color them differently than their original fill color
                For i = 0 To UBound(selectedShapes)
                    ctrlMap.set_ShapeFillColor(hndl, selectedShapes(i), System.Convert.ToUInt32(RGB(100, 100, 0)))
                Next
            End If
        End If
    End Sub

Aug 2, 2011 at 12:23 AM
mdelsinne wrote:

Hello,

I would like to change the color of  entities selected (polygon) of a layer. I am looking to identify the entities selected by using the event "SelectBoxDrag". Yet I followed the documentation, but "ShapeFillColor" does not work!? The color of the selected entities are the same as the default layer. The following code does not work, any ideas? thank you

 

Private Sub ctrlMap_SelectBoxDrag(ByVal sender As System.Object, ByVal e As AxMapWinGIS._DMapEvents_SelectBoxDragEvent) Handles ctrlMap.SelectBoxDrag
        Dim sf As MapWinGIS.Shapefile
        Dim myExtents As New MapWinGIS.Extents()
        Dim selectedShapes() As Integer
        Dim i As Integer, hndl As Integer
        Dim pxMin As Double, pxMax As Double, pyMin As Double, pyMax As Double, pzMin As Double, pzMax As Double
        Dim col As System.Drawing.Color
        'Check if the map is in selection mode
        If ctrlMap.CursorMode = MapWinGIS.tkCursorMode.cmSelection Then
            'Get the handle of the layer at position 0
            hndl = ctrlMap.get_LayerHandle(1)
            'Get the shapefile in the specified layer
            sf = ctrlMap.get_GetObject(hndl)
            'Convert the boundaries of the selection box from pixel units to projected map coordinates
            ctrlMap.PixelToProj(e.left, e.bottom, pxMin, pyMin)
            ctrlMap.PixelToProj(e.right, e.top, pxMax, pyMax)
            'Set the extents object to be used to find shapes that have been selected in the shapefile
            myExtents.SetBounds(pxMin, pyMin, 0, pxMax, pyMax, 0)
            'Check if there are any shapes with in the shapefile that intersect with the selection box
            If sf.SelectShapes(myExtents, 0, MapWinGIS.SelectMode.INTERSECTION, selectedShapes) Then
                'Get the System.Drawing.Color which is being used as the fill color for the shapes in the layer
                col = ctrlMap.get_ShapeLayerFillColor(hndl)
                'Set all shapes in the shapefile back to their original color
                ctrlMap.set_ShapeLayerFillColor(hndl, System.Convert.ToUInt32(RGB(col.R, col.G, col.B)))
                'For each of the selected shapes in the shapefile, color them differently than their original fill color
                For i = 0 To UBound(selectedShapes)
                    ctrlMap.set_ShapeFillColor(hndl, selectedShapes(i), System.Convert.ToUInt32(RGB(100, 100, 0)))
                Next
            End If
        End If
    End Sub

 

See http://mapwingis.codeplex.com/discussions/262457 and http://mapwingis.codeplex.com/wikipage?title=Sample%20code%3a%20shapefile%20caregories

Aug 2, 2011 at 1:51 PM

Thank's !!!

My solution in VBA for MS Access application, it's work ;) (comment in french)

'S�lection
Private Sub myMap_SelectBoxFinal(ByVal left As Long, ByVal right As Long, ByVal bottom As Long, ByVal top As Long)

    Dim myExtents As New MapWinGIS.Extents
    Dim selectedShapes As Variant
    Dim i As Integer
    Dim pxMin As Double, pxMax As Double, pyMin As Double, pyMax As Double
    Dim shpIndex As Long

    'Generer une classification � valeur unique, OBLIGATOIRE pour ensuite color� les entit�s selectionn�es d'une autre couleur
    'Classification doit porter sur un champ unique, pas de doublon !!!
    Dim index As Integer
    index = sfCounties.Table.FieldIndexByName("id")
    sfCounties.Categories.Generate index, MapWinGIS.tkClassificationType.ctUniqueValues, 0
    sfCounties.Categories.ApplyExpressions
    
    'Si curseur de selection
    If myMap.CursorMode = MapWinGIS.tkCursorMode.cmSelection Then
        'Conversion du rectangle de selection, pixel -> coordonn�es de la carte
        myMap.PixelToProj left, bottom, pxMin, pyMin
        myMap.PixelToProj right, top, pxMax, pyMax
        'Definir l'etendue de selection
        myExtents.SetBounds pxMin, pyMin, 0, pxMax, pyMax, 0
        'Verifier la selection, avec comme op�ration spatiale, une intersection
        If sfCounties.SelectShapes(myExtents, 0, MapWinGIS.SelectMode.INTERSECTION, selectedShapes) Then
            'Active le bouton de deselection
            btDeselect.Enabled = True
            'Pour chaque entit�s selectionn�es, recuperer la valeur du champ(0) de sa table attributaire
            For i = 0 To UBound(selectedShapes)
                'Recup l'index de l'entit� selectionn�e
                shpIndex = sfCounties.ShapeCategory(selectedShapes(i))
                'MsgBox (sfCounties.CellValue(0, selectedShapes(i))) 'Afficher la valeur attributaire du champ(0)
                'Colorer l'entit� selectionn�e d'une autre couleur
                sfCounties.Categories.item(shpIndex).DrawingOptions.FillColor = RGB(0, 255, 255)
            Next
        End If
        'Apporter les modifications
        myMap.Redraw
    End If

End Sub

Jan 1, 2012 at 4:28 PM

Hello and a happy new year everybody,

I've just upgraded from MapWinGis.ocx R4.7 to R4.8. Most of my Access-vba-code is ok, but I have some problems with changing the fill-color of selected Items. I tried the following code which I extracted from the above with no success:

' Language: vba
' create Layerobject
Dim objShape As MapWinGIS.Shapefile
Set objShape = Me.mapMain.GetObject(lngHandle)
' I'm not sure what the next 4 lines do - I simply copied them
Dim intShapeIndex As Integer
intShapeIndex = objShape.Table.FieldIndexByName("oid")
objShape.Categories.Generate intShapeIndex, ctUniqueValues, 0
objShape.Categories.ApplyExpressions
' AusSelected Objects
mapMain.PixelToProj X, Y, dblXProjected, dblYProjected
' Auschnitt-Grenzen auslesen
Set objExtends = New MapWinGIS.Extents
objExtends.SetBounds dblXProjected, dblYProjected, 0, dblXProjected, dblYProjected, 0
boolResult = objShape.SelectShapes(objExtends, 0, INTERSECTION, varShapeIDs)
' iterate over selected Objects
For i = 0 To UBound(varShapeIDs)
    ' Shape markieren
    objShape.Categories.Item(varShapeIDs(i)).DrawingOptions.fillColor = RGB(0, 255, 255)
Next i
Me.mapMain.Redraw
Can anybody tell me whats wrong with my Code?
Thanks and regards
Helmut
Jan 3, 2012 at 4:20 PM

Hello again,

I found the solution myself. I simply forgot the line:

lngShpIndex = objShape.ShapeCategory(varShapeIDs(i))

and than had to alter the next line to:

objShape.Categories.Item(lngShpIndex).DrawingOptions.fillColor = RGB(0, 255, 255)

So far so good, the next problem I encountered is that eveytime I call the routine, the shape I selected the last time, is unselected (i.e. the color set to the layer default). That is wanted in most cases, but not in all.

How can I keep the previous selection?

Thanks again

Helmut