Re: [OpenMap Users] How To capture Event in a Layer

From: Mike Lackey <mr.blutarski_at_gmail.com>
Date: Thu, 15 May 2008 08:17:29 -0500

Another Mike asks:

My application side of that project is to receive Aircraft objects
that contain a lat/long and some other simple information (N
objects/sec ), display them on a map and load the appropriate
shape/tiff files. User shall be able to click on the aircraft and get
the information about that aircraft in pop up window/or like
LocationLayer that holds cities.
-------------------------

This Mike replies: here is an earlier post for somebody who wanted to
display Mil Std icons. An icon is an icon, maybe some of it is
useful.
--------------------------


I used OMScalingIcon. Here is an example:


public class MyIconObject
{
    /**
     * the openmap icon
     */
    protected OMScalingIcon omIcon = null;


    /** Creates a new instance of an icon object*/
    public MyIconObject(float lat, float lon, String fileName)
    throws MyException
    {
        if (fileName == null) {
            throw new MyException ("MyIconObject: null filename");
        }
        ImageIcon imageIcon = new ImageIcon(fileName);
        if (imageIcon == null) {
            throw new MyException ("MyIconObject: null ImageIcon");
        }
        omIcon = new OMScalingIcon(lat, lon, imageIcon);
        if (omIcon == null) {
            throw new MyException ("PointObject: null OMScalingIcon");
        }
        // at map scale of 1:500,000 the icon will appear full size
omIcon.setBaseScale(500000f);
        // icon will be scaled (larger) until map scale > value
        omIcon.setMaxScale(500000f);
        // icon will be scaled (smaller) until map scale < this value
        omIcon.setMinScale(defaultIconMinScale);
        // when selected, color is red
        omIcon.setSelectPaint(Color.red);
    }
}


For my applicaton, MyIconObject "has a" OMScalingIcon, rather than "is
a" OMScalingIcon. I chose this design for a particular reason. But the
"is a" relationship is also logical (and perhaps more intuituve):


public class MyIconObject extends OMScalingIcon
{
}


Next, BasicLocationHandler.java will need a list of all objects on the
map. The location handler is responsible for the creating/maintaining
the list. Here is sample code:


public class MyObjectHandler
{
    // a list of all objects on the map
    protected Vector<MyIconObject> objList;


    // add an object to the map
    public void addIconObject (MyIconObject obj) {
        objList.add(obj);
    }


    /**
     * When the layer receives a new projection, it goes to each
     * objectHandler and asks it for additions to the layer's graphic list
     */
    public void get
    (float nLat, float wLon, float sLat, float eLon, Vector graphicList)
    {
        for (int i=0; i<objList.size(); i++)
        {
            // the object is an icon image, or similar,
            // and is defined by a singular point.
            // if the point is within the projection, show the image.
            MyIconObject iconObj = objList.get(i);
            if ((sLat <= iconObj .getLat()) && (iconObj .getLat()<= nLat))
            {
                if ((wLon <= iconObj .getLon()) && (iconObj .getLon()<= eLon))
                {
                    graphicList.add(iconObj);
                }
            }
        }
    }
}


Finally, create icons and add them to the map:


      MyIconObject myIcon= new MyIconObject (lat, lon, "C:/somefile.png");
        MyObjectHandler myHandler = myLayer.getMyHandler();
        myHandler.add (myIcon);
        myLayer.doPrepare();

--------------------------
Mike

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Thu May 15 2008 - 09:19:27 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT