annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/ZoomScale.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
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
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8609
diff changeset
16 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8609
diff changeset
17 import org.apache.logging.log4j.LogManager;
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4618
diff changeset
19 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
20
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21
7152
8c169743f4d0 Noted insights.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
22 /** 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
23 public class ZoomScale
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 {
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8609
diff changeset
25 private static Logger log = LogManager.getLogger(ZoomScale.class);
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 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
28
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 public ZoomScale() {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 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
31 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 public ZoomScale(String river) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 this();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 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
36 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 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
39 if (lower > upper) {
421e5cceac84 (issue1754) Better fix for radius calculation then 8607:2010da0904b7
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
40 double buf = lower;
421e5cceac84 (issue1754) Better fix for radius calculation then 8607:2010da0904b7
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
41 lower = upper;
421e5cceac84 (issue1754) Better fix for radius calculation then 8607:2010da0904b7
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
42 upper = buf;
421e5cceac84 (issue1754) Better fix for radius calculation then 8607:2010da0904b7
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8202
diff changeset
43 }
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 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
45 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
46 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
47 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
48 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
49 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
50 }
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
51 ranges = defaultRanges;
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 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
54 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
55 double x0 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 double x1 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 double y0 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 double y1 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 if (prev == null && next != null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 x1 = next.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 y1 = next.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 else if (prev != null && next == null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 return prev.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 else {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 x0 = prev.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 x1 = next.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 y0 = prev.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 y1 = next.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 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
73 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 public void addRiver(String river) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 if (!this.rivers.containsKey(river)) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 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
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
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 public Set<String> getRivers() {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 return this.rivers.keySet();
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
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 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
86 if (this.rivers.containsKey(river)) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 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
88 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 else {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 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
91 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
92 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
94 }

http://dive4elements.wald.intevation.org