Search in sources :

Example 16 with LayerRecord

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

the class WikipediaBoundingBoxLayerWorker method handleBackground.

@Override
protected List<LayerRecord> handleBackground() {
    BoundingBox boundingBox = this.boundingBox;
    GeometryFactory geometryFactory = this.geometryFactory;
    final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
    if (coordinateSystem instanceof ProjectedCoordinateSystem) {
        final ProjectedCoordinateSystem projCs = (ProjectedCoordinateSystem) coordinateSystem;
        geometryFactory = projCs.getGeographicCoordinateSystem().getGeometryFactory();
        boundingBox = boundingBox.convert(geometryFactory);
    }
    final List<LayerRecord> results = (List) this.geoNamesService.getWikipediaArticles(boundingBox);
    for (final Record record : results) {
        final String title = record.getValue("title");
        final String wikipediaUrl = record.getValue("wikipediaUrl");
        final String thumbnailImage = record.getValue("thumbnailImg");
        final Point point = record.getGeometry();
        String text;
        if (thumbnailImage != null) {
            text = "<html><b>" + title + "</b><br /><img src=\"" + thumbnailImage + "\" /><br /></html>";
        } else {
            text = "<html><b>" + title + "</b><br /></html>";
        }
    // if (viewport instanceof ComponentViewport2D) {
    // final ComponentViewport2D componentViewport =
    // (ComponentViewport2D)viewport;
    // componentViewport.addHotSpot(geometryFactory, point, text, "http://"
    // + wikipediaUrl);
    // }
    }
    return results;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) BoundingBox(com.revolsys.geometry.model.BoundingBox) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) List(java.util.List) Record(com.revolsys.record.Record) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) Point(com.revolsys.geometry.model.Point)

Example 17 with LayerRecord

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

the class AbstractOverlay method hasSnapPoint.

protected boolean hasSnapPoint() {
    this.snapPoint = null;
    this.snapEventX = MouseOverlay.getEventX();
    this.snapEventY = MouseOverlay.getEventY();
    this.snapCentre = MouseOverlay.getEventPoint();
    final double snapCentreX = this.snapCentre.getX();
    final double snapCentreY = this.snapCentre.getY();
    final double maxDistance = this.viewport.getHotspotMapUnits();
    final BoundingBox boundingBox = this.snapCentre.getBoundingBox().expand(maxDistance);
    final GeometryFactory geometryFactory = getViewportGeometryFactory2d();
    final Map<Point, Set<CloseLocation>> snapLocations = new HashMap<>();
    final List<AbstractRecordLayer> layers = getSnapLayers();
    for (final AbstractRecordLayer layer : layers) {
        final List<LayerRecord> records = layer.getRecordsBackground(boundingBox);
        for (final LayerRecord record : records) {
            if (layer.isVisible(record)) {
                final Geometry recordGeometry = record.getGeometry();
                final CloseLocation closeLocation = this.map.findCloseLocation(geometryFactory, layer, record, recordGeometry, snapCentreX, snapCentreY, maxDistance);
                if (closeLocation != null) {
                    final Point closePoint = closeLocation.getViewportPoint();
                    Maps.addToSet(snapLocations, closePoint, closeLocation);
                }
            }
        }
    }
    return setSnapLocations(snapLocations);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Set(java.util.Set) HashMap(java.util.HashMap) Point(com.revolsys.geometry.model.Point) Geometry(com.revolsys.geometry.model.Geometry) BoundingBox(com.revolsys.geometry.model.BoundingBox) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Example 18 with LayerRecord

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

the class EditRecordGeometryOverlay method mouseClicked.

@Override
public void mouseClicked(final MouseEvent event) {
    if (modeAddGeometryClick(event)) {
    } else if (SwingUtil.isLeftButtonAndNoModifiers(event) && event.getClickCount() == 2) {
        final List<LayerRecord> records = new ArrayList<>();
        final BoundingBox boundingBox = getHotspotBoundingBox();
        final Geometry boundary = boundingBox.toPolygon().prepare();
        addRecords(records, getProject(), boundary);
        final int size = records.size();
        if (size == 0) {
        } else if (size < 10) {
            for (final LayerRecord record : records) {
                final AbstractRecordLayer layer = record.getLayer();
                layer.showForm(record);
            }
            event.consume();
        } else {
            JOptionPane.showMessageDialog(this, "There are too many " + size + " selected to view. Maximum 10. Select fewer records or move mouse to middle of geometry.", "Too Many Selected Records", JOptionPane.ERROR_MESSAGE);
            event.consume();
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) BoundingBox(com.revolsys.geometry.model.BoundingBox) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) List(java.util.List) ArrayList(java.util.ArrayList) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Example 19 with LayerRecord

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

the class EditRecordGeometryOverlay method splitLineKeyPress.

// K key to split a record
protected boolean splitLineKeyPress(final KeyEvent e) {
    final int keyCode = e.getKeyCode();
    if (keyCode == KeyEvent.VK_K) {
        if (!isOverlayAction(ACTION_ADD_GEOMETRY) && hasMouseOverLocation()) {
            for (final CloseLocation mouseLocation : getMouseOverLocations()) {
                final LayerRecord record = mouseLocation.getRecord();
                final AbstractRecordLayer layer = record.getLayer();
                layer.splitRecord(record, mouseLocation);
            }
            e.consume();
            return true;
        }
    }
    return false;
}
Also used : CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) Point(com.revolsys.geometry.model.Point)

Example 20 with LayerRecord

use of com.revolsys.swing.map.layer.record.LayerRecord 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)

Aggregations

LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)79 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)34 Geometry (com.revolsys.geometry.model.Geometry)15 IdentifierProxyLayerRecord (com.revolsys.swing.map.layer.record.IdentifierProxyLayerRecord)15 NewProxyLayerRecord (com.revolsys.swing.map.layer.record.NewProxyLayerRecord)15 BoundingBox (com.revolsys.geometry.model.BoundingBox)11 Record (com.revolsys.record.Record)11 ArrayList (java.util.ArrayList)11 List (java.util.List)10 Test (org.junit.Test)10 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)7 Point (com.revolsys.geometry.model.Point)6 Condition (com.revolsys.record.query.Condition)4 LayerRecordMenu (com.revolsys.swing.map.layer.record.LayerRecordMenu)4 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)4 RecordRowTable (com.revolsys.swing.table.record.RecordRowTable)4 LineString (com.revolsys.geometry.model.LineString)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 AbstractLayer (com.revolsys.swing.map.layer.AbstractLayer)3 Layer (com.revolsys.swing.map.layer.Layer)3