public final class MapScale extends Object implements Comparable<MapScale>
For example: a map scale of 1:50000 means that 1 centimeter on a map corresponds with 500 meters on the ground.
This class gives a natural ordering to map scales, from zoomed out to zoomed in. When a part of the API takes an ordered collection as input, it must be ordered according to this natural ordering (unless stated otherwise).
In order for a Map
instance to interpret MapScale
values correctly, it needs to know the DPI (see Map#getDpi
) value of the screen on which it is rendered.
See also the related article
Modifier and Type | Field and Description |
---|---|
static MapScale |
MaxZoomedIn
The value that represents a maximally zoomed in map scale (1:0 ≈ the maximum double value)
|
static MapScale |
MaxZoomedOut
The value that represents a maximally zoomed out map scale (1:inf == 0)
|
Constructor and Description |
---|
MapScale(double value)
Creates a new
MapScale based on the given ratio. |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(MapScale other) |
boolean |
equals(Object other) |
static MapScale |
fromDenominator(double denominator)
Creates a map scale from a denominator value.
|
double |
getDenominator()
Returns the denominator of this map scale.
|
double |
getValue()
Returns the scale value.
|
int |
hashCode() |
String |
toString() |
MapScale |
zoomIn(double factor)
Creates a new MapScale which is zoomed in with a given factor.
|
MapScale |
zoomOut(double factor)
Creates a new MapScale which is zoomed outn with a given factor.
|
public static final MapScale MaxZoomedOut
public static final MapScale MaxZoomedIn
public MapScale(double value) throws IllegalArgumentException
MapScale
based on the given ratio.value
- a value that represents 1 / denominator. For example: a MapScale
of 1:50000 can be created using 0.00002 (=1/50000) as value.IllegalArgumentException
- when the map scale is smaller than 0.@NotNull public static MapScale fromDenominator(double denominator) throws IllegalArgumentException
For example when using 1:50000 as map scale, the denominator is 50000.
denominator
- the scale denominator.IllegalArgumentException
- when the denominator is negative.@NotNull public MapScale zoomOut(double factor)
For example, when applying this method on a 1:50000 scale, with a factor or 2, the resulting map scale will be 1:100000.
factor
- the factor using which to zoom out@NotNull public MapScale zoomIn(double factor)
For example, when applying this method on a 1:50000 scale, with a factor or 2, the resulting map scale will be 1:25000.
factor
- the factor using which to zoom inpublic double getValue()
public double getDenominator()
For example when the Map
Scale is 1:50000
, this method returns 50000
.
public int compareTo(@NotNull MapScale other)
compareTo
in interface Comparable<MapScale>