! Test case for Bug 1598 (PLOT: extra points appear when zooming in on a LayerXY)
!
! @bug NXM-3496 LayerXY support for labels - 3.9.3
! @author  J. Czechowski IV
!
startmacro

  call setDatDir

  file open/d/n test_file ram:test_file{SR=(AZ/SD,EL/SD,CITY/XA)}
    do az 0 99 1
      do el 0 99 1
        ! point names added in 3.9.3 for NXM-3495
        calc i:ptnum el 10 MOD
        file write test_file {AZ=^az,EL=^el,CITY="p^ptnum"}
      enddo
    enddo
  file close test_file

  res airportquals {HEADERROWS=L:1,COLUMNNAMES="NAME|CODE|F:LAT|F:LON",&
             LAYER={LABEL="NAME",LT="XY",X="LON",Y="LAT",LINE={COLOR="red",TYPE="symbol"},ENABLE=+LABELS}}

  set instructions "Bottom Plot (CSV):\n&
                    Names of airports (cities) are displayed\n\n&
                    Top Plot (BLUE):\n&
                    1) Click 'ZoomIn'\n&
                    2) Verify that there are no extra points.\n&
                    3) Click 'Add Labels'\n&
                    4) Points should now be labeled"

  pipe on
    panel/setup/controls=gc
    plot/id=test ram:test_file{LAYER={LT=XY,X=AZ,Y=EL,NAME=CITY,LINE={TYPE=SOLID|SYMBOL,SYMBOL=CIRCLE}}}
    plot/id=csv world.shp|^{datDir}.airports.csv^airportquals SCALETABLE={X1=-180,X2=0,Y1=-60,Y2=-10}

    gcontrol menu   main   "Exit with Status = " "PASS,FAIL" /tleft
    gcontrol text   idtext "Instructions" "^instructions" 24 12 /title
    gcontrol button zoom   ""             "ZoomIn"
    gcontrol button labels ""             "Add Labels"
    set gc.main.itemColors {PASS=GREEN,FAIL=RED}
  pipe off
endmacro

!******************************************************************************!
procedure processMessage m:msg

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: Interactive tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "ZOOM" and msg.data eqs "ZoomIn" then
    message sendw test ,, ZOOM ,, {XMIN=D:-0.016156908309919525,XMAX=D:0.08271457545557145,YMIN=D:91.48487957961821,YMAX=D:99.34995856195702}

  elseif msg.name eqs "LABELS" then
    set reg.test.layers.city.enable +LABELS

  endif
return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
