I would like to give color to the map with new category. to make must make previous expression. I've tried but still failed. What is wrong ? Please help me.

 Dim category As MapWinGIS.ShapefileCategory = sf.Categories.Add("Manual")
Dim ad As String = "Alaska"
Dim UniqueShape As New MapWinGIS.Shapefile
UniqueShape = FormMain.AxMapMain.get_GetObject(idx)

Dim af As String = UniqueShape.Table.Field(1).Name
Const cote As String = """"

' category.Expression = "[STATE_NAME] = """ + ad + """"
' category.Expression = "[STATE_NAME] <> """""
category.Expression = "[" + af + "] = " + ad
category.Expression = "[STATE_NAME] = " & cote & "Alaska" & cote
'category.Expression = "[STATE_NAME] = ""Alaska"""

Dim utils As New MapWinGIS.Utils
category.DrawingOptions.FillColor = utils.ColorByName(MapWinGIS.tkMapColor.Magenta)

sf.DefaultDrawingOptions.Visible = False
' FormMain.AxMapMain.AddLayer(sf, True)

The code does not define the DrawingOptions for the expression you are using, thus it defaults back to the default drawing options. You must code the DrawingOptions up and add them to the Category which has been added to the collection of Categories.. below, the function, GetShapeCategories() returns a ShapeCategories with 2 expressions defined (i've not included the drawing options for the second - you would choose a different colour or point size/shape) - (note the Categories are added to the collection when they are created):

Function GetShapeCategories() As ShapefileCategories
  Dim shpCategories As New ShapefileCategories() With {.Caption = "Status"}

  Dim CategoryComplete As ShapefileCategory = shpCategories.Add("Completed")
  CategoryComplete.Expression = "[Completed] = 1"
  Dim sdComplete As New ShapeDrawingOptions
  Dim utils As New MapWinGIS.Utils
  sdComplete.FillColor = utils.ColorByName(tkMapColor.Red)
  sdComplete.FillColor2 = utils.ColorByName(tkMapColor.Red)
  sdComplete.FillTransparency = 200
  sdComplete.LineColor = utils.ColorByName(tkMapColor.Red)
  sdComplete.PointShape = tkPointShapeType.ptShapeCircle
  sdComplete.PointSize = 30
  sdComplete.Visible = True
  CategoryComplete.DrawingOptions = sdComplete

  Dim CategoryIncomplete As ShapefileCategory = shpCategories.Add("Incomplete")
  CategoryIncomplete.Expression = "[Completed] = 2"
  # Define Drawing Options for this Category - sdIncomplete
  # CategoryIncomplete.DrawingOptions = sdIncomplete

  Return shpCategories
End Function

Finally when drawing, we run this:

  # You can set different Categories based on different requirements

  _Shp.DefaultDrawingOptions = GetDefaultDrawingOptions()
  _Shp.SelectionDrawingOptions = GetSelectionOptions()
  _Shp.Categories = GetShapeCategories()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.