001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data;
003
004import org.openstreetmap.josm.data.coor.EastNorth;
005import org.openstreetmap.josm.tools.CheckParameterUtil;
006
007/**
008 * Data class to keep viewport information.
009 *
010 * This can be either a combination of map center and map scale or
011 * a rectangle in east-north coordinate space.
012 *
013 * Either of those will be null, so the consumer of the ViewportData
014 * object has to check, which one is set.
015 *
016 * @since 5670 (creation)
017 * @since 6992 (extraction in this package)
018 */
019public class ViewportData {
020    private final EastNorth center;
021    private final Double scale;
022
023    private final ProjectionBounds bounds;
024
025    /**
026     * Constructs a new {@code ViewportData}.
027     * @param center Projected coordinates of the map center
028     * @param scale Scale factor in east-/north-units per pixel
029     */
030    public ViewportData(EastNorth center, Double scale) {
031        CheckParameterUtil.ensureParameterNotNull(center);
032        CheckParameterUtil.ensureParameterNotNull(scale);
033        this.center = center;
034        this.scale = scale;
035        this.bounds = null;
036    }
037
038    public ViewportData(ProjectionBounds bounds) {
039        CheckParameterUtil.ensureParameterNotNull(bounds);
040        this.center = null;
041        this.scale = null;
042        this.bounds = bounds;
043    }
044
045    /**
046     * Return the projected coordinates of the map center
047     * @return the center
048     */
049    public EastNorth getCenter() {
050        return center;
051    }
052
053    /**
054     * Return the scale factor in east-/north-units per pixel.
055     * @return the scale
056     */
057    public Double getScale() {
058        return scale;
059    }
060
061    /**
062     * Return the bounds in east-north coordinate space.
063     * @return the bounds
064     */
065    public ProjectionBounds getBounds() {
066        return bounds;
067    }
068}