annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/ZoomScale.java @ 8609:421e5cceac84

(issue1754) Better fix for radius calculation then 8607:2010da0904b7 Checking for that lower < upper is guranteed in radius calculation makes more sense to do centrally in ZoomScale. This also works for the MINFO Filter facets.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 24 Mar 2015 11:06:47 +0100
parents e4606eae8ea5
children 0a5239a1e46e
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4618
diff changeset
9 package org.dive4elements.river.artifacts.model;
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import java.util.HashMap;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import java.util.Map;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import java.util.Set;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import java.util.TreeMap;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4618
diff changeset
18 import org.dive4elements.river.artifacts.math.Linear;
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20
7152
8c169743f4d0 Noted insights.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
21 /** Has to do with adaptive smoothing based on current diagram extent. */
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 public class ZoomScale
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7789
diff changeset
24 private static Logger log = Logger.getLogger(ZoomScale.class);
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 private HashMap<String, TreeMap<Double, Double>> rivers;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 public ZoomScale() {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 this.rivers = new HashMap<String, TreeMap<Double, Double>>();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 public ZoomScale(String river) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 this();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 rivers.put(river, new TreeMap<Double, Double>());
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 public double getRadius(String river, double lower, double upper) {
8609
421e5cceac84 (issue1754) Better fix for radius calculation then 8607:2010da0904b7
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
38 if (lower > upper) {
421e5cceac84 (issue1754) Better fix for radius calculation then 8607:2010da0904b7
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
39 double buf = lower;
421e5cceac84 (issue1754) Better fix for radius calculation then 8607:2010da0904b7
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
40 lower = upper;
421e5cceac84 (issue1754) Better fix for radius calculation then 8607:2010da0904b7
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
41 upper = buf;
421e5cceac84 (issue1754) Better fix for radius calculation then 8607:2010da0904b7
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
42 }
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 double range = Math.abs(upper) - Math.abs(lower);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 TreeMap<Double, Double> ranges = rivers.get(river);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 if (ranges == null) {
7789
fac461c67d24 Try to load default zoom scales if no zoom scale defined for the current river.
Raimund Renkert <rrenkert@intevation.de>
parents: 7152
diff changeset
46 TreeMap<Double, Double> defaultRanges = rivers.get("default");
fac461c67d24 Try to load default zoom scales if no zoom scale defined for the current river.
Raimund Renkert <rrenkert@intevation.de>
parents: 7152
diff changeset
47 if (defaultRanges == null) {
fac461c67d24 Try to load default zoom scales if no zoom scale defined for the current river.
Raimund Renkert <rrenkert@intevation.de>
parents: 7152
diff changeset
48 return 0.001;
fac461c67d24 Try to load default zoom scales if no zoom scale defined for the current river.
Raimund Renkert <rrenkert@intevation.de>
parents: 7152
diff changeset
49 }
fac461c67d24 Try to load default zoom scales if no zoom scale defined for the current river.
Raimund Renkert <rrenkert@intevation.de>
parents: 7152
diff changeset
50 ranges = defaultRanges;
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 Map.Entry<Double, Double> next = ranges.higherEntry(range);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 Map.Entry<Double, Double> prev = ranges.lowerEntry(range);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 double x0 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 double x1 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 double y0 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 double y1 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 if (prev == null && next != null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 x1 = next.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 y1 = next.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 else if (prev != null && next == null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 return prev.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 else {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 x0 = prev.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 x1 = next.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 y0 = prev.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 y1 = next.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 return Linear.linear(range, x0, x1, y0, y1);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 public void addRiver(String river) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 if (!this.rivers.containsKey(river)) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 this.rivers.put(river, new TreeMap<Double, Double>());
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 public Set<String> getRivers() {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 return this.rivers.keySet();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 public void addRange(String river, double range, double radius) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 if (this.rivers.containsKey(river)) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 this.rivers.get(river).put(range, radius);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 else {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 this.rivers.put(river, new TreeMap<Double, Double>());
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 this.rivers.get(river).put(range, radius);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 }

http://dive4elements.wald.intevation.org