首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WorldWind Java中闪烁的注释

WorldWind Java中闪烁的注释
EN

Stack Overflow用户
提问于 2017-10-05 20:23:15
回答 1查看 460关注 0票数 1

我正试图在NASA Worldwind for Java中实现我自己的杂波过滤器,这导致了一个奇怪的问题--杂波过滤器还没做什么,但当我通过“闪烁”问题时,我会用它来移动东西。每当移动鼠标时,GlobeAnnotation可呈现性就会闪烁。当我将杂波滤波器设置为null时,闪烁似乎不会发生。

这里有一个GIF,它展示了我的意思:https://media.giphy.com/media/xT9IgFiZwYZ3VJHQU8/giphy.gif

我从这里克隆了美国宇航局的世界风代码:https://github.com/NASAWorldWind/WorldWindJava。我已经做了一些改变,让事情为我的最终过滤器工作。一个注意事项是,我希望GlobeAnnotations像往常一样出现在其他所有事物的顶端。

我怎样才能让GlobeAnnotations不互相争斗和闪烁,但仍然出现在其他东西之上--同时打开杂波过滤器?

请注意,下面的代码只是我放在一起的一个示例,显示了我在我的“真实”应用程序中看到的问题。我希望GlobeAnnotations永远在其他一切之上--但不要闪烁和相互争斗。

这是我的测试驱动程序:

代码语言:javascript
复制
package gov.nasa.worldwindx.examples;

import java.awt.Color;

import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layers.AnnotationLayer;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.render.GlobeAnnotation;
import gov.nasa.worldwind.render.Material;
import gov.nasa.worldwind.render.airspaces.CappedCylinder;

public class FlashyAnnotations extends ApplicationTemplate {
    @SuppressWarnings("unchecked")
    private static class AppFrame extends ApplicationTemplate.AppFrame {

        private AnnotationLayer layer;

        public AppFrame() {

            this.getWwd().getSceneController().setClutterFilter(new SimpleClutterFilter());

            CappedCylinder cappedCyl = new CappedCylinder(LatLon.fromDegrees(27, -100), 3000000);
            cappedCyl.getAttributes().setDrawInterior(true);
            cappedCyl.getAttributes().setInteriorMaterial(Material.GREEN);
            cappedCyl.getAttributes().setInteriorOpacity(.75f);
            cappedCyl.setAltitudes(10, 100000);
            RenderableLayer renderLayer = new RenderableLayer();

            renderLayer.addRenderable(cappedCyl);
            insertBeforeCompass(this.getWwd(), renderLayer);

            // Create example annotations
            this.setupAnnotations();

        }

        private void setupAnnotations() {

            // Create an AnnotationLayer with lots of annotations
            this.layer = new AnnotationLayer();

            GlobeAnnotation ga = new GlobeAnnotation("Annotation", Position.fromDegrees(20, -100.9, 1000));
            ga.getAttributes().setTextColor(Color.white);
            ga.getAttributes().setBackgroundColor(Color.BLACK);
            ga.getAttributes().setOpacity(.75f);
            ga.setAlwaysOnTop(true);
            layer.addAnnotation(ga);

            ga = new GlobeAnnotation("Annotation", Position.fromDegrees(25, -100.9, 1000));
            ga.getAttributes().setTextColor(Color.white);
            ga.getAttributes().setBackgroundColor(Color.BLACK);
            ga.getAttributes().setOpacity(.75f);
            ga.setAlwaysOnTop(true);
            layer.addAnnotation(ga);

            // Add layer to the layer list and update the layer panel
            insertBeforeCompass(this.getWwd(), layer);
        }

    }

    public static void main(String[] args) {
        ApplicationTemplate.start("WorldWind Annotations", AppFrame.class);
    }
}

下面是我的(本质上是不操作的)杂波过滤器:

代码语言:javascript
复制
package gov.nasa.worldwindx.examples;

import java.util.List;

import gov.nasa.worldwind.render.Declutterable;
import gov.nasa.worldwind.render.DrawContext;
import gov.nasa.worldwind.util.ClutterFilter;

public class SimpleClutterFilter implements ClutterFilter{

    @Override
    public void apply(DrawContext dc, List<Declutterable> shapes) {
        for(Declutterable shape: shapes) {
            dc.addOrderedRenderable(shape);
        }

    }

}

我还必须更新gov.nasa.worldwind.render.BasicAnnotationRenderer,使其创建的OrderedAnnotations实现Declutterable。(对这个内部类的唯一更改是添加isEnableDecluttering和getBounds):

代码语言:javascript
复制
public class OrderedAnnotation implements OrderedRenderable, Declutterable
{
protected Annotation annotation;


protected double eyeDistance;
protected Layer layer;

public OrderedAnnotation(Annotation annotation, double eyeDistance)
{
    this.annotation = annotation;
    this.eyeDistance = eyeDistance;
}

public OrderedAnnotation(Annotation annotation, Layer layer, double eyeDistance)
{
    this.annotation = annotation;
    this.eyeDistance = eyeDistance;
    this.layer = layer;
}

public double getDistanceFromEye()
{
    return this.eyeDistance;
}

public void render(DrawContext dc)
{
    OGLStackHandler stackHandler = new OGLStackHandler();
    BasicAnnotationRenderer.this.beginDrawAnnotations(dc, stackHandler);
    try
    {
        this.doRender(dc, this);
        // Draw as many as we can in a batch to save ogl state switching.
        while (dc.peekOrderedRenderables() instanceof OrderedAnnotation)
        {
            OrderedAnnotation oa = (OrderedAnnotation) dc.pollOrderedRenderables();
            this.doRender(dc, oa);
        }
    }
    catch (WWRuntimeException e)
    {
        Logging.logger().log(Level.SEVERE, "generic.ExceptionWhileRenderingAnnotation", e);
    }
    catch (Exception e)
    {
        Logging.logger().log(Level.SEVERE, "generic.ExceptionWhileRenderingAnnotation", e);
    }
    finally
    {
        BasicAnnotationRenderer.this.endDrawAnnotations(dc, stackHandler);
    }
}

public void pick(DrawContext dc, java.awt.Point pickPoint)
{
    OGLStackHandler stackHandler = new OGLStackHandler();
    BasicAnnotationRenderer.this.pickSupport.clearPickList();
    BasicAnnotationRenderer.this.beginDrawAnnotations(dc, stackHandler);
    try
    {
        this.annotation.setPickSupport(BasicAnnotationRenderer.this.pickSupport);
        this.doRender(dc, this);
        // Draw as many as we can in a batch to save ogl state switching.
        while (dc.peekOrderedRenderables() instanceof OrderedAnnotation)
        {
            OrderedAnnotation oa = (OrderedAnnotation) dc.pollOrderedRenderables();
            oa.annotation.setPickSupport(BasicAnnotationRenderer.this.pickSupport);
            this.doRender(dc, oa);
        }
    }
    catch (WWRuntimeException e)
    {
        Logging.logger().log(Level.SEVERE, "generic.ExceptionWhilePickingAnnotation", e);
    }
    catch (Exception e)
    {
        Logging.logger().log(Level.SEVERE, "generic.ExceptionWhilePickingAnnotation", e);
    }
    finally
    {
        BasicAnnotationRenderer.this.endDrawAnnotations(dc, stackHandler);
        BasicAnnotationRenderer.this.pickSupport.resolvePick(dc, pickPoint, this.layer);
        BasicAnnotationRenderer.this.pickSupport.clearPickList(); // to ensure entries can be garbage collected
    }
}

protected void doRender(DrawContext dc, OrderedAnnotation oa)
{
    // Swap the draw context's current layer with that of the ordered annotation
    Layer previousCurrentLayer = dc.getCurrentLayer();
    try
    {
        dc.setCurrentLayer(oa.layer);
        oa.annotation.renderNow(dc);
    }
    finally
    {
        dc.setCurrentLayer(previousCurrentLayer); // restore the original layer
    }
}

@Override
public boolean isEnableDecluttering() {
    return (annotation instanceof GlobeAnnotation);
}

@Override
public Rectangle2D getBounds(DrawContext dc) {
    if(annotation instanceof GlobeAnnotation) {
        return ((GlobeAnnotation) annotation).computeBounds(dc);
    }
    return null;
}

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-08 15:03:48

首先是;

Draw order of PointPlacemarks

https://forum.worldwindcentral.com/forum/world-wind-java-forums/development-help/13263-layer-priority-order

setupAnnotations方法中,为两个GlobeAnnotation对象设置alwaysOnTop为true。也许这就是原因。

代码语言:javascript
复制
private void setupAnnotations() {

            // Create an AnnotationLayer with lots of annotations
            this.layer = new AnnotationLayer();

            GlobeAnnotation ga = new GlobeAnnotation("Annotation", Position.fromDegrees(20, -100.9, 1000));
            ga.getAttributes().setTextColor(Color.white);
            ga.getAttributes().setBackgroundColor(Color.BLACK);
            ga.getAttributes().setOpacity(.75f);
            **ga.setAlwaysOnTop(true);**
            layer.addAnnotation(ga);

            ga = new GlobeAnnotation("Annotation", Position.fromDegrees(25, -100.9, 1000));
            ga.getAttributes().setTextColor(Color.white);
            ga.getAttributes().setBackgroundColor(Color.BLACK);
            ga.getAttributes().setOpacity(.75f);
            **ga.setAlwaysOnTop(true);**
            layer.addAnnotation(ga);

            // Add layer to the layer list and update the layer panel
            insertBeforeCompass(this.getWwd(), layer);
        }

相反,将您希望始终位于顶层的注释放在单独的层中,将其余的注释放到另一层中可能是通过使用上面的链接来解决的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46594214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档