Search in sources :

Example 1 with GriddedElevationModelImage

use of com.revolsys.elevation.gridded.GriddedElevationModelImage in project com.revolsys.open by revolsys.

the class RasterizerGriddedElevationModelLayerRenderer method render.

@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final ElevationModelLayer layer) {
    // TODO cancel
    final double scaleForVisible = viewport.getScaleForVisible();
    if (layer.isVisible(scaleForVisible)) {
        if (!layer.isEditable()) {
            final GriddedElevationModel elevationModel = getElevationModel();
            if (elevationModel != null) {
                synchronized (this) {
                    if (this.rasterizer == null) {
                        final ColorGradientGriddedElevationModelRasterizer rasterizer = new ColorGradientGriddedElevationModelRasterizer();
                        setRasterizer(rasterizer);
                        final String name = this.rasterizer.getName();
                        setName(name);
                    }
                    if (this.image == null) {
                        this.image = new GriddedElevationModelImage(this.rasterizer);
                    }
                    if (this.image.getElevationModel() != elevationModel) {
                        this.image.setElevationModel(elevationModel);
                        this.redraw = true;
                    }
                    if (this.rasterizer != this.image.getRasterizer()) {
                        this.image.setRasterizer(this.rasterizer);
                        this.redraw = true;
                    }
                }
                if (this.image.hasImage() && !(this.image.isCached() && this.redraw)) {
                    final BoundingBox boundingBox = layer.getBoundingBox();
                    final Graphics2D graphics = viewport.getGraphics();
                    if (graphics != null) {
                        final Object interpolationMethod = null;
                        GeoreferencedImageLayerRenderer.renderAlpha(viewport, graphics, this.image, true, this.opacity, interpolationMethod);
                        GeoreferencedImageLayerRenderer.renderDifferentCoordinateSystem(viewport, graphics, boundingBox);
                    }
                } else {
                    synchronized (this) {
                        if (this.redraw && this.worker == null) {
                            this.redraw = false;
                            this.worker = new Thread(() -> {
                                synchronized (this) {
                                    if (this.worker == Thread.currentThread()) {
                                        this.image.redraw();
                                        this.worker = null;
                                    }
                                    layer.redraw();
                                }
                            });
                            this.worker.start();
                        }
                    }
                }
            }
        }
    }
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) ColorGradientGriddedElevationModelRasterizer(com.revolsys.elevation.gridded.rasterizer.ColorGradientGriddedElevationModelRasterizer) GriddedElevationModel(com.revolsys.elevation.gridded.GriddedElevationModel) GriddedElevationModelImage(com.revolsys.elevation.gridded.GriddedElevationModelImage) Graphics2D(java.awt.Graphics2D)

Aggregations

GriddedElevationModel (com.revolsys.elevation.gridded.GriddedElevationModel)1 GriddedElevationModelImage (com.revolsys.elevation.gridded.GriddedElevationModelImage)1 ColorGradientGriddedElevationModelRasterizer (com.revolsys.elevation.gridded.rasterizer.ColorGradientGriddedElevationModelRasterizer)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 Graphics2D (java.awt.Graphics2D)1