Search in sources :

Example 6 with Layer

use of com.revolsys.swing.map.layer.Layer in project com.revolsys.open by revolsys.

the class LayerRendererOverlaySwingWorker method handleBackground.

@Override
protected Void handleBackground() {
    try {
        final Layer layer = this.overlay.getLayer();
        if (layer != null) {
            final Project project = this.overlay.getProject();
            final int imageWidth = this.referencedImage.getImageWidth();
            final int imageHeight = this.referencedImage.getImageHeight();
            if (imageWidth > 0 && imageHeight > 0 && project != null) {
                final BoundingBox boundingBox = this.referencedImage.getBoundingBox();
                try (final ImageViewport viewport = new ImageViewport(project, imageWidth, imageHeight, boundingBox)) {
                    if (layer != null && layer.isExists() && layer.isVisible()) {
                        final LayerRenderer<Layer> renderer = layer.getRenderer();
                        if (renderer != null) {
                            renderer.render(viewport, this);
                        }
                    }
                    if (!isCancelled()) {
                        final BufferedImage image = viewport.getImage();
                        this.referencedImage.setRenderedImage(image);
                    }
                }
            }
        }
        return null;
    } catch (final Throwable t) {
        if (!isCancelled()) {
            Logs.error(this, "Unable to paint", t);
        }
        return null;
    }
}
Also used : Project(com.revolsys.swing.map.layer.Project) ImageViewport(com.revolsys.swing.map.ImageViewport) BoundingBox(com.revolsys.geometry.model.BoundingBox) Layer(com.revolsys.swing.map.layer.Layer) BufferedImage(java.awt.image.BufferedImage)

Example 7 with Layer

use of com.revolsys.swing.map.layer.Layer in project com.revolsys.open by revolsys.

the class EditRecordGeometryOverlay method addSnapLayers.

