⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draggingshapeswithgeometry.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*Copyright (C) 2001, 2006 United States Governmentas represented by the Administrator of theNational Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.examples;import gov.nasa.worldwind.event.*;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.layers.*;import gov.nasa.worldwind.pick.*;import gov.nasa.worldwind.render.*;import gov.nasa.worldwind.render.airspaces.*;import java.awt.*;import java.awt.font.*;import java.util.*;/** * @author tag * @version $Id: DraggingShapes.java 3209 2007-10-06 21:57:53Z tgaskins $ */public class DraggingShapesWithGeometry extends ApplicationTemplate{    private static class AppFrame extends ApplicationTemplate.AppFrame    {        public AppFrame()        {            super(true, true, true);            this.getWwd().getModel().setShowWireframeInterior(false);            this.getWwd().getModel().setShowWireframeExterior(false);            /* Shapes from the original "DraggingShapes" demo */            //insertBeforeCompass(this.getWwd(), this.buildShapesLayer());            //insertBeforeCompass(this.getWwd(), this.buildIconLayer());            /* Random circles, using original "SurfaceShape" classes */            //insertBeforeCompass(this.getWwd(), this.buildRandomCirclesLayer());            /* Random circles, using "SurfaceShapeGeometry" classes */            //insertBeforeCompass(this.getWwd(), this.buildRandomCirclesLayerSurfaceGeometry());            /* random circles using "PolyLine" generated borders and uniformly subdivided triangles */            //insertBeforeCompass(this.getWwd(), this.buildRandomCirclesLayerPolyArc());            /* random circles using geometry classes derived from AbstractAirspace */            //insertBeforeCompass(this.getWwd(), this.buildRandomEllipses(this.getWwd().getModel().getGlobe()));            /* random circles using SurfaceShapesLayer as a manager */            insertBeforeCompass(this.getWwd(), this.buildRandomCircleShapesLayer());            /* approximation of state of Wyoming, using SurfaceShapeGeometry (sanity check of area calc.) */            //insertBeforeCompass(this.getWwd(), this.buildWyomingLayer());            this.getLayerPanel().update(this.getWwd());            this.getWwd().addSelectListener(new SelectListener()            {                private WWIcon lastToolTipIcon = null;                private BasicDragger dragger = new BasicDragger(getWwd());                public void selected(SelectEvent event)                {                    // Have hover selections show a picked icon's tool tip.                    if (event.getEventAction().equals(SelectEvent.HOVER))                    {                        // If a tool tip is already showing, undisplay it.                        if (lastToolTipIcon != null)                        {                            lastToolTipIcon.setShowToolTip(false);                            this.lastToolTipIcon = null;                            AppFrame.this.getWwd().repaint();                        }                        // If there's a selection, we're not dragging, and the selection is an icon, show tool tip.                        if (event.hasObjects() && !this.dragger.isDragging())                        {                            if (event.getTopObject() instanceof WWIcon)                            {                                this.lastToolTipIcon = (WWIcon) event.getTopObject();                                lastToolTipIcon.setShowToolTip(true);                                AppFrame.this.getWwd().repaint();                            }                        }                    }                    // Have rollover events highlight the rolled-over object.                    else if (event.getEventAction().equals(SelectEvent.ROLLOVER) && !this.dragger.isDragging())                    {                        AppFrame.this.highlight(event.getTopObject());                    }                    // Have drag events drag the selected object.                    else if (event.getEventAction().equals(SelectEvent.DRAG_END)                        || event.getEventAction().equals(SelectEvent.DRAG))                    {                        // Delegate dragging computations to a dragger.                        this.dragger.selected(event);                        // We missed any roll-over events while dragging, so highlight any under the cursor now,                        // or de-highlight the dragged shape if it's no longer under the cursor.                        if (event.getEventAction().equals(SelectEvent.DRAG_END))                        {                            PickedObjectList pol = getWwd().getObjectsAtCurrentPosition();                            if (pol != null)                            {                                AppFrame.this.highlight(pol.getTopObject());                                AppFrame.this.getWwd().repaint();                            }                            Object obj = pol.getTopObject();                            if (obj instanceof SurfaceShapeGeometry)                                System.out.println("Area of the object is: " + ((SurfaceShapeGeometry)obj).getArea());                        }                    }                }            });        }        WWIcon lastPickedIcon;        private void highlight(Object o)        {            // Manage highlighting of icons.            if (this.lastPickedIcon == o)                return; // same thing selected            // Turn off highlight if on.            if (this.lastPickedIcon != null)            {                this.lastPickedIcon.setHighlighted(false);                this.lastPickedIcon = null;            }            // Turn on highlight if object selected.            if (o != null && o instanceof WWIcon)            {                this.lastPickedIcon = (WWIcon) o;                this.lastPickedIcon.setHighlighted(true);            }        }        private IconLayer buildIconLayer()         {             IconLayer layer = new IconLayer();             Font font = this.makeToolTipFont();             // Distribute little NASA icons around the equator. Put a few at non-zero altitude.             for (double lat = 0; lat < 10; lat += 10)             {                 for (double lon = -180; lon < 180; lon += 10)                 {                     double alt = 0;                     if (lon % 90 == 0)                         alt = 2000000;                     WWIcon icon = new UserFacingIcon("images/32x32-icon-nasa.png",                         new Position(Angle.fromDegrees(lat), Angle.fromDegrees(lon), alt));                     icon.setHighlightScale(1.5);                     icon.setToolTipFont(font);                     icon.setToolTipText(icon.getImageSource().toString());                     icon.setToolTipTextColor(Color.YELLOW);                     layer.addIcon(icon);                 }             }             return layer;         }        private AbstractLayer buildRandomCirclesLayer()         {             SurfaceShapeLayer layer = new SurfaceShapeLayer();           // Generate random numbers of circles over the US...            for (int i = 0; i < numCircles; i++) {                double lat = (25. + Math.random() * (50. - 25.));                double lon = -(64 + Math.random() * (125. - 64.));                double size = 100000. * Math.random();                SurfaceCircle surfaceCircle = new SurfaceCircle(LatLon.fromDegrees(lat, lon), size);                surfaceCircle.getAttributes().setInteriorMaterial(new Material(new Color(1f, 0.11f, 0.2f)));                surfaceCircle.getAttributes().setInteriorOpacity(0.6);                surfaceCircle.getAttributes().setOutlineMaterial(new Material(new Color(0f, 1f, 0f)));                surfaceCircle.getAttributes().setOutlineOpacity(0.6);                surfaceCircle.getAttributes().setOutlineWidth(3);                layer.addRenderable(surfaceCircle);            }            layer.setPickEnabled(true);             return layer;         }        private RenderableLayer buildRandomCirclesLayerSurfaceGeometry()         {             RenderableLayer layer = new RenderableLayer();           // Generate random numbers of circles over the US...            for (int i = 0; i < numCircles; i++) {                double lat = (25. + Math.random() * (50. - 25.));                double lon = -(64 + Math.random() * (125. - 64.));                double size = 100000. * Math.random();                SurfaceShapeGeometry surfaceCircleShape = new SurfaceCircleGeometry(getWwd().getModel().getGlobe(),                        LatLon.fromDegrees(lat, lon), size, 32,                        new Color(1f, 0.11f, 0.2f, 0.4f), new Color(0f, 1f, 0f, 0.6f));                surfaceCircleShape.setBorderWidth(2);                surfaceCircleShape.setDrawBorder(true);                surfaceCircleShape.setDrawInterior(true);                layer.addRenderable(surfaceCircleShape);            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -