! Macro - Graphics Lab
!
! Author: George P. Burdell
!
startmacro
  set count 0
  pipe on
    panel/setup/controls=gc
    
    ! Setup the Plot
    plot/msgid=main/id=myplot world.shp|cities.prm

    ! Setup the List
    header/create ram:locations SR=(ALT/SD,LAT/SD,LON/SD,NAME/2A)
    set template {_GLOBAL_={FGCOLOR="RED"},&
                  ALT={WIDTH=16,ALIGN="CENTER",FORMAT="#ft"},&
                  LAT={WIDTH=16,ALIGN="CENTER",FORMAT="DMS"},&
                  LON={WIDTH=16,ALIGN="CENTER",FORMAT="DMS"},&
                  NAME={WIDTH=16,ALIGN="CENTER"}}
    list2/id=mylist locations template

    ! Setup the Feature
    feature LABEL=feature PLOT=myplot &
            TABLE={NAME="MYFEATURE",TYPE="SYMBOL",COLOR="RED",&
                   LINE={SYMBOL="DIAMOND",SYMBOLSIZE="12",SYMBOLFILL="ON"}}
    
    gcontrol label  MyApp    "My Application"  AlwaysOpen
    gcontrol button state    ""                "Exit"
    
    gcontrol label  status     "Status"
    gcontrol dval   altitude   "Alt=" 0 0    1e9 1 /EDIT=false
    gcontrol dval   latitude   "Lat=" 0 -90  90  1 /EDIT=false
    gcontrol dval   longitude  "Lon=" 0 -180 180 1 /EDIT=false
    
    gcontrol label  plotopts   "Plot Options" Closed
    gcontrol choice mapoptions "Map Options"  "Opaque,Transparent" 1
    gcontrol button citycolor  "City Color "  "SetColor" /tleft
  pipe off
endmacro



procedure processMessage m:msg
  say "Got message name=^msg.name info=^msg.info data=^msg.data"
  
  if msg.fid eqs "MYPLOT" then
    if msg.name eqs "MARK" then
      ! Update the Controls
      set gc.altitude.value   msg.data.alt
      set gc.latitude.value   msg.data.lat
      set gc.longitude.value  msg.data.lon

      ! Update the Feature
      set feature.z msg.data.alt
      set feature.y msg.data.lat
      set feature.x msg.data.lon

      ! Update the List
      calc l:count count 1 +
      set row {NAME="Point Number ^count",&
               ALT=msg.data.alt,LAT=msg.data.lat,LON=msg.data.lon}
      invoke ,, reg.mylist.addRow(row)
    endif
  elseif msg.name eqs "STATE" and msg.data eqs "EXIT" then
    pipe stop
  elseif msg.name eqs "MAPOPTIONS" then
    if msg.data eqs "OPAQUE" then
      set reg.myplot.layers.world.opaq 100
    else
      set reg.myplot.layers.world.opaq 0
    endif
  elseif msg.name eqs "CITYCOLOR" then
    popup/BLOCKING=None/msgid=main/msgname="NewColor"/TITLE="Set City Color" ,, COLOR
    
  elseif msg.name eqs "NEWCOLOR" then
    set reg.myplot.layers.cities.color msg.data
    
  else
    warn "Unhandled message name=^msg.name info=^msg.info data=^msg.data"
  endif
return

