Re: rangeControl with McIdas Map outlines

Hi Tim,

The RangeControl isn't working because the longitude values
in your map lie in the range (-180, +180), and the RangeControl
narrows this to (-180, -60).  With no RangeControl, VisAD's
smart longitude display logic wraps the values in (+120, +180)
to (-240, -180).  One work around is to take the values out
of the UnionSet return by BaseMapAdapter.getData(), wrap the
longitudes from (-180, +180) to (-240, +120), use them to
construct a new UnionSet, and display it.  Another approach
is to BaseMapAdapter's capability to select ranges, and
return your (-240, -60) range as the disjoint union of
ranges (+120, +180) and (-180, -60).  This is actually
pretty easy, and I've attached a modified version of your

Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
/* CCLI MapTest Class */

   This class is responsible for reading a McIdas Map database and
   drawing a map.

// Import needed classes

import visad.*;
import java.rmi.RemoteException;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
import javax.swing.*;
import visad.ColorControl;
import visad.CoordinateSystem;
import visad.ConstantMap;
import visad.Data;
import visad.DataReference;
import visad.DataReferenceImpl;
import visad.Display;
import visad.DisplayImpl;
import visad.RealTupleType;
import visad.RealType;
import visad.ScalarMap;
import visad.java3d.DisplayImplJ3D;
import visad.RangeControl;

public class MapTest
   public static ScalarMap latMap;     // latitude  -> YAxis
   public static ScalarMap lonMap;     // longitude -> XAxis
   public static ScalarMap lonRangeMap;
   public static ScalarMap latRangeMap;
   public static DataReference maplinesRef;
   public static DataReference maplinesRef2;
   public static ConstantMap[] maplinesConstantMap = new ConstantMap[4];
   public static DisplayImplJ3D display;

    public MapTest(String mapFile)
            //  Read in the map file
            BaseMapAdapter baseMapAdapter = new BaseMapAdapter(mapFile);
            BaseMapAdapter baseMapAdapter2 = new BaseMapAdapter(mapFile);

            // Set ScalarMaps for X and Y axes
            latMap = new ScalarMap(RealType.Latitude, Display.YAxis);
            lonMap = new ScalarMap(RealType.Longitude, Display.XAxis);

            // Remove any prior data references

            // Add the lat/lon maps

            // Set the lat/lon range within the 3D bounding box
            latMap.setRange(-30.0, 30.0);
            lonMap.setRange(-240.0, -60.0);

// In this next code section I am trying to create a RangeControl so that
// only the desired world map outlines between longitude -240 to -60 and 
// latitude -30 to 30 are displayed in the 3D bounding box.
// However, when this code is added, the map outlines between -240 and -180
// degrees Longitude do not display.  If the code is commented out, as below,
// all the correct map outlines appear within the 3D bounding box.  However,
// the rest of the world map also appears outside of the bounding box.
// How do I get all the desired map outlines within the 3D bounding box 
// without having the rest of the world map appear outside the bounding box?
      lonRangeMap = new ScalarMap(RealType.Longitude,Display.SelectRange);
      RangeControl lonRangeControl = (RangeControl) lonRangeMap.getControl();
      latRangeMap = new ScalarMap(RealType.Latitude,Display.SelectRange);
      RangeControl latRangeControl = (RangeControl) latRangeMap.getControl();
      float[] nlonRange = { -240.0f, -60.0f };
      float[] nlatRange = { -30.0f, 30.0f };
      lonRangeControl.setRange ( nlonRange );
      latRangeControl.setRange ( nlatRange );
            // create a reference for the map lines
            maplinesRef = new DataReferenceImpl("MapTest");
            baseMapAdapter.setLatLonLimits(-30.0f, 30.0f, -180.0f, -60.0f);
            maplinesRef2 = new DataReferenceImpl("MapTest2");
            baseMapAdapter2.setLatLonLimits(-30.0f, 30.0f, 120.0f, 180.0f);

            // set the attributes of the map lines (color, location)
            maplinesConstantMap[0] = new ConstantMap(0., Display.Blue);
            maplinesConstantMap[1] = new ConstantMap(1., Display.Red);
            maplinesConstantMap[2] = new ConstantMap(0., Display.Green);
            maplinesConstantMap[3] = new ConstantMap(1.001, Display.Radius); 
            display.addReference (maplinesRef, maplinesConstantMap);
            display.addReference (maplinesRef2, maplinesConstantMap);
        catch (Exception ne)
            ne.printStackTrace(); System.exit(1);


  public static void main(String[] args)
        throws RemoteException, VisADException

    display = new DisplayImplJ3D("display1");
    MapTest mapLines = new MapTest("../examples/OUTLSUPW");
    JFrame jframe = new JFrame();
    jframe.setContentPane( (JPanel) display.getComponent() );


  • 2000 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: