📄 annotations.java
字号:
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_VLINEAR, new Dimension(32, 64), 1f, Color.LIGHT_GRAY, Color.WHITE)); // gray/white
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(10, 120, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.PATTERN_DIAGONAL_UP, Color.YELLOW)); // yellow stripes
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(0, 100, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_HLINEAR, new Dimension(256, 32), 1f, Color.WHITE, new Color(0f, 0f, 0f, 0f))); // White to transparent
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(0, 110, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_HLINEAR, new Dimension(32, 64), 1f, Color.LIGHT_GRAY, Color.WHITE)); // gray/white
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(0, 120, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.PATTERN_SQUARES, Color.YELLOW)); // yellow circles
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(-10, 100, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_HLINEAR, new Dimension(16, 16), 1f, Color.BLACK, Color.WHITE)); // Black to white
ga.getAttributes().setImageRepeat(Annotation.IMAGE_REPEAT_Y);
ga.getAttributes().setBackgroundColor(Color.WHITE);
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(-10, 110, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.GRADIENT_VLINEAR, new Dimension(16, 16), 1f, Color.BLACK, Color.WHITE)); // Black to white
ga.getAttributes().setImageRepeat(Annotation.IMAGE_REPEAT_X);
ga.getAttributes().setBackgroundColor(Color.WHITE);
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
ga = new GlobeAnnotation("Background patterns...", Position.fromDegrees(-10, 120, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.PATTERN_HVLINE, .15f, Color.GREEN)); // green + lines
ga.getAttributes().setImageScale(.4);
ga.getAttributes().setSize(new Dimension(200, 128));
layer.addAnnotation(ga);
// Shows pattern scale effect on circles pattern
for (int i = 1; i <= 10; i++)
{
ga = new GlobeAnnotation("Pattern scale:" + (float)i / 10, Position.fromDegrees(-20, 97 + i * 3, 0), patternAttr);
ga.getAttributes().setImageSource(PatternFactory.createPattern(PatternFactory.PATTERN_CIRCLES, (float)i / 10, Color.LIGHT_GRAY));
ga.getAttributes().setImageScale(.4);
ga.getAttributes().setSize(new Dimension(160, 60));
layer.addAnnotation(ga);
}
// Using a GlobeAnnotation subclass to override drawing
class SimpleGlobeAnnotation extends GlobeAnnotation
{
Font font = Font.decode("Arial-PLAIN-12");
public SimpleGlobeAnnotation(String text, Position position)
{
super(text, position);
}
protected void applyScreenTransform(DrawContext dc, int x, int y, int width, int height, double scale)
{
GL gl = dc.getGL();
gl.glTranslated(x, y, 0);
gl.glScaled(scale, scale, 1);
}
protected void doDraw(DrawContext dc, int width, int height, double opacity, Position pickPosition)
{
if (dc.isPickingMode())
return;
TextRenderer textRenderer = this.getTextRenderer(dc, this.font);
// Draw text centered just above the screen point - use annotation's colors
String text = getText().split("\n")[0]; // First line only
int textWidth = (int) textRenderer.getBounds(text).getWidth();
Color textColor = this.modulateColorOpacity(this.getAttributes().getTextColor(), opacity);
Color backColor = this.modulateColorOpacity(this.getAttributes().getBackgroundColor(), opacity);
textRenderer.begin3DRendering();
textRenderer.setColor(backColor);
textRenderer.draw(text, - textWidth / 2 + 1, 12 - 1); // Background 'shadow'
textRenderer.setColor(textColor);
textRenderer.draw(text, - textWidth / 2, 12); // Foreground text
textRenderer.end3DRendering();
// Draw little square around screen point - use annotation's color
Color borderColor = this.getAttributes().getBorderColor();
setDrawColor(dc, borderColor, opacity, OGLStateSupport.COLOR_NO_PREMULTIPLIED_ALPHA);
// Draw 3x3 shape from its bottom left corner
GL gl = dc.getGL();
gl.glDisable(GL.GL_LINE_SMOOTH);
gl.glDisable(GL.GL_LINE_STIPPLE);
gl.glLineWidth(1);
dc.getGL().glTranslated(-1, -1, 0);
FrameFactory.drawShape(dc, FrameFactory.SHAPE_RECTANGLE, 3, 3, GL.GL_LINE_STRIP, 0);
}
}
ga = new SimpleGlobeAnnotation("Mount Rainier\nAlt: 4392m", Position.fromDegrees(46.8534, -121.7609, 0));
layer.addAnnotation(ga);
ga = new SimpleGlobeAnnotation("Mount Adams\nAlt: 3742m", Position.fromDegrees(46.2018, -121.4931, 0));
layer.addAnnotation(ga);
ga = new SimpleGlobeAnnotation("Mount Saint Helens\nAlt: 4392m", Position.fromDegrees(46.1991, -122.1882, 0));
layer.addAnnotation(ga);
// Using an anonymous subclass to change annotation text on the fly
ga = new GlobeAnnotation("DRAG ME!", Position.fromDegrees(42, -118, 0), Font.decode("Arial-BOLD-18"))
{
public void doDraw(DrawContext dc, int width, int height, double opacity, Position pickPosition)
{
// if annotation has moved, set its text
if(getPosition().getLatitude().degrees != 42 || getPosition().getLongitude().degrees != -118)
setText(String.format("Lat %7.4f\u00B0\nLon %7.4f\u00B0", getPosition().getLatitude().degrees, getPosition().getLongitude().degrees));
// Keep rendering
super.doDraw(dc, width, height, opacity, pickPosition);
}
};
layer.addAnnotation(ga);
// Using post drawing code in an anonymous subclass
ga = new GlobeAnnotation("Annotation with extra frames drawn by a render delegate.", Position.fromDegrees(40, -116, 0), Font.decode("Serif-BOLD-18"), Color.DARK_GRAY)
{
public void doDraw(DrawContext dc, int width, int height, double opacity, Position pickPosition)
{
// Let normal rendering happen
super.doDraw(dc, width, height, opacity, pickPosition);
java.awt.Rectangle insetBounds = this.computeInsetBounds(width, height);
java.awt.Rectangle freeBounds = this.computeFreeBounds(dc, width, height);
// Draw second light gray frame outside draw rectangle
// Refers to scaleFactor, alphaFactor, drawRectangle and freeRectangle which have been
// set during drawing.
setDrawColor(dc, Color.BLACK, 0.5 * opacity, OGLStateSupport.COLOR_PREMULTIPLIED_ALPHA);
// Translate to draw area bottom left corner, 3 pixels outside
dc.getGL().glTranslated(insetBounds.x - 3, insetBounds.y - 3, 0);
FrameFactory.drawShape(dc, FrameFactory.SHAPE_RECTANGLE, insetBounds.width + 6, insetBounds.height + 6, GL.GL_LINE_STRIP, 4);
// Draw another frame in the free space if any
if(freeBounds.height > 0)
{
dc.getGL().glTranslated(+3, +3, 0);
FrameFactory.drawShape(dc, FrameFactory.SHAPE_ELLIPSE, freeBounds.width, freeBounds.height, GL.GL_TRIANGLE_FAN, 0);
}
}
};
ga.getAttributes().setTextAlign(MultiLineTextRenderer.ALIGN_CENTER);
ga.getAttributes().setBackgroundColor(new Color(1f, 1f, 1f, .7f));
ga.getAttributes().setBorderColor(Color.BLACK);
ga.getAttributes().setSize(new Dimension(160, 200));
layer.addAnnotation(ga);
// Using a ScreenAnnotation
ScreenAnnotation sa = new ScreenAnnotation("Fixed position annotation", new Point(20, 20));
sa.getAttributes().setDefaults(defaultAttributes);
sa.getAttributes().setCornerRadius(0);
sa.getAttributes().setSize(new Dimension(200, 0));
sa.getAttributes().setAdjustWidthToText(Annotation.SIZE_FIXED); // use strict dimension width - 200
sa.getAttributes().setDrawOffset(new Point(100, 0)); // screen point is annotation bottom left corner
sa.getAttributes().setHighlightScale(1); // No highlighting either
layer.addAnnotation(sa);
// Add layer to the layer list and update the layer panel
insertBeforeCompass(this.getWwd(), layer);
getLayerPanel().update(getWwd());
// Add control panel
this.getLayerPanel().add(makeControlPanel(), BorderLayout.SOUTH);
// Test save as kml placemarks
//save();
// Add a select listener to select or highlight annotations on rollover
this.getWwd().addSelectListener(new SelectListener()
{
private BasicDragger dragger = new BasicDragger(getWwd());
public void selected(SelectEvent event)
{
if (event.hasObjects() && event.getTopObject() instanceof Annotation)
{
// Handle cursor change on hyperlink
if (event.getTopPickedObject().getValue(AVKey.URL) != null)
getWwd().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
else
getWwd().setCursor(Cursor.getDefaultCursor());
}
// Select/unselect on left click on annotations
if (event.getEventAction().equals(SelectEvent.LEFT_CLICK))
{
if (event.hasObjects())
{
if (event.getTopObject() instanceof Annotation)
{
// Check for text or url
PickedObject po = event.getTopPickedObject();
if(po.getValue(AVKey.TEXT) != null)
{
System.out.println("Text: \"" + po.getValue(AVKey.TEXT) + "\" Hyperlink: " + po.getValue(AVKey.URL));
if (po.getValue(AVKey.URL) != null)
{
// Try to launch a browser with the clicked URL
try
{
BrowserOpener.browse(new URL((String)po.getValue(AVKey.URL)));
}
catch (Exception ignore) {}
}
if(AppFrame.this.currentAnnotation == event.getTopObject())
return;
}
// Left click on an annotation - select
if(AppFrame.this.currentAnnotation != null)
{
// Unselect current
//AppFrame.this.currentAnnotation.getAttributes().setHighlighted(false);
AppFrame.this.currentAnnotation.getAttributes().setBorderColor(AppFrame.this.savedBorderColor);
}
if(AppFrame.this.currentAnnotation != event.getTopObject())
{
// Select new one if not current one already
AppFrame.this.currentAnnotation = (Annotation)event.getTopObject();
//AppFrame.this.currentAnnotation.getAttributes().setHighlighted(true);
AppFrame.this.savedBorderColor = AppFrame.this.currentAnnotation.getAttributes().getBorderColor();
AppFrame.this.savedImage = AppFrame.this.currentAnnotation.getAttributes()
.getImageSource() instanceof BufferedImage ?
(BufferedImage)AppFrame.this.currentAnnotation.getAttributes().getImageSource() : null;
AppFrame.this.currentAnnotation.getAttributes().setBorderColor(Color.YELLOW);
}
else
{
// Clear current annotation
AppFrame.this.currentAnnotation = null; // switch off
}
// Update control panel
AppFrame.this.updateControlPanel();
}
else
System.out.println("Left click on " + event.getTopObject());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -