!******************************************************************************!
! Starter test for the experimental prototype supporting the plotting of GeoJSON (.geojson) files.
!
! @issue   NXM-3679 GeoJSON support
! @author  Jeanette McCall
! Since:   NeXtMidas 4.1.3
!******************************************************************************!
startmacro/auto
  switch INTERACTIVE interAct    GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline    GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)
  switch PLAINJSON   plainjson   GET DEF=FALSE SDEF=TRUE

  invoke z:jvmHangFix nxm.sys.lib.Shell.getJVMHangWorkaround()
  res z:mytrue true
  invoke ,, nxm.sys.lib.Shell.setJVMHangWorkaround(^mytrue)

  if interAct then
    call setDatDir

    set defaultInstructions "&
       Both Plots:\n&
       - 2 part MultiPolygon over Canada and Alaska\n&
       - 2 part MultiLineString between South America and Africa\n&
       - 2 part MultiPoint off coast of Africa\n&
       - GeometryCollection of\n   &
         LineString off coast of Australia\n   &
         Point off coast of Africa\n&
       - Polygon with inner Polygon over Africa and Europe\n&
       - Filled Polygon with inner Polygons off coast of Australia\n&
       - Simple Polygon south of Mexico\n&
       - LineString over Indonesia and Malaysia\n\n&
       Left Plot - default colors:\n&
       - objects: green\n&
       - fill:    aqua\n&
       Right Plot - custom colors:\n&
       - objects: yellow\n&
       - fill:    pink\n\n&
       Cntrl-LMB to verify object type&
       "

    set layerGeoJSONDef "LT="GeoJSON",SELECTMESSAGES=TRUE"
    set layerGeoJSONCustom "LT="GeoJSON",SELECTMESSAGES=TRUE,SELECTCOLOR=BLUE,COLOR=AQUA,LINECOLOR=YELLOW,POLYGONFILLCOLOR=PINK,POLYGONOUTLINE=FALSE"

    pipe init
      panel/msgid=MAIN/setup/controls=gc

      gcontrol label mainLabel "Main"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      if plainjson ISFALSE then
        plot/id=idplotDef/msgid=main/READOUT="+OnAxis" ^{datDir}.world.shp|nxm.sys.test.geojson_sample_standard.geojson{Layer={^{layerGeoJSONDef}}}
        plot/id=idplotCustom/msgid=main/READOUT="+OnAxis" ^{datDir}.world.prm|nxm.sys.test.geojson_sample_standard.geojson{Layer={^{layerGeoJSONCustom}}}
      else
        plot/id=idplotDef/msgid=main/READOUT="+OnAxis" ^{datDir}.world.shp|nxm.sys.test.geo_data_json.geojson{EnableJSONSearch=true,Layer={^{layerGeoJSONDef}}}
        plot/id=idplotCustom/msgid=main/READOUT="+OnAxis" ^{datDir}.world.prm|nxm.sys.test.geo_data_json_ns.geojson{EnableJSONSearch=true,Layer={^{layerGeoJSONCustom}}}
      endif

      gcontrol text idtext "Instructions" "^defaultInstructions" 40 30 /title

      shellgui/id=idshellgui/attach/rows=15
    pipe off

  endif

  ! Additional interactive tests, only run with /BASELINE
  if interAct and baseline then
    %test_plot_layergeojson_range ! NXM-3679
  endif

  invoke ,, nxm.sys.lib.Shell.setJVMHangWorkaround(^jvmHangFix)
endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name user indicated" msg.data eqss "PASS"
    pipe stop
  elseif msg.name EQS "SELECT" OR msg.name EQS "DESELECT" then
    info "^msg.name MESSAGE"
    say "^msg.name ^msg.data"
  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
