Search in sources :

Example 1 with Viewport2D

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

the class ZoomOverlay method panFinish.

public boolean panFinish(final MouseEvent event) {
    if (event.getButton() == this.panButton) {
        if (clearOverlayAction(ACTION_PAN) && this.panX1 != -1) {
            this.panImage = null;
            if (this.panX1 != this.panX2 || this.panY1 != this.panY2) {
                final java.awt.Point point = event.getPoint();
                final Viewport2D viewport = getViewport();
                final Point fromPoint = viewport.toModelPoint(this.panX1, this.panY1);
                final Point toPoint = viewport.toModelPoint(point);
                final double deltaX = fromPoint.getX() - toPoint.getX();
                final double deltaY = fromPoint.getY() - toPoint.getY();
                final BoundingBox boundingBox = viewport.getBoundingBox();
                final BoundingBox newBoundingBox = boundingBox.move(deltaX, deltaY);
                final MapPanel map = getMap();
                map.setBoundingBox(newBoundingBox);
            }
            panClear();
            repaint();
            return true;
        }
    }
    return false;
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) MapPanel(com.revolsys.swing.map.MapPanel) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point)

Example 2 with Viewport2D

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

the class ZoomOverlay method zoomBoxFinish.

protected boolean zoomBoxFinish(final MouseEvent event) {
    if (event.getButton() == MouseEvent.BUTTON1 && clearOverlayAction(ACTION_ZOOM_BOX)) {
        final Viewport2D viewport = getViewport();
        // Convert first point to envelope top left in map coords.
        final int minX = Math.min(this.zoomBoxX1, this.zoomBoxX2);
        final int minY = Math.min(this.zoomBoxY1, this.zoomBoxY2);
        final Point topLeft = viewport.toModelPoint(minX, minY);
        // Convert second point to envelope bottom right in map coords.
        final int maxX = Math.max(this.zoomBoxX1, this.zoomBoxX2);
        final int maxY = Math.max(this.zoomBoxY1, this.zoomBoxY2);
        final Point bottomRight = viewport.toModelPoint(maxX, maxY);
        final MapPanel map = getMap();
        final GeometryFactory geometryFactory = map.getGeometryFactory();
        final BoundingBox boundingBox = geometryFactory.newBoundingBox(topLeft.getX(), topLeft.getY(), bottomRight.getX(), bottomRight.getY());
        if (boundingBox.isEmpty()) {
            Toolkit.getDefaultToolkit().beep();
        } else {
            map.setBoundingBox(boundingBox);
        }
        zoomBoxClear();
        if (SwingUtil.isShiftDown(event) && isMouseInMap()) {
            setOverlayAction(ACTION_ZOOM_BOX);
        }
        return true;
    }
    return false;
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) MapPanel(com.revolsys.swing.map.MapPanel) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 3 with Viewport2D

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

the class ZoomOverlay method mouseWheelMoved.

@Override
public void mouseWheelMoved(final MouseWheelEvent event) {
    if (canOverrideOverlayAction(ACTION_ZOOM)) {
        if (Math.abs(event.getWheelRotation()) == 1 && event.getModifiersEx() == 0) {
            int numSteps = 1;
            if (event.getUnitsToScroll() < 0) {
                numSteps = -1;
            }
            if (SwingUtil.isScrollReversed()) {
                numSteps = -numSteps;
            }
            if (!isWheelForwardsZoomIn()) {
                numSteps = -numSteps;
            }
            final int x = event.getX();
            final int y = event.getY();
            final Viewport2D viewport = getViewport();
            final Point mapPoint = viewport.toModelPoint(x, y);
            final MapPanel map = getMap();
            map.zoom(mapPoint, numSteps);
            event.consume();
        }
    }
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) MapPanel(com.revolsys.swing.map.MapPanel) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 4 with Viewport2D

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

the class AbstractOverlay method newXorLine.

protected LineString newXorLine(final GeometryFactory geometryFactory, final Point c0, final Point p1) {
    final Viewport2D viewport = getViewport();
    final GeometryFactory viewportGeometryFactory = viewport.getGeometryFactory2dFloating();
    final LineSegment line = viewportGeometryFactory.lineSegment(c0, p1);
    final double length = line.getLength();
    if (length > 0) {
        final double cursorRadius = viewport.getModelUnitsPerViewUnit() * 6;
        final Point newC1 = line.pointAlongOffset((length - cursorRadius) / length, 0);
        return geometryFactory.lineString(c0, newC1);
    } else {
        return null;
    }
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) ComponentViewport2D(com.revolsys.swing.map.ComponentViewport2D) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 5 with Viewport2D

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

the class AbstractOverlay method getPoint.

protected Point getPoint(final GeometryFactory geometryFactory, final MouseEvent event) {
    final Viewport2D viewport = getViewport();
    final Point point = viewport.toModelPointRounded(geometryFactory, event.getX(), event.getY());
    return point;
}
Also used : Viewport2D(com.revolsys.swing.map.Viewport2D) ComponentViewport2D(com.revolsys.swing.map.ComponentViewport2D) Point(com.revolsys.geometry.model.Point)

Aggregations

Viewport2D (com.revolsys.swing.map.Viewport2D)17 Point (com.revolsys.geometry.model.Point)10 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 MapPanel (com.revolsys.swing.map.MapPanel)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 Project (com.revolsys.swing.map.layer.Project)5 ComponentViewport2D (com.revolsys.swing.map.ComponentViewport2D)3 Graphics2D (java.awt.Graphics2D)3 LineSegment (com.revolsys.geometry.model.segment.LineSegment)2 BaseCloseable (com.revolsys.io.BaseCloseable)2 ImageViewport (com.revolsys.swing.map.ImageViewport)2 BufferedImage (java.awt.image.BufferedImage)2 PageFormat (java.awt.print.PageFormat)2 PrinterException (java.awt.print.PrinterException)2 PrinterJob (java.awt.print.PrinterJob)2 WebColors (com.revolsys.awt.WebColors)1 Maps (com.revolsys.collection.map.Maps)1 DataType (com.revolsys.datatype.DataType)1 DataTypes (com.revolsys.datatype.DataTypes)1 Geometry (com.revolsys.geometry.model.Geometry)1