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

📄 surfaceobjects.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            ga.getAttributes().setImageRepeat(Annotation.IMAGE_REPEAT_NONE);
            ga.getAttributes().setImageOpacity(.6);
            ga.getAttributes().setImageScale(.7);
            ga.getAttributes().setImageOffset(new Point(12, 12));
            ga.getAttributes().setInsets(new Insets(12, 20, 20, 12));
            layer.addRenderable(ga);


            // Surface icons
            SurfaceIcon icon;
            icon = new SurfaceIcon("images/notched-compass.png", LatLon.fromDegrees(45, -112));
            icon.setOpacity(.5);
            icon.setScale(.5);
            icon.setMaxSize(50e3);
            //icon.setLocationOffset(new Vec4(0, -128, 0)); // gets the compass to rotate around it's needle tip.
            //layer.addRenderable(icon);

            // Marker with surface icon
            Position position = Position.fromDegrees(47.74, -123.44, 0);
            MarkerAttributes ma = new BasicMarkerAttributes();
            ma.setMaxMarkerSize(10e3);
            ma.setMinMarkerSize(10);
            ma.setMaterial(Material.RED);
            CustomMarker marker = new CustomMarker(position, ma, icon);
            marker.setHeading(Angle.ZERO);
            layer.addRenderable(marker);

            return layer;
        }

        private class CustomMarker extends BasicMarker implements PreRenderable, Renderable, Movable
        {
            private ArrayList<Marker> markerList;
            private MarkerRenderer markerRenderer;
            private SurfaceIcon headingIcon;
            private SurfaceIcon highlightIcon;
            private PickSupport pickSupport = new PickSupport();
            private SurfaceTrail trail = new SurfaceTrail();
            private Material savedMaterial;

            public CustomMarker(Position position, MarkerAttributes attrs, SurfaceIcon headingIcon)
            {
                super(position, attrs);

                this.headingIcon = headingIcon;
                this.headingIcon.setLocation(position);

                BufferedImage image = PatternFactory.createPattern(PatternFactory.PATTERN_CIRCLE, .9f, Color.RED);
                image = PatternFactory.blur(PatternFactory.blur(image, 5));
                this.highlightIcon = new SurfaceIcon(image, position);
                this.highlightIcon.setOpacity(.5);
                this.highlightIcon.setScale(3);
                this.highlightIcon.setVisible(false);
            }

            public void setHighlighted(boolean state)
            {
                if (this.highlightIcon.isVisible() == state)
                    return;

                this.highlightIcon.setVisible(state);
                if (this.highlightIcon.isVisible())
                {
                    this.savedMaterial = this.getAttributes().getMaterial();
                    this.getAttributes().setMaterial(Material.RED);
                }
                else
                    this.getAttributes().setMaterial(this.savedMaterial);
            }

            public void preRender(DrawContext dc)
            {
                this.trail.preRender(dc);
                this.headingIcon.setHeading(this.getHeading());
                this.headingIcon.preRender(dc);
                this.highlightIcon.preRender(dc);
            }

            public void render(DrawContext dc)
            {
                if (this.markerList == null)
                {
                    this.markerList = new ArrayList<Marker>();
                    this.markerList.add(this);
                }
                if (this.markerRenderer == null)
                {
                    this.markerRenderer = new MarkerRenderer();
                    this.markerRenderer.setOverrideMarkerElevation(true);
                    this.markerRenderer.setElevation(0);
                }

                if (dc.isPickingMode())
                {
                    this.markerRenderer.pick(dc, this.markerList, dc.getPickPoint(), null);
                    // Separate pick color for the icon
                    this.pickSupport.clearPickList();
                    this.pickSupport.beginPicking(dc);
                    java.awt.Color color = dc.getUniquePickColor();
                    dc.getGL().glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
                    this.headingIcon.render(dc);
                    PickedObject po = new PickedObject(color.getRGB(), this);
                    po.setValue("Heading", true); // Attach heading key to picked object
                    this.pickSupport.addPickableObject(po);
                    this.pickSupport.endPicking(dc);
                    this.pickSupport.resolvePick(dc, dc.getPickPoint(), null);
                }
                else
                {
                    this.trail.render(dc);
                    this.markerRenderer.render(dc, this.markerList);
                    this.headingIcon.render(dc);
                    this.highlightIcon.render(dc);
                }

            }

            public Position getReferencePosition()
            {
                return this.getPosition();
            }

            public void move(Position delta)
            {
                this.moveTo(this.getReferencePosition().add(delta));
            }

            public void moveTo(Position position)
            {
                // Add current position to the trail
                this.trail.add(this.getReferencePosition());
                // Have the marker point in the move direction
                Angle heading = LatLon.greatCircleAzimuth(this.getReferencePosition(), position);
                this.setHeading(heading);
                // Update positions
                this.headingIcon.setLocation(position);
                this.highlightIcon.setLocation(position);
                this.setPosition(position);
            }
        }

        private class SurfaceTrail implements PreRenderable, Renderable
        {
            private int MAX_SIZE = 30;
            private ArrayList<SurfaceIcon> locations = new ArrayList<SurfaceIcon>();
            private TiledSurfaceObjectRenderer renderer = new TiledSurfaceObjectRenderer();

            public void add(LatLon location)
            {
                // Add shape
                BufferedImage imageSource = PatternFactory.createPattern(PatternFactory.PATTERN_CIRCLE, .9f, Color.BLACK);
                SurfaceIcon icon = new SurfaceIcon(imageSource, location);
                icon.setScale(.5);
                this.locations.add(icon);
                if (this.locations.size() > MAX_SIZE)
                    this.locations.remove(0);
                this.renderer.setSurfaceObjects(this.locations);
                // Fade out
                for (int i = 0; i < this.locations.size(); i++)
                    this.locations.get(i).setOpacity(1d - (double)(this.locations.size() - i - 1) / MAX_SIZE);
            }

            public void preRender(DrawContext dc)
            {
                this.renderer.preRender(dc);
            }

            public void render(DrawContext dc)
            {
                this.renderer.render(dc);
            }
        }

    }

    public static void main(String[] args)
    {
        // Set up view initial state
        Configuration.setValue(AVKey.INITIAL_LATITUDE, 47.15);
        Configuration.setValue(AVKey.INITIAL_LONGITUDE, -122.74);
        Configuration.setValue(AVKey.INITIAL_ALTITUDE, 300e3);
        Configuration.setValue(AVKey.INITIAL_PITCH, 60);
        Configuration.setValue(AVKey.INITIAL_HEADING, 155);
        
        ApplicationTemplate.start("World Wind Surface Objects", AppFrame.class);
    }
}

⌨️ 快捷键说明

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