📄 overviewmaphandler.java
字号:
+ MinScaleProperty, defaultMinScale);
String uom = props.getProperty(prefix + MinScaleUomProperty);
if (uom != null) {
minScaleUom = Length.get(uom);
setMinScale(minScale, minScaleUom);
}
backgroundSlave = PropUtils.booleanFromProperties(props, prefix
+ BackgroundSlaveProperty, backgroundSlave);
setControlSourceMap(PropUtils.booleanFromProperties(props, prefix
+ ControlSourceMapProperty, controlSourceMap));
String statusLayerName = props.getProperty(prefix + StatusLayerProperty
+ ".class");
if (statusLayerName != null) {
statusLayer = (Layer) ComponentFactory.create(statusLayerName,
prefix + StatusLayerProperty,
props);
if (statusLayer == null) {
Debug.error("OverviewMapHandler.setProperties: status layer not set.");
}
} else {
statusLayer = new OverviewMapAreaLayer();
}
statusLayer.setProperties(prefix, props);
projection = createStartingProjection(props.getProperty(prefix
+ ProjectionTypeProperty));
setLayers(LayerHandler.getLayers(overviewLayers, overviewLayers, props));
}
private Proj createStartingProjection(String projName) {
Class projClass = ProjectionFactory.getProjClassForName(projName);
if (projClass == null) {
projClass = Mercator.class;
}
// The scale, lat/lon and size shouldn't matter, because the
// size will get reset when it is added to a component, and
// the projection will change when it is added to a MapBean
// as a projection listener.p
return (Proj) ProjectionFactory.makeProjection(projClass,
Environment.getFloat(Environment.Latitude, 0f),
Environment.getFloat(Environment.Longitude, 0f),
Environment.getFloat(Environment.Scale, Float.POSITIVE_INFINITY)
* scaleFactor,
INITIAL_WIDTH,
INITIAL_HEIGHT);
}
/**
* PropertyConsumer method, to fill in a Properties object, reflecting the
* current values of the layer. If the layer has a propertyPrefix set, the
* property keys should have that prefix plus a separating '.' prepended to
* each propery key it uses for configuration.
*
* @param props a Properties object to load the PropertyConsumer properties
* into. If props equals null, then a new Properties object should be
* created.
* @return Properties object containing PropertyConsumer property values. If
* getList was not null, this should equal getList. Otherwise, it
* should be the Properties object created by the PropertyConsumer.
*/
public Properties getProperties(Properties props) {
if (props == null) {
props = new Properties();
}
String prefix = PropUtils.getScopedPropertyPrefix(this);
// Build marker list
StringBuffer layerList = new StringBuffer();
Component[] comps = map.getComponents();
int ncomponents = comps.length;
for (int i = 0; i < ncomponents; i++) {
Layer layer = (Layer) comps[i];
if (layer != statusLayer) { // Take care of the
// statusLayer later.
layerList.append(" " + layer.getPropertyPrefix());
layer.getProperties(props);
}
}
props.put(prefix + OverviewMapHandlerLayerProperty,
layerList.toString());
props.put(prefix + ScaleFactorProperty, Float.toString(scaleFactor));
props.put(prefix + ProjectionTypeProperty, map.getProjection()
.getName());
props.put(prefix + MinScaleProperty, Float.toString(minScale));
props.put(prefix + BackgroundSlaveProperty,
new Boolean(backgroundSlave).toString());
if (statusLayer != null) {
props.put(prefix + StatusLayerProperty, statusLayer.getClass()
.getName());
statusLayer.getProperties(props);
}
props.put(prefix + ControlSourceMapProperty,
new Boolean(controlSourceMap).toString());
return props;
}
/**
* Method to fill in a Properties object with values reflecting the
* properties able to be set on this PropertyConsumer. The key for each
* property should be the raw property name (without a prefix) with a value
* that is a String that describes what the property key represents, along
* with any other information about the property that would be helpful
* (range, default value, etc.). For Layer, this method should at least
* return the 'prettyName' property.
*
* @param list a Properties object to load the PropertyConsumer properties
* into. If getList equals null, then a new Properties object should
* be created.
* @return Properties object containing PropertyConsumer property values. If
* getList was not null, this should equal getList. Otherwise, it
* should be the Properties object created by the PropertyConsumer.
*/
public Properties getPropertyInfo(Properties list) {
if (list == null) {
list = new Properties();
}
list.put(OverviewMapHandlerLayerProperty,
"Space separated list of marker names of layers to use as background on the overview map.");
list.put(ScaleFactorProperty,
"Multiplier reflecting the difference between the scale of the overview map and the source map (default is 20.0).");
list.put(ProjectionTypeProperty,
"Projection name to use for overview map (Default is mercator).");
list.put(MinScaleProperty,
"Minimum scale of overview map (Default is 500,000.0).");
list.put(StatusLayerProperty,
"Class name of layer to use as the active layer on the overview map, receiving mouse events (Default is com.bbn.openmap.layer.OverviewMapAreaLayer).");
list.put(ControlSourceMapProperty,
"Flag to have the source map controlled by gestures on the overview map (true/false, default is true).");
list.put(ControlSourceMapProperty + ScopedEditorProperty,
"com.bbn.openmap.util.propertyEditor.TrueFalsePropertyEditor");
list.put(BackgroundSlaveProperty,
"Flag to have the map mimic any changes made to the source map's background (true/false, default is true).");
list.put(BackgroundSlaveProperty + ScopedEditorProperty,
"com.bbn.openmap.util.propertyEditor.TrueFalsePropertyEditor");
statusLayer.getPropertyInfo(list);
return list;
}
/**
* Sets the sourceMap associated with this OverviewMap. if controlSourceMap
* property is set, srcMap will also be controlled by this OverviewHandler
* Passing a null value will remove the current sourceMap from the list of
* Maps that this handler is controlling and set sourceMap to null.
*
* @param srcMap srcMap.
*/
public void setSourceMap(MapBean srcMap) {
if (sourceMap != null) {
removeControlledMap(sourceMap);
sourceMap.removeProjectionListener(this);
sourceMap.removePropertyChangeListener(this);
}
// Add the sourceMap to a set of listeners that wish to be
// controlled by this OverviewMapHandler
if (srcMap != null) {
if (controlSourceMap == true) {
addControlledMap(srcMap);
}
// Check and see if the overview map window is up. If it
// is, we should add the overview map as a projection
// listener to it. Note: overview map windows went away
// due to window support, but not sure how it affected
// this statement. Keeping commented code here for
// reference in case behavior is weird. Seems to be
// working as expected, though. DFD
// if ((overviewWindowFrame != null &&
// overviewWindowFrame.isShowing()) ||
// (overviewWindow != null && overviewWindow.isShowing())
// ||
// Turns out non-tool overview maps weren't becoming
// projection change listeners...
if (!getUseAsTool() && isVisible()) {
srcMap.addProjectionListener(this);
}
srcMap.addPropertyChangeListener(this);
}
sourceMap = srcMap;
}
/**
* Get the map that the overview map is listening to.
*/
public MapBean getSourceMap() {
return sourceMap;
}
/**
* Set the string used for the frame title of the overview map.
*/
public void setFrameTitle(String in_frameTitle) {
frameTitle = in_frameTitle;
}
public String getFrameTitle() {
return frameTitle;
}
/**
* Set whether the map's background mimics changes to the source map's
* background.
*
* @param set true to enable mimicing.
*/
public void setBackgroundSlave(boolean set) {
backgroundSlave = set;
}
/**
* Get whether the map's background mimics changes to the source map's
* background.
*/
public boolean getBackgroundSlave() {
return backgroundSlave;
}
/**
* Default value of this property is true. if you want your sourceMap to be
* controlled by this OverviewMapHandler, set the value of this property for
* this OverviewHandler. This will allow, for instance, clicking on the
* overview map to recenter the source map. That depends on the overview map
* mouse mode, however.
*
* @param value
*/
public void setControlSourceMap(boolean value) {
if (sourceMap != null) {
if (value == true && controlSourceMap == false) {
addControlledMap(sourceMap);
}
if (value == false && controlSourceMap == true) {
removeControlledMap(sourceMap);
}
}
controlSourceMap = value;
}
public boolean getControlSourceMap() {
return controlSourceMap;
}
/**
* Set the layers in the Overview MapBean. An AreaLayer is automatically
* added on top.
*/
public void setLayers(Layer[] layers) {
map.setLayers(new LayerEvent(this, LayerEvent.REPLACE, new Layer[0]));
if (statusLayer != null) {
map.add(statusLayer);
}
map.setLayers(new LayerEvent(this, LayerEvent.ADD, layers));
}
/**
* Part of the ProjectionListener interface. The new projections from the
* source MapBean arrive here.
*
* @param projEvent the projection event from the source MapBean.
*/
public void projectionChanged(ProjectionEvent projEvent) {
if (sourceMap == null) {
sourceMap = (MapBean) projEvent.getSource();
map.setBckgrnd(sourceMap.getBckgrnd());
}
Projection proj = projEvent.getProjection();
if (proj == null) {
return;
}
if (statusLayer != null
&& statusLayer instanceof OverviewMapStatusListener) {
((OverviewMapStatusListener) statusLayer).setSourceMapProjection(proj);
}
float newScale = proj.getScale() * scaleFactor;
// Adjust the newScale based on the ratio of the
// source projection width and the overview
// map projection width.
Projection sourceProj = sourceMap.getProjection();
newScale *= (float) sourceProj.getWidth()
/ (float) projection.getWidth();
if (newScale < minScale) {
newScale = minScale;
}
if (projection != null) {
projection.setScale(newScale);
projection.setCenter(proj.getCenter());
map.setProjection(projection);
}
}
/**
* Set the MapMouseMode for the overview map. If you want the status layer
* to listen to the mouse mode, you have to get the layer and wire it up
* yourself.
*/
public void setMouseMode(MapMouseMode ammm) {
// If we're removing a mouse mode, disconnect it from the map.
if (ammm == null) {
deactivateMouseMode();
}
mmm = ammm;
activateMouseMode();
}
/**
* Get the MapMouseMode used for the overview map.
*/
public MapMouseMode getMouseMode() {
return mmm;
}
/**
* Adds the mouse mode as a listener to the overview map. If the mouse mode
* is null, the default is created.
*/
public void activateMouseMode() {
if (mmm == null) {
mmm = new DefaultOverviewMouseMode(this);
}
if (map != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -