我使用WorldWind並試圖「挑選」同一圖層中的多個表面圖像,並不理解它爲什麼不起作用。Worldwind SurfaceImage Deep/Batch Clicking
我的印象是,調用該:
this.getWwd().getSceneController().setDeepPickEnabled(true);
將使我能夠選擇多個renderables在同一層。這似乎適用於除SurfaceImage以外的其他所有情況。我還注意到,如果我強制加載的SurfaceImage到不同的層,它按預期工作。
這是我使用測試了這一點代碼:
public class SurfaceImageViewer extends ApplicationTemplate
{
public static class AppFrame extends ApplicationTemplate.AppFrame
{
private JFileChooser fileChooser = new JFileChooser();
private JSlider opacitySlider;
private SurfaceImageLayer layer;
private JLabel statusLabel = new JLabel("status: ready");
public AppFrame()
{
super(true, true, false);
this.getWwd().getSceneController().setDeepPickEnabled(true);
try
{
this.layer = new SurfaceImageLayer();
this.layer.setOpacity(1);
this.layer.setPickEnabled(true);
this.layer.setName("Surface Images");
insertBeforeCompass(this.getWwd(), layer);
this.getControlPanel().add(makeControlPanel(), BorderLayout.SOUTH);
}
catch (Exception e)
{
e.printStackTrace();
}
this.getWwd().addSelectListener(new SelectListener() {
@Override
public void selected(SelectEvent event) {
PickedObjectList pol = AppFrame.this.getWwd().getObjectsAtCurrentPosition();
if(event.isLeftClick()){
System.out.println("POL SIZE "+pol.size());
}
}
});
}
Action openElevationsAction = new AbstractAction("Open Elevation File...")
{
public void actionPerformed(ActionEvent e)
{
int status = fileChooser.showOpenDialog(AppFrame.this);
if (status != JFileChooser.APPROVE_OPTION)
return;
final File imageFile = fileChooser.getSelectedFile();
if (imageFile == null)
return;
Thread t = new Thread(new Runnable()
{
public void run()
{
try
{
CompoundElevationModel cem
= (CompoundElevationModel) getWwd().getModel().getGlobe().getElevationModel();
LocalElevationModel em = new LocalElevationModel();
em.addElevations(imageFile.getPath());
cem.addElevationModel(em);
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
});
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
};
Action openImageAction = new AbstractAction("Open Image File...")
{
public void actionPerformed(ActionEvent actionEvent)
{
int status = fileChooser.showOpenDialog(AppFrame.this);
if (status != JFileChooser.APPROVE_OPTION)
return;
final File imageFile = fileChooser.getSelectedFile();
if (imageFile == null)
return;
Thread t = new Thread(new Runnable()
{
public void run()
{
try
{
statusLabel.setText("status: Loading image");
// TODO: proper threading
layer.addImage(imageFile.getAbsolutePath());
getWwd().redraw();
statusLabel.setText("status: ready");
}
catch (IOException e)
{
e.printStackTrace();
}
}
});
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
};
private JPanel makeControlPanel()
{
JPanel controlPanel = new JPanel(new GridLayout(0, 1, 5, 5));
JButton openImageButton = new JButton(openImageAction);
controlPanel.add(openImageButton);
this.opacitySlider = new JSlider();
this.opacitySlider.setMaximum(100);
this.opacitySlider.setValue((int) (layer.getOpacity() * 100));
this.opacitySlider.setEnabled(true);
this.opacitySlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
int value = opacitySlider.getValue();
layer.setOpacity(value/100d);
getWwd().redraw();
}
});
JPanel opacityPanel = new JPanel(new BorderLayout(5, 5));
opacityPanel.setBorder(new EmptyBorder(0, 10, 0, 0));
opacityPanel.add(new JLabel("Opacity"), BorderLayout.WEST);
opacityPanel.add(this.opacitySlider, BorderLayout.CENTER);
controlPanel.add(opacityPanel);
JButton openElevationsButton = new JButton(openElevationsAction);
controlPanel.add(openElevationsButton);
controlPanel.add(statusLabel);
controlPanel.setBorder(new EmptyBorder(15, 15, 15, 15));
return controlPanel;
}
}
public static void main(String[] args)
{
ApplicationTemplate.start("World Wind Surface Images", SurfaceImageViewer.AppFrame.class);
}
}
這些都是對對方說我一直在使用測試了這一點的上面一層2個geotiffs。我希望我在SelectListener上的println打印出「3」,當我單擊鼠標左鍵單擊這兩個geotiff時。 (我已上載的geotiffs成可用here一個zip)
在那裏你會看到這些是在舊金山的區域,見截圖:
感謝您的關注 - 不幸的是,它看起來像SurfaceImage導入程序使用gov.nasa.worldwind.render.SurfaceImage作爲其可渲染且SurfaceImage不擴展gov.nasa.worldwind.render.AbstractSurfaceObject。看起來像SurfaceImage被視爲一種特殊情況或什麼時候涉及到批量/深度採摘,但我沒有看到問題在哪裏破解。 – systemoutprintln
感謝您取回AbstractSurfaceObject結果!如果您調試RenderableLayer內部的PickSupport引用,是否會找到光標下的所有SurfaceImages?您可能會在輸出中看到「TopPickedObject」,但PickSupport會保存要從該圖層中選擇的所有有效對象的地圖。如果它知道surfaceImage實例,那麼也許可以調整該類如何返回到SceneController。 – Jeremiah
有趣的想法。我會深入挖掘PickSupport,看看能否找到失去參考的地方。 – systemoutprintln