public class CSVLocationHandler extends AbstractLocationHandler implements LocationHandler, java.awt.event.ActionListener
The individual fields must not have leading whitespace.
The CSVLocationLayer gives you some basic functionality. The properties file lets you set defaults on whether to draw the locations and the names by default. For crowded layers, having all the names displayed might cause a cluttering problem. In gesture mode, OpenMap will display the name of each location as the mouse is passed over it. Pressing the left mouse button over a location brings up a popup menu that lets you show/hide the name label, and also to display the entire row contents of the location CSV file in a Browser window that OpenMap launches.
If you want to extend the functionality of this LocationHandler, there are a couple of methods to focus your changes: The setProperties() method lets you add properties to set from the properties file. The createData() method, by default, is a one-time method that creates the graphic objects based on the CSV data. By modifying these methods, and creating a different combination graphic other than the CSVLocation, you can create different layer effects pretty easily.
The locationFile property should contain a URL referring to the file. This can take the form of file:/myfile.csv for a local file or http://somehost.org/myfile.csv for a remote file.
In the openmap.properties file (for instance):
# In the section for the LocationLayer: locationLayer.locationHandlers=csvlocationhandler csvlocationhandler.class=com.bbn.openmap.layer.location.csv.CSVLocationHandler csvlocationhandler.locationFile=/data/worldpts/WorldLocs_point.csv csvlocationhandler.csvFileHasHeader=true csvlocationhandler.locationColor=FF0000 csvlocationhandler.nameColor=008C54 csvlocationhandler.showNames=false csvlocationhandler.showLocations=true csvlocationhandler.nameIndex=0 csvlocationhandler.latIndex=8 csvlocationhandler.lonIndex=10 # Optional property, if you have a column in the file for URLs of # images to use for an icon. csvlocationhandler.iconIndex=11 # Optional property, URL of image to use as marker for all entries in # csv file without a URL listed at the iconIndex. csvlocationhandler.defaultIconURL=/data/symbols/default.gif # Optional property, if the eastern hemisphere longitudes are negative. False by default. csvlocationhandler.eastIsNeg=false # CSVLocationHandler has been updated to have regular DrawingAttribute properties for both name and location. csvlocationhandler.name.lineColor=FF008C54 csvlocationhandler.location.lineColor=FFFF0000 csvlocationhandler.location.fillColor=FFaaaaaa csvlocationhandler.location.pointRadius=3 csvlocationhandler.location.pointOval=true # The old nameColor and locationColor properties will still work, and will take precedence over these DrawingAttribtues properties.
Modifier and Type | Class and Description |
---|---|
class |
CSVLocationHandler.DefaultLocationDecoder |
static interface |
CSVLocationHandler.TokenDecoder |
Modifier and Type | Field and Description |
---|---|
protected javax.swing.Box |
box |
protected boolean |
csvHasHeader
Flag that specifies that the first line consists of header information,
and should not be mapped to a graphic.
|
static java.lang.String |
csvHeaderProperty
Set if the CSVFile has a header record.
|
protected java.lang.String |
defaultIconURL |
static java.lang.String |
DefaultIconURLProperty
Property to set an URL for an icon image to use for all the locations
that don't have an image defined in the csv file, or if there isn't an
icon defined in the csv file for any of the locations and you want them
all to have the same icon.
|
protected boolean |
eastIsNeg
Are east values really negative with this file?
|
static java.lang.String |
eastIsNegProperty
The property describing whether East is a negative value.
|
protected int |
iconIndex
Index of column in CSV to use as URL of the icon.
|
static java.lang.String |
IconIndexProperty
Property to use to designate the column of the CSV file to use as an icon
URL
|
protected int |
latIndex
Index of column in CSV to use as latitude of location.
|
static java.lang.String |
LatIndexProperty
Property to use to designate the column of the CSV file to use as the
latitude.
|
protected java.lang.String |
locationFile
The path to the primary CSV file holding the locations.
|
static java.lang.String |
LocationFileProperty
The property describing the locations of location data.
|
protected int |
lonIndex
Index of column in CSV to use as longitude of location.
|
static java.lang.String |
LonIndexProperty
Property to use to designate the column of the CSV file to use as the
longitude.
|
protected int |
nameIndex
Index of column in CSV to use as name of location.
|
static java.lang.String |
NameIndexProperty
Property to use to designate the column of the CSV file to use as a name.
|
protected QuadTree |
quadtree
The storage mechanism for the locations.
|
i18n, locationDrawingAttributes, logger, nameDrawingAttributes, propertyPrefix, zLayer
defaultLocationColorString, defaultNameColorString, forceGlobalCommand, ForceGlobalProperty, LocationColorProperty, LocationPropertyPrefix, NameColorProperty, NamePropertyPrefix, readDataCommand, showdetails, showLocationsCommand, ShowLocationsProperty, showname, showNamesCommand, ShowNamesProperty
EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty
Constructor and Description |
---|
CSVLocationHandler()
The default constructor for the Layer.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
The Action Listener method, that reacts to the palette widgets actions.
|
protected boolean |
checkIndexSettings() |
protected QuadTree |
createData()
Look at the CSV file and create the QuadTree holding all the Locations.
|
protected Location |
createLocation(float lat,
float lon,
java.lang.String name,
java.lang.String iconURL)
When a new Location object needs to be created from data read in the CSV
file, this method is called.
|
OMGraphicList |
get(float nwLat,
float nwLon,
float seLat,
float seLon,
OMGraphicList graphicList)
Prepares the graphics for the layer.
|
java.awt.Component |
getGUI()
Provides the palette widgets to control the options of showing maps, or
attribute text.
|
java.util.List<java.awt.Component> |
getItemsForPopupMenu(Location loc)
The location layer passes a LocationPopupMenu to the handler when on of
its locations has been clicked on.
|
java.util.Properties |
getProperties(java.util.Properties props)
PropertyConsumer method, to fill in a Properties object, reflecting the
current values of the layer.
|
java.util.Properties |
getPropertyInfo(java.util.Properties list)
Method to fill in a Properties object with values reflecting the
properties able to be set on this PropertyConsumer.
|
protected CSVLocationHandler.TokenDecoder |
getTokenDecoder() |
protected java.lang.String[] |
readCSVLineFromFile(java.io.BufferedReader ranFile,
java.lang.String[] retPaths) |
void |
reloadData()
A trigger function to tell the handler that new data is available.
|
void |
setProperties(java.lang.String prefix,
java.util.Properties properties)
The properties and prefix are managed and decoded here, for the standard
uses of the CSVLocationHandler.
|
getLayer, getLocationColor, getLocationDrawingAttributes, getNameColor, getNameDrawingAttributes, getPropertyPrefix, isForceGlobal, isShowLocations, isShowNames, removed, setForceGlobal, setLayer, setLocationColor, setLocationDrawingAttributes, setNameColor, setNameDrawingAttributes, setProperties, setPropertyPrefix, setShowLocations, setShowNames
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getLayer, isForceGlobal, isShowLocations, isShowNames, removed, setForceGlobal, setLayer, setShowLocations, setShowNames
getPropertyPrefix, setProperties, setPropertyPrefix
protected java.lang.String locationFile
public static final java.lang.String LocationFileProperty
public static final java.lang.String csvHeaderProperty
protected QuadTree quadtree
public static final java.lang.String eastIsNegProperty
protected boolean eastIsNeg
protected boolean csvHasHeader
protected int nameIndex
public static final java.lang.String NameIndexProperty
public static final java.lang.String LatIndexProperty
public static final java.lang.String LonIndexProperty
public static final java.lang.String IconIndexProperty
public static final java.lang.String DefaultIconURLProperty
protected int latIndex
protected int lonIndex
protected int iconIndex
protected java.lang.String defaultIconURL
protected javax.swing.Box box
public CSVLocationHandler()
public void setProperties(java.lang.String prefix, java.util.Properties properties)
setProperties
in interface PropertyConsumer
setProperties
in class AbstractLocationHandler
prefix
- string prefix used in the properties file for this layer.properties
- the properties set in the properties file.public java.util.Properties getProperties(java.util.Properties props)
getProperties
in interface PropertyConsumer
getProperties
in class AbstractLocationHandler
props
- a Properties object to load the PropertyConsumer properties
into.public java.util.Properties getPropertyInfo(java.util.Properties list)
getPropertyInfo
in interface PropertyConsumer
getPropertyInfo
in class AbstractLocationHandler
list
- a Properties object to load the PropertyConsumer properties
into. If getList equals null, then a new Properties object should
be created.public void reloadData()
LocationHandler
reloadData
in interface LocationHandler
protected boolean checkIndexSettings()
protected QuadTree createData()
protected CSVLocationHandler.TokenDecoder getTokenDecoder()
protected Location createLocation(float lat, float lon, java.lang.String name, java.lang.String iconURL)
lat
- latitude of location, decimal degrees.lon
- longitude of location, decimal degrees.name
- the label of the location.iconURL
- the String for a URL for an icon. Can be null.protected java.lang.String[] readCSVLineFromFile(java.io.BufferedReader ranFile, java.lang.String[] retPaths)
ranFile
- the file to be read. The file pointer should be set to the
line you want read.public OMGraphicList get(float nwLat, float nwLon, float seLat, float seLon, OMGraphicList graphicList)
Occasionally it is necessary to abort a prepare call. When this happens, the map will set the cancel bit in the LayerThread, (the thread that is running the prepare). If this Layer needs to do any cleanups during the abort, it should do so, but return out of the prepare asap.
get
in interface LocationHandler
nwLat
- NorthWest latitude of area of interest.nwLon
- NorthWest longitude of area of interest.seLat
- SouthEast latitude of area of interest.seLon
- SouthEast longitude of area of interest.graphicList
- Vector to add Locations to. If null, the
LocationHandler should create a new Vector to place graphics into.public java.util.List<java.awt.Component> getItemsForPopupMenu(Location loc)
LocationHandler
getItemsForPopupMenu
in interface LocationHandler
loc
- Location that items should be provided for.public java.awt.Component getGUI()
getGUI
in interface LocationHandler
getGUI
in class AbstractLocationHandler
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details