1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.projection;
|
---|
3 |
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.Map;
|
---|
6 |
|
---|
7 | import org.openstreetmap.josm.data.ProjectionBounds;
|
---|
8 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
9 | import org.openstreetmap.josm.data.coor.ILatLon;
|
---|
10 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * This is a projecting instance that shifts the projection by a given eastnorth offset.
|
---|
14 | * @author Michael Zangl
|
---|
15 | * @since 10805
|
---|
16 | */
|
---|
17 | public class ShiftedProjecting implements Projecting {
|
---|
18 | private final Projecting base;
|
---|
19 | private final EastNorth offset;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Create a new {@link ShiftedProjecting}
|
---|
23 | * @param base The base to use
|
---|
24 | * @param offset The offset to move base. Subtracted when converting lat/lon->east/north.
|
---|
25 | */
|
---|
26 | public ShiftedProjecting(Projecting base, EastNorth offset) {
|
---|
27 | this.base = base;
|
---|
28 | this.offset = offset;
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public EastNorth latlon2eastNorth(ILatLon ll) {
|
---|
33 | return base.latlon2eastNorth(ll).add(offset);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public LatLon eastNorth2latlonClamped(EastNorth en) {
|
---|
38 | return base.eastNorth2latlonClamped(en.subtract(offset));
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public Projection getBaseProjection() {
|
---|
43 | return base.getBaseProjection();
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public Map<ProjectionBounds, Projecting> getProjectingsForArea(ProjectionBounds area) {
|
---|
48 | Map<ProjectionBounds, Projecting> forArea = base
|
---|
49 | .getProjectingsForArea(new ProjectionBounds(area.getMin().subtract(offset), area.getMax().subtract(offset)));
|
---|
50 | HashMap<ProjectionBounds, Projecting> ret = new HashMap<>();
|
---|
51 | forArea.forEach((pb, projecting) -> ret.put(
|
---|
52 | new ProjectionBounds(pb.getMin().add(offset), pb.getMax().add(offset)),
|
---|
53 | new ShiftedProjecting(projecting, offset)));
|
---|
54 | return ret;
|
---|
55 | }
|
---|
56 | }
|
---|