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    /**
039     * Create a new {@link ViewportData}
040     * @param bounds The bounds to zoom to
041     */
042    public ViewportData(ProjectionBounds bounds) {
043        CheckParameterUtil.ensureParameterNotNull(bounds);
044        this.center = null;
045        this.scale = null;
046        this.bounds = bounds;
047    }
048
049    /**
050     * Return the projected coordinates of the map center
051     * @return the center
052     */
053    public EastNorth getCenter() {
054        return center;
055    }
056
057    /**
058     * Return the scale factor in east-/north-units per pixel.
059     * @return the scale
060     */
061    public Double getScale() {
062        return scale;
063    }
064
065    /**
066     * Return the bounds in east-north coordinate space.
067     * @return the bounds
068     */
069    public ProjectionBounds getBounds() {
070        return bounds;
071    }
072}