source: josm/trunk/src/org/openstreetmap/josm/data/projection/ShiftedProjecting.java@ 14273

Last change on this file since 14273 was 12161, checked in by michael2402, 7 years ago

See #13415: Add the ILatLon interface, unify handling of Nodes and CachedLatLon

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection;
3
4import java.util.HashMap;
5import java.util.Map;
6
7import org.openstreetmap.josm.data.ProjectionBounds;
8import org.openstreetmap.josm.data.coor.EastNorth;
9import org.openstreetmap.josm.data.coor.ILatLon;
10import 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 */
17public 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}
Note: See TracBrowser for help on using the repository browser.