1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
5 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Data class to keep viewport information.
|
---|
9 | *
|
---|
10 | * This can be either a combination of map center and map scale or
|
---|
11 | * a rectangle in east-north coordinate space.
|
---|
12 | *
|
---|
13 | * Either of those will be null, so the consumer of the ViewportData
|
---|
14 | * object has to check, which one is set.
|
---|
15 | *
|
---|
16 | * @since 5670 (creation)
|
---|
17 | * @since 6992 (extraction in this package)
|
---|
18 | */
|
---|
19 | public class ViewportData {
|
---|
20 | private final EastNorth center;
|
---|
21 | private final Double scale;
|
---|
22 |
|
---|
23 | private final ProjectionBounds bounds;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructs a new {@code ViewportData}.
|
---|
27 | * @param center Projected coordinates of the map center
|
---|
28 | * @param scale Scale factor in east-/north-units per pixel
|
---|
29 | */
|
---|
30 | public ViewportData(EastNorth center, Double scale) {
|
---|
31 | CheckParameterUtil.ensureParameterNotNull(center);
|
---|
32 | CheckParameterUtil.ensureParameterNotNull(scale);
|
---|
33 | this.center = center;
|
---|
34 | this.scale = scale;
|
---|
35 | this.bounds = null;
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Create a new {@link ViewportData}
|
---|
40 | * @param bounds The bounds to zoom to
|
---|
41 | */
|
---|
42 | public ViewportData(ProjectionBounds bounds) {
|
---|
43 | CheckParameterUtil.ensureParameterNotNull(bounds);
|
---|
44 | this.center = null;
|
---|
45 | this.scale = null;
|
---|
46 | this.bounds = bounds;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Return the projected coordinates of the map center
|
---|
51 | * @return the center
|
---|
52 | */
|
---|
53 | public EastNorth getCenter() {
|
---|
54 | return center;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Return the scale factor in east-/north-units per pixel.
|
---|
59 | * @return the scale
|
---|
60 | */
|
---|
61 | public Double getScale() {
|
---|
62 | return scale;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Return the bounds in east-north coordinate space.
|
---|
67 | * @return the bounds
|
---|
68 | */
|
---|
69 | public ProjectionBounds getBounds() {
|
---|
70 | return bounds;
|
---|
71 | }
|
---|
72 | }
|
---|