1

This is not coming out correct for me. Setting the zoom level based on some other code I got on here using the EarthFlat model, which does not set the correct zoom for the placemarks within a sector bounds.

private void invoke() {
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {

            ArrayList<Position> pos = new ArrayList<Position>();
            pos.add(Position.fromDegrees(32, -117));
            pos.add(Position.fromDegrees(48, -72));
            pos.add(Position.fromDegrees(40, -70));

            final Sector bounds = Sector.boundingSector(pos);

            setWwPanel(new WWPanel());
            final WWPanel wwPanel = getWwPanel();
            wwPanel.setPreferredSize(new Dimension((int) getSize().getWidth(), (int) getSize().getHeight()));
            wwPanel.getWwd().addGLEventListener(new GLEventListener() {

                public void display(GLAutoDrawable e) {
                    //System.out.println("Map displayed");
                }

                public void dispose(GLAutoDrawable e) {
                    System.out.println("Map disposed");
                }

                public void init(GLAutoDrawable e) {
                    System.out.println("Map GL initialized");
                }

                public void reshape(GLAutoDrawable e, int arg1,
                        int arg2, int arg3, int arg4) {
                    System.out.println("Map reshaped");
                }

            });

            LayerList layerList = new LayerList();
            BMNGWMSLayer bmng = new BMNGWMSLayer();
            layerList.add(bmng);
            ViewControlsLayer vcl = new ViewControlsLayer();
            vcl.setShowPitchControls(false);
            vcl.setShowVeControls(false);
            vcl.setShowHeadingControls(false);
            layerList.add(vcl);
            Model flatModel = new BasicModel(new EarthFlat(), layerList);
            ((EarthFlat) flatModel.getGlobe()).setProjection(FlatGlobe.PROJECTION_MERCATOR);
            wwPanel.getWwd().setModel(flatModel);
            wwPanel.getWwd().addSelectListener(new ViewControlsSelectListener(wwPanel.getWwd(), vcl));

            RenderableLayer rl = new RenderableLayer();
            for(Position curPos : pos) {
                PointPlacemark pm = new PointPlacemark(curPos);
                pm.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND);
                pm.setLabelText("Test");
                PointPlacemarkAttributes pma = new PointPlacemarkAttributes();

                pma.setImageColor(Color.GREEN);
                pma.setLabelFont(Font.decode("Verdana-Bold-11"));
                pma.setLabelMaterial(Material.GREEN);
                pm.setAttributes(pma);
                pm.setValue(AVKey.DISPLAY_NAME, "Text displayed on mouse over");

                rl.addRenderable(pm);
            }

            layerList.add(rl);

            BasicOrbitView fov = (BasicOrbitView) wwPanel.getWwd().getView();
            fov.setCenterPosition(Position.fromDegrees(bounds.getCentroid().getLatitude().degrees, bounds.getCentroid().getLongitude().degrees));

// this is what i am using to set zoom ??????
            double radius = wwPanel.getWwd().getModel().getExtent().getRadius();
            double viewRange = Math.sqrt(Math.pow(bounds.getMaxLatitude().degrees-bounds.getMinLatitude().degrees, 2)+Math.pow(bounds.getMaxLongitude().degrees-bounds.getMinLongitude().degrees, 2));
            double altitude = radius * Math.sin(Math.toRadians(viewRange * 0.5));

            fov.setZoom(altitude);

            add(getWwPanel(), BorderLayout.CENTER);
        }

    });
}

It sets the zoom fine, but the placemarks are off the view bounds.

Expected result:

enter image description here

Undesired/actual result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.