Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# ArrowQry2
# Point CartoScript to draw a black arrow oriented in a
# direction determined from an azimuth value in the database.
# Also draws a label with the azimuth.
# Script discussed in Using CartoScripts tutorial.
# Read azimuth from database table
azim = Direct.Azimuth
# Convert azimuth to internal coordinate system
direction = -(azim - 90)
if (direction < 0) then direction = direction + 360
# Set color values for symbol
red = 0; green = 0; blue = 0
LineStyleSetColor(red, green,blue)
# Set dimensions for arrow
arrowLength = 30
headSize = 0.4 * arrowLength
sweepAngle = 40; dofill = 1
# Draw arrow with zero line width, tip of stem at point
LineStyleDropAnchor(0) # anchor at point
LineStyleSetLineWidth(0)
LineStyleDrawArrow(direction,arrowLength,headSize,sweepAngle,dofill)
LineStyleDropAnchor(1) # anchor at tip of arrow
# Redraw arrow stem with wider line
stemLength = arrowLength - headSize * cosd(sweepAngle)
LineStyleMoveToAnchor(0)
LineStyleSetLineWidth(1.5)
LineStyleLineTo(direction, stemLength)
LineStyleMoveToAnchor(1)
# Convert azimuth value to text string for use as a label
label$ = sprintf("%d", azim)
# Find length of label text for label positioning
height = 10
LineStyleTextNextPosition(label$,height,0,0,next_x,next_y,length)
# Set font name and color
LineStyleSetFont("ARIALBD.TTF")
LineStyleSetTextColor(red,green,blue)
# Compute label shift perpendicular to arrow to center label
shift1 = 0.5 * (height * cosd(direction) - length * sind(direction))
# Compute label shift parallel to arrow to avoid overwriting arrow
offset = arrowLength * 0.1
if (direction >= 0 and direction < 90) then
shift2 = offset
if (direction >= 90 and direction < 180) then
shift2 = offset - length * cosd(direction)
if (direction >= 180 and direction < 270) then
shift2 = offset - length * cosd(direction) - height * sind(direction)
if (direction >= 270 and direction <= 360) then
shift2 = offset - height * sind(direction)
# shift pen position and draw label
if (shift1 < 0 ) { # MoveTo distances can't be less than 0
shift1 = abs(shift1) # absolute value
LineStyleMoveTo(direction + 90,shift1) }
else {
LineStyleMoveTo(direction - 90,shift1) }
LineStyleMoveTo(direction, shift2)
LineStyleDrawText(label$,height,0,0)