GPSCalculation.java 2.74 KB
Newer Older
1
/*
2
 * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * This file is part of PeerfactSim.KOM.
 * 
 * PeerfactSim.KOM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * PeerfactSim.KOM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with PeerfactSim.KOM.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package de.tud.kom.p2psim.impl.topology.movement.modularosm;

23
import de.tud.kom.p2psim.api.topology.Topology;
24
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
25
import de.tudarmstadt.maki.simonstrator.api.Binder;
26

27
28
29
30
31
/**
 * 
 * @author Martin Hellwig
 * @version 1.0, Nov 3, 2015
 */
32
public class GPSCalculation {
33

34
	private static double latCenter;
35

36
	private static double lonCenter;
37

38
	private static int zoom;
39

40
	private static double scaleFactor;
41

42
43
	public GPSCalculation() {
	}
44

45
	private void setScaleFactor() {
46
		// this.scaleFactor = Math.pow(2.0d, (13 - zoom));
47
		/*
48
49
50
		 * BR: set scaleFactor to fixed zoom level 15 ==> 0.125 (as in this
		 * case, 1px == 1m) - this way, the world-size specified in the configs
		 * is valid on all zoom levels.
51
52
53
54
		 */
		this.scaleFactor = 0.125;
		// 17: 2, 16: 1, 15: 0.5, 14: 0.25
		VisualizationInjector.setScale(Math.pow(2.0d, (zoom - 16)));
55
	}
56

57
58
59
	public static double getLatCenter() {
		return latCenter;
	}
60

61
62
63
	public static double getLonCenter() {
		return lonCenter;
	}
64

65
66
67
	public static int getZoom() {
		return zoom;
	}
68

69
	public static double getLatUpper() {
70
71
72
		return latCenter + scaleFactor * 0.027613 * Binder
				.getComponentOrNull(Topology.class).getWorldDimensions().getX()
				/ 1000;
73
	}
74

75
	public static double getLatLower() {
76
77
78
		return latCenter - scaleFactor * 0.027613 * Binder
				.getComponentOrNull(Topology.class).getWorldDimensions().getX()
				/ 1000;
79
80
81
	}

	public static double getLonLeft() {
82
83
84
		return lonCenter - scaleFactor * 0.0419232 * Binder
				.getComponentOrNull(Topology.class).getWorldDimensions().getY()
				/ 1000;
85
	}
86

87
	public static double getLonRight() {
88
89
90
		return lonCenter + scaleFactor * 0.0419232 * Binder
				.getComponentOrNull(Topology.class).getWorldDimensions().getY()
				/ 1000;
91
	}
92

93
94
95
	public void setLatCenter(double latCenter) {
		this.latCenter = latCenter;
	}
96

97
98
99
	public void setLonCenter(double lonCenter) {
		this.lonCenter = lonCenter;
	}
100

101
102
103
104
105
	public void setZoom(int zoom) {
		this.zoom = zoom;
		setScaleFactor();
	}
}