Search in sources :

Example 6 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class AbstractOverlay method getSnapLayers.

protected List<AbstractRecordLayer> getSnapLayers() {
    final Project project = getProject();
    final MapPanel map = getMap();
    final double scale = map.getScale();
    return AbstractRecordLayer.getVisibleLayers(project, scale);
}
Also used : Project(com.revolsys.swing.map.layer.Project) MapPanel(com.revolsys.swing.map.MapPanel)

Example 7 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class AbstractOverlay method setSnapLocations.

protected boolean setSnapLocations(final Map<Point, Set<CloseLocation>> snapLocations) {
    if (snapLocations.isEmpty()) {
        if (!this.snapPointLocationMap.isEmpty()) {
            this.snapCentre = null;
            this.snapPoint = null;
            this.snapPointLocationMap = snapLocations;
            this.snapPoints.clear();
            clearMapCursor();
            this.map.clearToolTipText();
        }
        return false;
    } else {
        if (!DataType.equal(snapLocations, this.snapPointLocationMap)) {
            this.snapPointIndex = 1;
            this.snapPointLocationMap = snapLocations;
            this.snapPoints.clear();
            this.snapPoints.addAll(snapLocations.keySet());
            Collections.sort(this.snapPoints, new Comparator<Point>() {

                @Override
                public int compare(final Point point1, final Point point2) {
                    final Collection<CloseLocation> locations1 = snapLocations.get(point1);
                    final Collection<CloseLocation> locations2 = snapLocations.get(point2);
                    final boolean hasVertex1 = hasVertex(locations1);
                    final boolean hasVertex2 = hasVertex(locations2);
                    if (hasVertex1) {
                        if (!hasVertex2) {
                            return -1;
                        }
                    } else if (hasVertex2) {
                        return 0;
                    }
                    final double distance1 = AbstractOverlay.this.snapCentre.distancePoint(point1);
                    final double distance2 = AbstractOverlay.this.snapCentre.distancePoint(point2);
                    if (distance1 <= distance2) {
                        return -1;
                    } else {
                        return 0;
                    }
                }

                private boolean hasVertex(final Collection<CloseLocation> locations) {
                    for (final CloseLocation location : locations) {
                        if (location.getVertex() != null) {
                            return true;
                        }
                    }
                    return false;
                }
            });
        }
        final MapPanel map = getMap();
        if (this.snapPointIndex == 0) {
            this.snapPoint = getEventPoint();
        } else {
            this.snapPoint = this.snapPoints.get(this.snapPointIndex - 1);
        }
        boolean nodeSnap = false;
        final StringBuilder text = new StringBuilder("<html>");
        text.append("<div style=\"padding: 1px;");
        if (0 == this.snapPointIndex) {
            text.append("background-color: #0000ff;color: #ffffff");
        } else {
            text.append("background-color: #ffffff");
        }
        text.append("\"><b>0.</b> ");
        final Point mousePoint = getEventPoint();
        appendPoint(text, mousePoint);
        text.append(" (");
        text.append(mousePoint.getCoordinateSystemId());
        text.append(")</div>");
        int i = 1;
        for (final Point snapPoint : this.snapPoints) {
            text.append("<div style=\"border-top: 1px solid #666666;");
            if (i == this.snapPointIndex) {
                text.append("border: 2px solid #0000ff");
            } else {
                text.append("padding: 2px;background-color: #ffffff2");
            }
            text.append("\">");
            text.append("<div style=\"padding: 1px;");
            if (i == this.snapPointIndex) {
                text.append("background-color: #0000ff;color: #ffffff");
            }
            text.append("\"><b>");
            text.append(i);
            text.append(".</b> ");
            appendPoint(text, snapPoint);
            text.append(" (");
            text.append(snapPoint.getCoordinateSystemId());
            text.append(")</div>");
            final Map<String, Set<CloseLocation>> typeLocationsMap = new TreeMap<>();
            for (final CloseLocation snapLocation : this.snapPointLocationMap.get(snapPoint)) {
                final String typePath = snapLocation.getLayerPath();
                final String locationType = snapLocation.getType();
                if ("Point".equals(locationType) || "End-Vertex".equals(locationType)) {
                    nodeSnap = true;
                }
                Maps.addToSet(typeLocationsMap, typePath + " (<b style=\"color:red\">" + locationType + "</b>)", snapLocation);
            }
            for (final Entry<String, Set<CloseLocation>> typeLocations : typeLocationsMap.entrySet()) {
                final String type = typeLocations.getKey();
                text.append("<div style=\"padding: 1px;");
                if (i == this.snapPointIndex) {
                    text.append("background-color: #87CEFA");
                } else {
                // text.append("background-color: #ffffff");
                }
                text.append("\">&nbsp;&nbsp;&nbsp;");
                text.append(type);
                text.append("</div>");
            }
            text.append("</div>");
            i++;
        }
        text.append("</html>");
        map.setToolTipText(this.snapEventX, this.snapEventY, text);
        if (Booleans.getBoolean(nodeSnap)) {
            setMapCursor(CURSOR_NODE_SNAP);
        } else {
            setMapCursor(CURSOR_LINE_SNAP);
        }
        return true;
    }
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) Set(java.util.Set) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) TreeMap(java.util.TreeMap) Paint(java.awt.Paint) Point(com.revolsys.geometry.model.Point) Collection(java.util.Collection)

