Search in sources :

Example 1 with LayerGroup

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

the class ElevationModelLayer method getElevation.

static double getElevation(final LayerGroup layerGroup, final double scale, final Point point) {
    if (layerGroup.isVisible(scale)) {
        for (final Layer layer : layerGroup) {
            if (layer instanceof LayerGroup) {
                final LayerGroup childGroup = (LayerGroup) layer;
                final double elevation = getElevation(childGroup, scale, point);
                if (Double.isFinite(elevation)) {
                    return elevation;
                }
            } else if (layer instanceof ElevationModelLayer) {
                final ElevationModelLayer elevationModel = (ElevationModelLayer) layer;
                if (elevationModel.isUseElevationAtScale(scale)) {
                    final double elevation = elevationModel.getElevation(point);
                    if (Double.isFinite(elevation)) {
                        return elevation;
                    }
                }
            }
        }
    }
    return Double.NaN;
}
Also used : LayerGroup(com.revolsys.swing.map.layer.LayerGroup) Layer(com.revolsys.swing.map.layer.Layer)

Example 2 with LayerGroup

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

the class ElevationModelLayer method getElevationVisible.

static double getElevationVisible(final LayerGroup layerGroup, final double scale, final Point point) {
    if (layerGroup.isVisible(scale)) {
        for (final Layer layer : layerGroup) {
            if (layer instanceof LayerGroup) {
                final LayerGroup childGroup = (LayerGroup) layer;
                final double elevation = getElevation(childGroup, scale, point);
                if (Double.isFinite(elevation)) {
                    return elevation;
                }
            } else if (layer instanceof ElevationModelLayer) {
                final ElevationModelLayer elevationModel = (ElevationModelLayer) layer;
                if (elevationModel.isVisible(scale)) {
                    final double elevation = elevationModel.getElevation(point);
                    if (Double.isFinite(elevation)) {
                        return elevation;
                    }
                }
            }
        }
    }
    return Double.NaN;
}
Also used : LayerGroup(com.revolsys.swing.map.layer.LayerGroup) Layer(com.revolsys.swing.map.layer.Layer)

Example 3 with LayerGroup

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

the class MapPrintable method print.

@Override
public int print(final Graphics graphics, final PageFormat pageFormat, final int pageIndex) throws PrinterException {
    final Graphics2D graphics2d = (Graphics2D) graphics;
    final PrintViewport2D viewport = new PrintViewport2D(this.map, graphics2d, pageFormat, this.boundingBox, this.contentRect, this.dpi);
    graphics2d.translate(pageFormat.getImageableX() * this.dpi / 72.0, pageFormat.getImageableX() * this.dpi / 72.0);
    drawFooter(graphics2d);
    graphics2d.translate(this.contentRect.getMinX(), this.contentRect.getMinY());
    drawRuler(viewport, graphics2d);
    graphics2d.clip(new Rectangle2D.Double(0, 0, this.contentRect.getWidth(), this.contentRect.getHeight()));
    final LayerGroup map = viewport.getProject();
    map.getRenderer().render(viewport);
    final double unit = viewport.getModelUnitsPerViewUnit();
    final float lineWidth = (float) (unit * this.millimetre / 5);
    // final boolean saved = viewport.setUseModelCoordinates(true, graphics2d);
    try {
        graphics2d.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
        final double minX = this.boundingBox.getMinX();
        final double maxX = this.boundingBox.getMaxX();
        final double minY = this.boundingBox.getMinY();
        final double maxY = this.boundingBox.getMaxY();
        final int startXIndex = (int) Math.ceil(minX / this.majorDivisions);
        final int endXIndex = (int) Math.ceil(maxX / this.majorDivisions);
        graphics2d.setColor(Color.GRAY);
        for (int i = startXIndex; i < endXIndex; i++) {
            final double x = i * this.majorDivisions;
            graphics2d.draw(new Line2D.Double(x, minY, x, maxY));
        }
        final int startYIndex = (int) Math.ceil(minY / this.majorDivisions);
        final int endYIndex = (int) Math.ceil(maxY / this.majorDivisions);
        for (int i = startYIndex; i < endYIndex; i++) {
            final double y = i * this.majorDivisions;
            graphics2d.draw(new Line2D.Double(minX, y, maxX, y));
        }
    } finally {
    // viewport.setUseModelCoordinates(saved, graphics2d);
    }
    return PAGE_EXISTS;
}
Also used : BasicStroke(java.awt.BasicStroke) Rectangle2D(java.awt.geom.Rectangle2D) LayerGroup(com.revolsys.swing.map.layer.LayerGroup) Line2D(java.awt.geom.Line2D) Graphics2D(java.awt.Graphics2D)

Example 4 with LayerGroup

use of com.revolsys.swing.map.layer.LayerGroup 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 5 with LayerGroup

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

the class WebServiceConnectionTrees method getLayerGroup.

public static LayerGroup getLayerGroup(final WebServiceResource webServiceResource) {
    LayerGroup layerGroup = Project.get();
    if (layerGroup != null) {
        final WebService<?> webService = webServiceResource.getWebService();
        if (webService != null) {
            final String webServiceName = webService.getName();
            if (Property.hasValue(webServiceName)) {
                layerGroup = layerGroup.addLayerGroup(webServiceName);
            }
        }
        final PathName layerPath = webServiceResource.getPathName();
        if (layerPath != null) {
            final PathName parent = layerPath.getParent();
            if (parent != null) {
                for (final String groupName : parent.getElements()) {
                    layerGroup = layerGroup.addLayerGroup(groupName);
                }
            }
        }
    }
    return layerGroup;
}
Also used : LayerGroup(com.revolsys.swing.map.layer.LayerGroup) PathName(com.revolsys.io.PathName)

Aggregations

LayerGroup (com.revolsys.swing.map.layer.LayerGroup)30 Layer (com.revolsys.swing.map.layer.Layer)16 AbstractLayer (com.revolsys.swing.map.layer.AbstractLayer)13 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)7 ArrayList (java.util.ArrayList)7 BaseTreeNode (com.revolsys.swing.tree.BaseTreeNode)5 List (java.util.List)5 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)4 Geometry (com.revolsys.geometry.model.Geometry)3 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 PathName (com.revolsys.io.PathName)3 LayerRendererOverlay (com.revolsys.swing.map.overlay.LayerRendererOverlay)3 BaseMapLayerGroup (com.revolsys.swing.map.layer.BaseMapLayerGroup)2 Project (com.revolsys.swing.map.layer.Project)2 File (java.io.File)2 LinkedList (java.util.LinkedList)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 RectangularMapGrid (com.revolsys.gis.grid.RectangularMapGrid)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 RecordStore (com.revolsys.record.schema.RecordStore)1