I wrote a piece of code a while ago for colouring lines depending on what was in a certain column. I struggled through it, but managed to get it to work. Now, I want to write a piece of code that will do the same for points, rather than lines. I'm presuming I can alter my existing code slightly to do this but I can't for the life of me figure it out! It doesn't help that I'm not that experienced with MapBasic, and have forgotten most of what I learned the first time round!
Here is my existing code. It looks at what each entry in the table has in column called 'symbology', and changes the colour and line style as such.
My new code will need to make all points a size 5 circle (from Map Symbols font) with a border. The only thing that will change will be the colour.
Include "MapBasic.def"
Declare Sub Main
Declare Function ChangeLineColour (ByVal objTarget as Object, ByVal stringAttribute as String) as Object
Sub Main()
Update ww_gravity_pipe_location set Obj = ChangeLineColour(obj, symbology)
End Sub
Function ChangeLineColour (ByVal objTarget as Object, ByVal stringAttribute as String) as Object
Dim curPen, newPen as Pen
Dim penWidth, penPattern, penColour as Integer
'// check that the object is a line object, if not just return the original object
If Not ObjectInfo(objTarget, OBJ_INFO_TYPE) = Any(OBJ_TYPE_LINE, OBJ_TYPE_PLINE) then
ChangeLineColour = objTarget
Exit Function
End if
'// get the current pen style
curPen = ObjectInfo(objTarget, OBJ_INFO_PEN)
'// get the individual style attributes of the current pen
'// set the new pen colour based on the numerical attribute
Do Case stringAttribute
Case "Surface Water (S)"
penColour = BLUE
penWidth = 2
Case "Combined (C)"
penColour = RED
penWidth = 2
Case "Foul (F)"
penColour = 11239175
penWidth = 2
Case "Proposed"
penColour = GREEN
penWidth = 2
penPattern = 12
Case "Abandoned"
penColour = 9079434
penWidth = 2
penPattern = 112
End Case
'// - Colour codes from http://www.tydac.ch/color/
'// create a new pen with the new colour
newPen = MakePen(penWidth, penPattern, penColour)
'// alter the object we passed into the function to use the new pen
Alter Object objTarget Info OBJ_INFO_PEN, newPen
'// return the altered object to the update statement
ChangeLineColour = objTarget
End Function
All the cases will remain the same, so they don't need to be changed.
I'm guessing I need to change all the 'pens' to 'symbols' or something along those lines.