有没有办法应用随机颜色将所选点的样式更改为该颜色

Is there a way tor apply a random color to change the style of the selected points to that color

所以我有一个随机颜色函数,我想将其应用于选择的点,但它为每个点提供了一种随机颜色,而不是一种随机颜色用于选择 points.I 知道选择部分有效但我不确定如何让它每种颜色只调用一次随机颜色生成器。这是我到目前为止所拥有的。感谢任何 advice/help!

include "mapbasic.def"
include "menu.def"
include "icons.def"

Declare Sub Main
Declare Sub Color
Declare Sub RndColor



Declare Function ChangeSymbolColour (ByVal objTarget as Object, ByVal stringAttribute as String) as Object

' ==========================

Sub Main

Dim i, nRecords as integer
Dim ColValue As Alias
Dim s_ColValues(50) as String


'// - Query your table and group wanted column (list of unique values)
Select Symbology from YOUR_TABLE2 group by Symbology into UNIQUE_values

'// - Populate array with all unique values (from first column in UNIQUE_values table)
print "new"  
  For i = 1 to SelectionInfo(SEL_INFO_NROWS)         
    ReDim s_ColValues(i)
    Fetch rec i From UNIQUE_values

    ColValue = UNIQUE_values + ".col1"

    s_ColValues(i) = ColValue

Select * from Your_Table2 where Symbology= s_ColValues(i) into Selection

Call Color

Next

End Sub

Sub RndColor

Dim Color as integer

Color = RGB((254*Rnd(1)+1),(254*Rnd(1)+1),(254*Rnd(1)+1))

End Sub

Sub Color


Update Your_table2 set Obj = ChangeSymbolColour(obj, symbology)


End Sub



Function ChangeSymbolColour (ByVal objTarget as Object, ByVal stringAttribute as String) as Object

Dim newSymbol as Symbol
Dim nColour as Integer
'nColour=RGB((254*Rnd(1)+1),(254*Rnd(1)+1),(254*Rnd(1)+1))
ncolour=RED

newSymbol = MakeFontSymbol(36, nColour, 5, "Map Symbols", 0, 0) 
Alter Object objTarget Info OBJ_INFO_SYMBOL, newSymbol
ChangeSymbolColour = objTarget
End Function

您需要在函数外部生成随机颜色,然后将其作为参数传入,而不是每次调用函数时都生成一种新颜色。另外,您似乎没有使用函数的 StringAttribute 参数,这真的是必需的吗?

例如

Sub Main

    Dim nColour as Integer
    
    ...
    Select * from MyTable where ... into MySelection
    nColour = GetRandomColour()
    Update MySelection Set Obj = ChangeSymbolColour(obj, nColour)

End Sub

Function GetRandomColour() as Integer

    GetRandomColour = RGB((254*Rnd(1)+1),(254*Rnd(1)+1),(254*Rnd(1)+1))

End Function

Function ChangeSymbolColour (ByVal objTarget as Object, ByVal nColour as Integer) as Object

    Dim newSymbol as Symbol

    newSymbol = MakeFontSymbol(36, nColour, 5, "Map Symbols", 0, 0) 
    Alter Object objTarget Info OBJ_INFO_SYMBOL, newSymbol
    ChangeSymbolColour = objTarget

End Function