📄 location.java
字号:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/location/Location.java,v $// $RCSfile: Location.java,v $// $Revision: 1.6.2.5 $// $Date: 2005/08/11 21:03:23 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.location;/* Java Core */import java.awt.Graphics;import java.awt.Paint;import java.awt.Point;import java.awt.Rectangle;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.Layer;import com.bbn.openmap.layer.DeclutterMatrix;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.omGraphics.OMPoint;import com.bbn.openmap.omGraphics.OMText;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * A Location is a place. It can be thought of as a lat/lon place, * with or without an pixel offset, or a place on the screen. A * location is basically thought of as having a name, which get * represented as a label, and some graphical represenation. It is * abstract because it doesn't really know what kind of markers or * labels are being used or how they are being positioned around the * particular point. Therefore, it should be extended, and the * setGraphicLocations methods implemented to position the marker and * text as desired. * <P> */public abstract class Location extends OMGraphic { /** * The main latitude of object, in decimal degrees, for * RENDERTYPE_LATLON and RENDERTYPE_OFFSET locations. */ public float lat = 0.0f; /** * The main longitude of object, in decimal degrees, for * RENDERTYPE_LATLON and RENDERTYPE_OFFSET locations. */ public float lon = 0.0f; /** * The x pixel offset from the longitude, for RENDERTYPE_OFFSET * locations. */ public int xOffset = 0; /** * The y pixel offset from the latitude, for RENDERTYPE_OFFSET * locations. */ public int yOffset = 0; /** The x object location, in pixels, for RENDERTYPE_XY locations. */ public int x = 0; /** The y object location, in pixels, for RENDERTYPE_XY locations. */ public int y = 0; /** The name of the location. */ public String name = null; /** * The LocationHandler that is handling the location. Need this to * check for more global settings for rendering. */ public LocationHandler handler; public final static int DECLUTTER_LOCALLY = -1; public final static int DECLUTTER_ANYWHERE = -2; /** The Label of the object. */ protected OMText label = null; /** The simple location marker of the object. */ protected OMGraphic location = null; /** The URL to display when the object is gestured upon. */ protected String details = ""; /** The flag for displaying the location marker. */ protected boolean showLocation = true; /** The flag for displaying the name label. */ protected boolean showName = true; /** * The original offset/y location, kept for resetting the * placement of the label after decluttering and/or location * placement. */ public int origYLabelOffset = 0; /** * The original offset/x location, kept for resetting the * placement of the label after decluttering and/or location * placement. */ public int origXLabelOffset = 0; /** * the default distance away a label should be placed from a * location marker. */ public final static int DEFAULT_SPACING = 6; /** * The pixel limit where the delcutter matrix won't draw the name, * if it can't put the name at least this close to the original * place. DECLUTTER_LOCALLY keeps the limit to twice the height of * the label. DECLUTTER_ANYWHERE will place the thing anywhere it * fits. Anything else is the pixel limit. */ protected int declutterLimit = DECLUTTER_LOCALLY; /** Set whether you want this location label decluttered. */ protected boolean allowDecluttering = true; /** * The horizontal pixel distance you want to place the text away * from the actual location - to put space between the graphic. */ protected int horizontalLabelBuffer = 0; /** * A plain contructor if you are planning on setting everything * yourself. */ public Location() {} /** * Create a location at a latitude/longitude. If the * locationMarker is null, a small rectangle (dot) will be created * to mark the location. * * @param latitude the latitude, in decimal degrees, of the * location. * @param longitude the longitude, in decimal degrees, of the * location. * @param name the name of the location, also used in the label. * @param locationMarker the OMGraphic to use for the location * mark. */ public Location(float latitude, float longitude, String name, OMGraphic locationMarker) { setLocation(latitude, longitude); this.name = name; if (Debug.debugging("locationdetail")) { Debug.output("Location Lat/Lon(" + latitude + ", " + longitude + ", " + name + ")"); } if (locationMarker == null) { location = new OMPoint(lat, lon); } else { location = locationMarker; } // We can do the x offset off the location here, we'll do the // vertical offset later, when we can figure out the height of // the text and can line the middle of the text up with the // location. // If the caller has supplied a substitute graphic for // the location spot, it's up to them to horizontally // offset the label appropriately. They should do that // here, or in an extended class. label = new OMText(lat, lon, 0, 0, name, OMText.JUSTIFY_LEFT); } /** * Create a location at a map location. If the locationMarker is * null, a small rectangle (dot) will be created to mark the * location. * * @param x the pixel location of the object from the let of the * map. * @param y the pixel location of the object from the top of the * map * @param name the name of the location, also used in the label. * @param locationMarker the OMGraphic to use for the location * mark. */ public Location(int x, int y, String name, OMGraphic locationMarker) { setLocation(x, y); this.name = name; if (Debug.debugging("locationdetail")) { Debug.output("Location XY(" + x + ", " + y + ", " + name + ")"); } if (locationMarker == null) { location = new OMPoint(x, y); } else { location = locationMarker; } // We can do the x offset off the location here, we'll do the // vertical offset later, when we can figure out the height of // the text and can line the middle of the text up with the // location. // If the caller has supplied a substitute graphic for // the location spot, it's up to them to horizontally // offset the label appropriately. They should do that // here, or in an extended class. label = new OMText(x, y, name, OMText.JUSTIFY_LEFT); } /** * Create a location at a pixel offset from a latitude/longitude. * If the locationMarker is null, a small rectangle (dot) will be * created to mark the location. * * @param latitude the latitude, in decimal degrees, of the * location. * @param longitude the longitude, in decimal degrees, of the * location. * @param xOffset the pixel location of the object from the * longitude. * @param yOffset the pixel location of the object from the * latitude. * @param name the name of the location, also used in the label. * @param locationMarker the OMGraphic to use for the location * mark. */ public Location(float latitude, float longitude, int xOffset, int yOffset, String name, OMGraphic locationMarker) { setLocation(latitude, longitude, xOffset, yOffset); this.name = name; if (Debug.debugging("locationdetail")) { Debug.output("Location(" + latitude + ", " + longitude + ", offset " + x + ", " + y + ", " + name + ")"); } if (locationMarker == null) { location = new OMPoint(lat, lon, xOffset, yOffset); } else { location = locationMarker; } // We can do the x offset off the location here, we'll do the // vertical offset later, when we can figure out the height of // the text and can line the middle of the text up with the // location. // If the caller has supplied a substitute graphic for // the location spot, it's up to them to horizontally // offset the label appropriately. They should do that // here, or in an extended class. label = new OMText(lat, lon, xOffset, yOffset, name, OMText.JUSTIFY_LEFT); } /** Set the placement of the location. */ public void setLocation(float latitude, float longitude) { lat = latitude; lon = longitude; origYLabelOffset = 0; origXLabelOffset = DEFAULT_SPACING; setRenderType(RENDERTYPE_LATLON); if (location != null && label != null) { setGraphicLocations(latitude, longitude); } } /** Set the placement of the location. */ public void setLocation(int x, int y) { this.x = x; this.y = y; origYLabelOffset = y; origXLabelOffset = x + DEFAULT_SPACING; setRenderType(RENDERTYPE_XY); if (location != null && label != null) { setGraphicLocations(x, y); } } /** Set the placement of the location. */ public void setLocation(float latitude, float longitude, int xOffset, int yOffset) { lat = latitude; lon = longitude; this.xOffset = xOffset; this.yOffset = yOffset; origYLabelOffset = yOffset; origXLabelOffset = xOffset + DEFAULT_SPACING; setRenderType(RENDERTYPE_OFFSET); if (location != null && label != null) { setGraphicLocations(latitude, longitude, xOffset, yOffset); } } /** * Convenience method that lets you provide a screen x, y and a * projection to the location, and let the location hash out how * to place itself based on it's rendertype. */ public void setLocation(int x, int y, Projection proj) { int renderType = getRenderType(); LatLonPoint llp; switch (renderType) { case RENDERTYPE_LATLON: if (proj != null) { llp = proj.inverse(x, y); setLocation(llp.getLatitude(), llp.getLongitude()); } else { Debug.error("Location can't set lat/lon coordinates without a projection"); } break; case RENDERTYPE_OFFSET: if (proj != null) { llp = proj.inverse(x, y); setLocation(llp.getLatitude(), llp.getLongitude(), this.xOffset, this.yOffset); } else { Debug.error("Location can't set lat/lon coordinates without a projection"); } break; default: setLocation(x, y); } } public abstract void setGraphicLocations(float latitude, float longitude); public abstract void setGraphicLocations(int x, int y); public abstract void setGraphicLocations(float latitude, float longitude, int offsetX, int offsetY); /** * Set the location handler for the location. */ public void setLocationHandler(LocationHandler lh) { handler = lh; } /** * Get the location handler for the location. */ public LocationHandler getLocationHandler() { return handler; } /** * Set the edge java.awt.Paint for the marker graphic. */ public void setLocationPaint(Paint locationPaint) { if (location != null) { location.setLinePaint(locationPaint); } } /** * Get the label for the location. */ public OMText getLabel() { return label; } /** * Set the label for the location. */ public void setLabel(OMText lable) { label = lable; } /** * Get the location marker for this location. */ public OMGraphic getLocationMarker() { return location; } /** * Set the graphic for the location. */ public void setLocationMarker(OMGraphic graphic) { location = graphic; } /** * Set whether this location should be shown on an individual * basis. */ public void setShowLocation(boolean showLocations) { showLocation = showLocations; } /** See of the location is displaying it's location. */ public boolean isShowLocation() { return showLocation; } /** Set the location to display it's label. */ public void setShowName(boolean showNames) { showName = showNames; } /** See if the location is displaying it's label. */ public boolean isShowName() { return showName; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -