Package org.locationtech.udig.project.internal.render

Examples of org.locationtech.udig.project.internal.render.ViewportModel


            }
        });
    }

    public void widgetSelected( SelectionEvent e ) {
        ViewportModel viewportModel = (ViewportModel) ApplicationGIS.getActiveMap().getViewportModel();

        Object source = e.getSource();
        if (source.equals(scaleCombo)) {
            int index = scaleCombo.getSelectionIndex();
            String item = scaleCombo.getItem(index);
            String scaleString = item.split(":")[1];
            double scale = Double.parseDouble(scaleString);
            viewportModel.setScale(scale);
        }
        if (source.equals(dateTimeCombo)) {
            int index = dateTimeCombo.getSelectionIndex();
            String item = dateTimeCombo.getItem(index);
            DateTime date = ISO_DATE_TIME_PARSER.parseDateTime(item);
            viewportModel.setCurrentTimestep(date);
        }
        if (source.equals(verticalCombo)) {
            int index = verticalCombo.getSelectionIndex();
            String item = verticalCombo.getItem(index);
            try {
                double vertical = Double.parseDouble(item);
                viewportModel.setCurrentElevation(vertical);
            } catch (NumberFormatException e1) {
                e1.printStackTrace();
            }
        }
        if (source.equals(verticalDownButton)) {
            int selectionIndex = verticalCombo.getSelectionIndex();
            selectionIndex++;
            if (selectionIndex > verticalCombo.getItemCount() - 1) {
                selectionIndex = verticalCombo.getItemCount() - 1;
            }
            String item = verticalCombo.getItem(selectionIndex);
            double vertical = Double.parseDouble(item);
            viewportModel.setCurrentElevation(vertical);
            verticalCombo.select(selectionIndex);
        }
        if (source.equals(verticalUpButton)) {
            int selectionIndex = verticalCombo.getSelectionIndex();
            selectionIndex--;
            if (selectionIndex < 0) {
                selectionIndex = 0;
            }
            String item = verticalCombo.getItem(selectionIndex);
            double vertical = Double.parseDouble(item);
            viewportModel.setCurrentElevation(vertical);
            verticalCombo.select(selectionIndex);
        }
        if (source.equals(scaleDownButton)) {
            int selectionIndex = scaleCombo.getSelectionIndex();
            selectionIndex--;
            if (selectionIndex < 0) {
                selectionIndex = 0;
            }
            String item = scaleCombo.getItem(selectionIndex);
            double scale = Double.parseDouble(item.split(":")[1]);
            viewportModel.setScale(scale);
            scaleCombo.select(selectionIndex);
        }
        if (source.equals(scaleUpButton)) {
            int selectionIndex = scaleCombo.getSelectionIndex();
            selectionIndex++;
            if (selectionIndex > scaleCombo.getItemCount() - 1) {
                selectionIndex = scaleCombo.getItemCount() - 1;
            }
            String item = scaleCombo.getItem(selectionIndex);
            double scale = Double.parseDouble(item.split(":")[1]);
            viewportModel.setScale(scale);
            scaleCombo.select(selectionIndex);
        }
        if (source.equals(dtDownButton)) {
            int selectionIndex = dateTimeCombo.getSelectionIndex();
            selectionIndex--;
            if (selectionIndex < 0) {
                selectionIndex = 0;
            }
            String item = dateTimeCombo.getItem(selectionIndex);
            DateTime dt = ISO_DATE_TIME_PARSER.parseDateTime(item);
            viewportModel.setCurrentTimestep(dt);
            dateTimeCombo.select(selectionIndex);
        }
        if (source.equals(dtUpButton)) {
            int selectionIndex = dateTimeCombo.getSelectionIndex();
            selectionIndex++;
            if (selectionIndex > dateTimeCombo.getItemCount() - 1) {
                selectionIndex = dateTimeCombo.getItemCount() - 1;
            }
            String item = dateTimeCombo.getItem(selectionIndex);
            DateTime dt = ISO_DATE_TIME_PARSER.parseDateTime(item);
            viewportModel.setCurrentTimestep(dt);
            dateTimeCombo.select(selectionIndex);
        }
        updateData();
    }
View Full Code Here


     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain basicSetViewportModelInternal(ViewportModel newViewportModelInternal,
            NotificationChain msgs) {
        ViewportModel oldViewportModelInternal = viewportModelInternal;
        viewportModelInternal = newViewportModelInternal;
        if (eNotificationRequired()) {
            ENotificationImpl notification = new ENotificationImpl(this, Notification.SET,
                    ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL, oldViewportModelInternal,
                    newViewportModelInternal);
View Full Code Here

                    .parseDouble(upperCorner[1]));
        } catch (Exception noBBox) {
            System.out.println("No BoundingBox" + boundingBox); //$NON-NLS-1$
        }
        if (env != null && crs != null) {
            ViewportModel viewportModel = map.getViewportModelInternal();
            viewportModel.setBounds(env);
            viewportModel.setCRS(crs);
        }
    }
