Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/ZoomScale.java @ 7027:21064459dc5d
Doc.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 16 Sep 2013 17:29:16 +0200 |
parents | af13ceeba52a |
children | 8c169743f4d0 |
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 |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 public class ZoomScale |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 private static Logger logger = Logger.getLogger(ZoomScale.class); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
25 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
|
26 |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
27 public ZoomScale() { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 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
|
29 } |
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 public ZoomScale(String river) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
32 this(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
33 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
|
34 } |
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 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
|
37 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
|
38 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
|
39 if (ranges == null) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 return 0.001; |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
41 } |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 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
|
43 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
|
44 double x0 = 0d; |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
45 double x1 = 0d; |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 double y0 = 0d; |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 double y1 = 0d; |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 if (prev == null && next != null) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 x1 = next.getKey(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 y1 = next.getValue(); |
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 else if (prev != null && next == null) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
53 return prev.getValue(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 } |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
55 else { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 x0 = prev.getKey(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 x1 = next.getKey(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 y0 = prev.getValue(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
59 y1 = next.getValue(); |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
60 } |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
61 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
|
62 } |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
63 |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 public void addRiver(String river) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
65 if (!this.rivers.containsKey(river)) { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 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
|
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 |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
70 public Set<String> getRivers() { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
71 return this.rivers.keySet(); |
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 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
|
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.get(river).put(range, radius); |
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 else { |
e8c6fbed889b
New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
79 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
|
80 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
|
81 } |
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 } |