protected boolean addSnapLayers(final Set<AbstractRecordLayer> layers, final Project project, final AbstractRecordLayer layer, final double scale) {
    if (layer != null) {
        if (layer.isSnapToAllLayers()) {
            return true;
        } else {
            layers.add(layer);
            final Collection<String> layerPaths = layer.getSnapLayerPaths();
            if (layerPaths != null) {
                for (final String layerPath : layerPaths) {
                    final Layer snapLayer = project.getLayer(layerPath);
                    if (snapLayer instanceof AbstractRecordLayer) {
                        if (snapLayer.isVisible(scale)) {
                            layers.add((AbstractRecordLayer) snapLayer);
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LineString(com.revolsys.geometry.model.LineString) ElevationModelLayer(com.revolsys.swing.map.layer.elevation.ElevationModelLayer) Layer(com.revolsys.swing.map.layer.Layer) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) AbstractLayer(com.revolsys.swing.map.layer.AbstractLayer)

Example 8 with Layer

use of com.revolsys.swing.map.layer.Layer in project com.revolsys.open by revolsys.

the class MapPanel method propertyChange.

@SuppressWarnings("unchecked")
@Override
public void propertyChange(final PropertyChangeEvent event) {
    final Object source = event.getSource();
    final String propertyName = event.getPropertyName();
    final Object oldValue = event.getOldValue();
    final Object newValue = event.getNewValue();
    if (AbstractRecordLayer.RECORDS_SELECTED.equals(propertyName)) {
        final List<LayerRecord> oldRecords = (List<LayerRecord>) oldValue;
        this.selectedRecordsIndex.removeRecords(oldRecords);
        final List<LayerRecord> newRecords = (List<LayerRecord>) newValue;
        this.selectedRecordsIndex.addRecords(newRecords);
    } else if (source == this.project) {
        if ("viewBoundingBox".equals(propertyName)) {
            final BoundingBox boundingBox = (BoundingBox) newValue;
            setBoundingBox(boundingBox);
        } else if ("geometryFactory".equals(propertyName)) {
            final GeometryFactory oldGeometryFactory = (GeometryFactory) oldValue;
            final GeometryFactory newGeometryFactory = (GeometryFactory) newValue;
            setGeometryFactory(oldGeometryFactory, newGeometryFactory);
        }
    } else if (source == this.viewport) {
        if ("geometryFactory".equals(propertyName)) {
            final GeometryFactory oldGeometryFactory = (GeometryFactory) oldValue;
            final GeometryFactory newGeometryFactory = (GeometryFactory) newValue;
            setGeometryFactory(oldGeometryFactory, newGeometryFactory);
        } else if ("boundingBox".equals(propertyName)) {
            final BoundingBox boundingBox = this.viewport.getBoundingBox();
            setBoundingBox(boundingBox);
        } else if ("unitsPerPixel".equals(propertyName)) {
            repaint();
        }
    } else if (source == this.baseMapOverlay) {
        if ("layer".equals(propertyName)) {
            final Layer layer = (Layer) newValue;
            if (this.baseMapLayerField != null) {
                if (layer == null) {
                    this.baseMapLayerField.setSelectedItem(0);
                } else {
                    this.baseMapLayerField.setSelectedItem(layer);
                }
            }
        }
    } else if (source == this.baseMapLayers) {
        if ("layers".equals(propertyName)) {
            if (this.baseMapOverlay != null) {
                final Layer selectedLayer = this.baseMapOverlay.getLayer();
                final Layer newLayer = (Layer) newValue;
                if (selectedLayer != newLayer) {
                    if (selectedLayer != null) {
                        final LayerGroup selectedLayerParent = selectedLayer.getLayerGroup();
                        if (selectedLayer.isDeleted() || selectedLayerParent != null && selectedLayerParent != this.baseMapLayers) {
                            this.baseMapOverlay.setLayer(null);
                        }
                    }
                    if (newLayer != null && newLayer.isVisible()) {
                        this.baseMapOverlay.setLayer(newLayer);
                        this.baseMapLayerField.setSelectedItem(newLayer);
                        if (selectedLayer != null) {
                            selectedLayer.setVisible(false);
                        }
                    }
                }
            }
        }
    } else if (source instanceof Layer) {
        final Layer layer = (Layer) source;
        if (layer.getParent() == this.baseMapLayers) {
            if ("visible".equals(propertyName)) {
                final boolean visible = layer.isVisible();
                if (visible) {
                    this.baseMapLayerField.setSelectedItem(layer);
                } else if (!this.baseMapLayers.isHasVisibleLayer()) {
                    this.baseMapLayerField.setSelectedIndex(0);
                }
            }
        }
    } else if (source instanceof LayerRecord) {
        final LayerRecord record = (LayerRecord) source;
        if (propertyName.equals(record.getGeometryFieldName())) {
            if (record.isSelected()) {
                final Geometry oldGeometry = (Geometry) oldValue;
                if (oldGeometry == null) {
                    final BoundingBox boundingBox = record.getGeometry().getBoundingBox();
                    this.selectedRecordsIndex.removeItem(boundingBox, record);
                } else {
                    final BoundingBox boundingBox = oldGeometry.getBoundingBox();
                    this.selectedRecordsIndex.removeItem(boundingBox, record);
                }
                this.selectedRecordsIndex.addRecord(record);
            }
        }
    }
    repaint();
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) BaseMapLayerGroup(com.revolsys.swing.map.layer.BaseMapLayerGroup) LayerGroup(com.revolsys.swing.map.layer.LayerGroup) Layer(com.revolsys.swing.map.layer.Layer) NullLayer(com.revolsys.swing.map.layer.NullLayer) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer)

Example 9 with Layer

use of com.revolsys.swing.map.layer.Layer in project com.revolsys.open by revolsys.

the class MapPanel method setBaseMapLayer.

public synchronized void setBaseMapLayer(final Layer layer) {
    if (layer == NullLayer.INSTANCE || this.baseMapLayers.containsLayer(layer)) {
        final Layer oldValue = getBaseMapLayer();
        this.baseMapOverlay.setLayer(layer);
        firePropertyChange("baseMapLayer", oldValue, layer);
    }
}
Also used : Layer(com.revolsys.swing.map.layer.Layer) NullLayer(com.revolsys.swing.map.layer.NullLayer) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer)

Example 10 with Layer

use of com.revolsys.swing.map.layer.Layer in project com.revolsys.open by revolsys.

the class AbstractLayerTreeNode method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(Component renderer, final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
    renderer = super.getTreeCellRendererComponent(renderer, tree, value, selected, expanded, leaf, row, hasFocus);
    if (isUserObjectInitialized()) {
        final Layer layer = getLayer();
        final MapPanel map = layer.getMapPanel();
        if (map != null) {
            final double scale = map.getScale();
            if (layer.getRenderer() != null && !layer.isVisible(scale)) {
                renderer.setForeground(WebColors.Gray);
            }
        }
    }
    return renderer;
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) Layer(com.revolsys.swing.map.layer.Layer)

Aggregations

Layer (com.revolsys.swing.map.layer.Layer)33 AbstractLayer (com.revolsys.swing.map.layer.AbstractLayer)18 LayerGroup (com.revolsys.swing.map.layer.LayerGroup)16 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)10 ArrayList (java.util.ArrayList)8 NullLayer (com.revolsys.swing.map.layer.NullLayer)5 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)4 BaseTreeNode (com.revolsys.swing.tree.BaseTreeNode)4 List (java.util.List)4 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)3 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 TreePath (javax.swing.tree.TreePath)3 MapPanel (com.revolsys.swing.map.MapPanel)2 BaseMapLayerGroup (com.revolsys.swing.map.layer.BaseMapLayerGroup)2 Project (com.revolsys.swing.map.layer.Project)2 ElevationModelLayer (com.revolsys.swing.map.layer.elevation.ElevationModelLayer)2 Rectangle (java.awt.Rectangle)2 JTree (javax.swing.JTree)2 TreeUI (javax.swing.plaf.TreeUI)2