View Full Code Here

   */
  @Ignore
  @Test
  public void testGetScaleDenominatorWGS84BoundsSmallerThanWorld() throws Exception {
    Map map = MapTests.createDefaultMap("test",4,true, new Dimension( 500,500 )); //$NON-NLS-1$
    ViewportModel viewportModel = map.getViewportModelInternal();
    viewportModel.setCRS(DefaultGeographicCRS.WGS84);
    viewportModel.setBounds(-20,20,-20,20);
    assertEquals(1.0d, viewportModel.getBounds().getWidth()/viewportModel.getHeight(), ACCURACY);
   
    assertEquals(calculateScale(viewportModel.getBounds(), viewportModel.getCRS(), 500,500),
        viewportModel.getScaleDenominator());
   
  }
View Full Code Here

   * Test method for 'org.locationtech.udig.project.internal.render.impl.ViewportModelImpl.getScaleDenominator()'
   */
    @Test
  public void testGetScaleDenominatorAlbersBoundsSmallerThanWorld() throws Exception {
    Map map = MapTests.createDefaultMap("test",4,true, new Dimension( 500,500 )); //$NON-NLS-1$
    ViewportModel viewportModel = map.getViewportModelInternal();
    viewportModel.setCRS(CRS.decode("EPSG:3005")); //$NON-NLS-1$
    viewportModel.setBounds(-140,-120,40,60);
    assertEquals(1.0d, viewportModel.getBounds().getWidth()/viewportModel.getHeight(), ACCURACY);
   
//    assertEquals(calculateScale(viewportModel.getBounds(), viewportModel.getCRS(), 500,500),
//        viewportModel.getScaleDenominator());
  }
View Full Code Here

   * Test method for 'org.locationtech.udig.project.internal.render.impl.ViewportModelImpl.getScaleDenominator()'
   */
    @Test
  public void testGetScaleDenominatorWGS84BoundsLongerThanWorldIn1Direction() throws Exception {
    Map map = MapTests.createDefaultMap("test",4,true, new Dimension( 500,500 )); //$NON-NLS-1$
    ViewportModel viewportModel = map.getViewportModelInternal();
    viewportModel.setCRS(DefaultGeographicCRS.WGS84);
    viewportModel.setBounds(-100,100,-100,100);
    assertEquals(1.0d, viewportModel.getBounds().getWidth()/viewportModel.getHeight(), ACCURACY);
   
    double trueScale = calculateScale(new Envelope(-180,-80, -90,10), viewportModel.getCRS(), 250,250);
    double viewportResults = viewportModel.getScaleDenominator();
    double d = Math.abs(trueScale-viewportResults);
  }
View Full Code Here

   * Test method for 'org.locationtech.udig.project.internal.render.impl.ViewportModelImpl.getScaleDenominator()'
   */
    @Test
  public void testGetScaleDenominatorWGS84BoundsLargerThanWorld() throws Exception {
    Map map = MapTests.createDefaultMap("test",4,true, new Dimension( 500,500 )); //$NON-NLS-1$
    ViewportModel viewportModel = map.getViewportModelInternal();
    viewportModel.setCRS(DefaultGeographicCRS.WGS84);
    viewportModel.setBounds(-180,320,-90,410);
    assertEquals(1.0d, viewportModel.getBounds().getWidth()/viewportModel.getHeight(), ACCURACY);
   
    double trueScale = calculateScale(new Envelope(-180,-80, -90,10), viewportModel.getCRS(), 100,100);
    double viewportResults = viewportModel.getScaleDenominator();
    double d = Math.abs(trueScale-viewportResults);
//    assertTrue(d+" should be less than "+ACCURACY_SCALE, d< ACCURACY_SCALE );     //$NON-NLS-1$
  }
View Full Code Here

   * Test method for 'org.locationtech.udig.project.internal.render.impl.ViewportModelImpl.getScaleDenominator()'
   */
    @Test
  public void testGetScaleDenominatorWGS84BoundsLargerThanWorldOffScreenData() throws Exception {
    Map map = MapTests.createDefaultMap("test",4,true, new Dimension( 500,500 )); //$NON-NLS-1$
    ViewportModel viewportModel = map.getViewportModelInternal();
    viewportModel.setCRS(DefaultGeographicCRS.WGS84);
    viewportModel.setBounds(500,500,1000,1000);
//    assertEquals(1.0d, viewportModel.getBounds().getWidth()/viewportModel.getHeight(), ACCURACY);
   
    double trueScale = calculateScale(new Envelope(-180,-80, -90,10), viewportModel.getCRS(), 100,100);
    double viewportResults = viewportModel.getScaleDenominator();
    double d = Math.abs(trueScale-viewportResults);
//    assertTrue(d+" should be less than "+ACCURACY_SCALE, d< ACCURACY_SCALE );     //$NON-NLS-1$
  }
