source: osm/applications/editors/josm/plugins/smed2/src/seamap/Renderer.java@ 29198

Last change on this file since 29198 was 29198, checked in by malcolmh, 14 years ago

save

File size: 4.1 KB
Line 
1/* Copyright 2013 Malcolm Herring
2 *
3 * This is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License.
6 *
7 * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.
8 */
9
10package seamap;
11
12import java.awt.Graphics2D;
13import java.awt.RenderingHints;
14import java.awt.geom.Point2D;
15import java.util.ArrayList;
16import java.util.HashMap;
17
18import s57.S57att.Att;
19import s57.S57obj.Obj;
20import s57.S57val.*;
21import s57.S57val;
22import seamap.SeaMap.*;
23import symbols.Symbols;
24import symbols.Symbols.*;
25
26public class Renderer {
27
28 static MapHelper helper;
29 static SeaMap map;
30 static double sScale;
31 static double tScale;
32 static Graphics2D g2;
33
34 public static void reRender(Graphics2D g, int zoom, double factor, SeaMap m, MapHelper h) {
35 g2 = g;
36 helper = h;
37 map = m;
38 sScale = Symbols.symbolScale[zoom]*factor;
39 tScale = Symbols.textScale[zoom]*factor;
40 if (map != null) {
41 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
42 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
43 Rules.rules(map, zoom);
44 }
45 }
46
47 public static AttMap getAtts(Feature feature, Obj obj, int idx) {
48 HashMap<Integer, AttMap> objs = feature.objs.get(obj);
49 if (objs == null) return null;
50 else return objs.get(idx);
51 }
52
53 public static Object getAttVal(Feature feature, Obj obj, int idx, Att att) {
54 AttMap atts = getAtts(feature, obj, idx);
55 if (atts == null) return S57val.nullVal(att);
56 else {
57 AttItem item = atts.get(att);
58 if (item == null) return S57val.nullVal(att);
59 return item.val;
60 }
61 }
62
63 public static double calcArea(Feature feature) {
64 if (feature.flag == Fflag.AREA) {
65 ArrayList<Long> way = map.ways.get(feature.refs);
66 Coord coord = map.nodes.get(way.get(0));
67 double llon = coord.lon;
68 double llat = coord.lat;
69 double sigma = 0.0;
70 for (long node : way) {
71 coord = map.nodes.get(node);
72 double lat = coord.lat;
73 double lon = coord.lon;
74 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat));
75 llon = lon;
76 llat = lat;
77 }
78 return Math.abs(sigma) * 3444 * 3444 / 2.0;
79 }
80 return 0.0;
81 }
82
83 public static Coord findCentroid(Feature feature) {
84 Coord coord;
85 ArrayList<Long> way = map.ways.get(feature.refs);
86 switch (feature.flag) {
87 case NODE:
88 return map.nodes.get(feature.refs);
89 case WAY:
90 coord = map.nodes.get(way.get(1));
91 break;
92 case AREA:
93 default:
94 coord = map.nodes.get(way.get(0));
95 }
96 double slat = 0.0;
97 double slon = 0.0;
98 double sarc = 0.0;
99 double llat = coord.lat;
100 double llon = coord.lon;
101 for (long node : way) {
102 coord = map.nodes.get(node);
103 double lon = coord.lon;
104 double lat = coord.lat;
105 double arc = (Math.acos(Math.cos(lon-llon) * Math.cos(lat-llat)));
106 slat += (lat * arc);
107 slon += (lon * arc);
108 sarc += arc;
109 llat = lat;
110 llon = lon;
111 }
112 return map.new Coord((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0));
113 }
114
115 public static void symbol(Feature feature, Symbol symbol, Obj obj, Delta delta) {
116 Point2D point = helper.getPoint(findCentroid(feature));
117 ArrayList<ColCOL> colours = (ArrayList<ColCOL>) getAttVal(feature, obj, 0, Att.COLOUR);
118 ArrayList<ColPAT> pattern = (ArrayList<ColPAT>) getAttVal(feature, obj, 0, Att.COLPAT);
119 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), delta, new Scheme(pattern, colours));
120 }
121
122 public static void lineSymbols(Feature feature, Symbol prisymb, double space, Symbol secsymb, int ratio) {
123 if (feature.flag != Fflag.NODE) {
124 ArrayList<Long> way = map.ways.get(feature.refs);
125 for (long node : way) {
126 Point2D point = helper.getPoint(map.nodes.get(node));
127
128 }
129 }
130 }
131
132 public static void lineVector (Feature feature, LineStyle style) {
133
134 }
135
136 public static void labelText (Feature feature, String str, TextStyle style, Delta delta) {
137
138 }
139
140 public static void lineText (Feature feature, String str, TextStyle style, double offset, Delta delta) {
141
142 }
143}
Note: See TracBrowser for help on using the repository browser.