Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/ZoomScale.java @ 8202:e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 12:58:17 +0200 |
parents | fac461c67d24 |
children | 421e5cceac84 |
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) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 } |
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
|
45 ranges = defaultRanges; |
4618
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 } |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 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
|
48 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
|
49 double x0 = 0d; |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 double x1 = 0d; |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
51 double y0 = 0d; |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
52 double y1 = 0d; |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
53 if (prev == null && next != null) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 x1 = next.getKey(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
55 y1 = next.getValue(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 } |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 else if (prev != null && next == null) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 return prev.getValue(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
59 } |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
60 else { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
61 x0 = prev.getKey(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
62 x1 = next.getKey(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
63 y0 = prev.getValue(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 y1 = next.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 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
|
67 } |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 public void addRiver(String river) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
70 if (!this.rivers.containsKey(river)) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
71 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
|
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 |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
75 public Set<String> getRivers() { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
76 return this.rivers.keySet(); |
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 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
|
80 if (this.rivers.containsKey(river)) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
81 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
|
82 } |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 else { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
84 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
|
85 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
|
86 } |
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 } |