View Full Code Here

     * Applies the supplied scale on the map on the current type of paper.
     *
     * @param scale the scale to apply to the map.
     */
    private void applyNewScale( double scale ) {
        ViewportModel viewportModel = getMapBoxPrinter().getMap().getViewportModelInternal();
        // get page size in pixels and in mm
        Page page = getMapBoxPrinter().getBox().getPage();
        org.eclipse.draw2d.geometry.Dimension pageSize = page.getSize();
        org.eclipse.draw2d.geometry.Dimension paperSize = page.getPaperSize();
        // map box size in pixels
        org.eclipse.draw2d.geometry.Dimension mapSize = owner.getBoxPrinter().getBox().getSize();
        // map box size in points and then in meters on paper
        float mapPaperWidthPoints = (float) paperSize.width * (float) mapSize.width
                / (float) pageSize.width;
        float mapPaperWidthMeters = AbstractBoxPrinter.point2cm(mapPaperWidthPoints) / 100f;
        float mapPaperHeightPoints = (float) paperSize.height * (float) mapSize.height
                / (float) pageSize.height;
        float mapPaperHeightMeters = AbstractBoxPrinter.point2cm(mapPaperHeightPoints) / 100f;

        double mapWorldWidthMeters = scale * mapPaperWidthMeters;
        double mapWorldHeightMeters = scale * mapPaperHeightMeters;

        // current map bounds in meters
        ReferencedEnvelope mapEnvelope = (ReferencedEnvelope) viewportModel.getBounds();
        double centerX = (mapEnvelope.getMaxX() + mapEnvelope.getMinX()) / 2.0;
        double centerY = (mapEnvelope.getMaxY() + mapEnvelope.getMinY()) / 2.0;

        double minX = centerX - mapWorldWidthMeters / 2.0;
        double maxX = centerX + mapWorldWidthMeters / 2.0;
        double minY = centerY - mapWorldHeightMeters / 2.0;
        double maxY = centerY + mapWorldHeightMeters / 2.0;

        viewportModel.setBounds(minX, maxX, minY, maxY);
    }
View Full Code Here

            // SWT, draw all the tiles
            Set<ReferencedEnvelope> keySet = tiles.keySet();
              for (ReferencedEnvelope env : keySet) {
                Tile tile = tiles.get(env);
                //System.out.println("SWTImage: "+tile.getSWTImage());
                ViewportModel viewportModelInternal = tile.getRenderExecutor().getRenderer().getContext().getViewportModelInternal();
                java.awt.Point a = viewportModelInternal.worldToPixel(new Coordinate(env.getMinX(), env.getMinY()));
              java.awt.Point b = viewportModelInternal.worldToPixel(new Coordinate(env.getMaxX(), env.getMaxY()));
                    int width = b.x - a.x;
                    int height = a.y - b.y;
              synchronized (tile) {
                      //an exception can be thrown here if the image has been disposed of
                      //since it was retrieved or something else bad happens while drawing
                      //this is OK in our case because another paint event should be coming soon
                      //which will fix the issue; so for now we just catch the errors
                      //and don't worry about them.
                      try{
                          org.eclipse.swt.graphics.Image im = tile.getSWTImage();
                          gc.drawImage(im, 0, 0, im.getBounds().width, im.getBounds().height, a.x, b.y, width, height);
                      }catch (Exception ex){
                      }   
                    }
              if( TESTING ){
                    g.setColor(Color.BLUE);
                      g.drawLine(a.x, a.y, a.x, b.y);
                      g.drawLine(a.x, b.y, b.x, b.y);
                      g.drawLine(b.x, b.y, b.x, a.y);
                      g.drawLine(b.x, a.y, a.x, a.y);               
              }
              }  
            }
          else {
            // AWT, draw all the tiles
            Set<ReferencedEnvelope> keySet = tiles.keySet();
              for (ReferencedEnvelope env : keySet) {
                Tile tile = tiles.get(env);
                //System.out.println("BufferedImage: "+tile.getBufferedImage());
                ViewportModel viewportModelInternal = tile.getRenderExecutor().getRenderer().getContext().getViewportModelInternal();
                java.awt.Point a = viewportModelInternal.worldToPixel(new Coordinate(env.getMinX(), env.getMinY()));
                java.awt.Point b = viewportModelInternal.worldToPixel(new Coordinate(env.getMaxX(), env.getMaxY()));
                g.drawImage((RenderedImage)tile.getBufferedImage(), a.x, b.y);
                g.setColor(Color.BLUE);
                  g.drawLine(a.x, a.y, a.x, b.y);
                  g.drawLine(a.x, b.y, b.x, b.y);
                  g.drawLine(b.x, b.y, b.x, a.y);
View Full Code Here

TOP

Related Classes of org.locationtech.udig.project.internal.render.ViewportModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.