Example 8 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class EditRecordGeometryOverlay method modeAddGeometryMove.

protected boolean modeAddGeometryMove(final MouseEvent event) {
    if (this.addGeometryEditor != null) {
        if (isOverlayAction(ACTION_ADD_GEOMETRY) || isOverlayAction(ACTION_MOVE_GEOMETRY) || isOverlayAction(ACTION_ADD_GEOMETRY_EDIT_VERTICES)) {
            final MapPanel map = getMap();
            final CloseLocation location = map.findCloseLocation(this.addLayer, null, this.addGeometryEditor);
            final List<CloseLocation> locations = new ArrayList<>();
            if (location != null) {
                locations.add(location);
            }
            final boolean hasMouseOver = setMouseOverLocations(locations);
            if (event != null && event.isAltDown()) {
                if (hasMouseOver) {
                    setOverlayAction(ACTION_MOVE_GEOMETRY);
                } else {
                    clearOverlayAction(ACTION_MOVE_GEOMETRY);
                    if (!hasMouseOverLocation()) {
                        clearMapCursor();
                    }
                }
            } else {
                clearOverlayAction(ACTION_MOVE_GEOMETRY);
                // TODO make work with multi-part
                if (hasMouseOver) {
                    setOverlayAction(ACTION_ADD_GEOMETRY_EDIT_VERTICES);
                } else {
                    clearOverlayAction(ACTION_ADD_GEOMETRY_EDIT_VERTICES);
                    modeAddGeometryUpdateXorGeometry();
                }
            }
            return true;
        }
    }
    return false;
}
Also used : CloseLocation(com.revolsys.swing.map.overlay.CloseLocation) MapPanel(com.revolsys.swing.map.MapPanel) ArrayList(java.util.ArrayList)

Example 9 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class EditRecordGeometryOverlay method clearMouseOverLocations.

protected void clearMouseOverLocations() {
    setXorGeometry(null);
    clearMouseOverGeometry();
    final MapPanel map = getMap();
    map.clearCloseSelected();
    map.clearToolTipText();
    repaint();
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel)

Example 10 with MapPanel

use of com.revolsys.swing.map.MapPanel in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method panToBoundingBox.

public void panToBoundingBox(final BoundingBox boundingBox) {
    final MapPanel mapPanel = getMapPanel();
    mapPanel.panToBoundingBox(boundingBox);
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel)

Aggregations

MapPanel (com.revolsys.swing.map.MapPanel)32 Point (com.revolsys.geometry.model.Point)6 Viewport2D (com.revolsys.swing.map.Viewport2D)6 BoundingBox (com.revolsys.geometry.model.BoundingBox)4 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 LineString (com.revolsys.geometry.model.LineString)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 CloseLocation (com.revolsys.swing.map.overlay.CloseLocation)4 ArrayList (java.util.ArrayList)4 DataType (com.revolsys.datatype.DataType)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 Project (com.revolsys.swing.map.layer.Project)3 Set (java.util.Set)3 TreeMap (java.util.TreeMap)3 JLabel (javax.swing.JLabel)3 Geometry (com.revolsys.geometry.model.Geometry)2 RectangularMapGrid (com.revolsys.gis.grid.RectangularMapGrid)2 EnableCheck (com.revolsys.swing.action.enablecheck.EnableCheck)2 TabbedValuePanel (com.revolsys.swing.component.TabbedValuePanel)2 Layer (com.revolsys.swing.map.layer.Layer)2