source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java@ 627

Last change on this file since 627 was 627, checked in by framm, 16 years ago
  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1package org.openstreetmap.josm.gui.mappaint;
2
3import java.util.HashMap;
4import java.util.Iterator;
5
6import org.openstreetmap.josm.data.osm.OsmPrimitive;
7public class ElemStyles
8{
9 HashMap<String, ElemStyle> styles;
10 static int nr = 0;
11
12
13 public ElemStyles()
14 {
15 styles = new HashMap<String, ElemStyle>();
16 }
17
18 public void add (String k, String v, ElemStyle style)
19 {
20 ElemStyle old_style;
21 String key = k + "=" + v;
22
23 /* unfortunately, there don't seem to be an efficient way to */
24 /* find out, if a given OsmPrimitive is an area or not, */
25 /* so distinguish only between way and node here - for now */
26 if(style instanceof AreaElemStyle) {
27 key = key + "way";
28 }
29 else if(style instanceof LineElemStyle) {
30 key = key + "way";
31 }
32 else if(style instanceof IconElemStyle) {
33 key = key + "node";
34 }
35 /* avoid duplicates - for now */
36 old_style = styles.get(key);
37 if(old_style == null) {
38 /* new key/value, insert */
39 styles.put(key, style);
40 } else {
41 if(style.getMaxScale() < old_style.getMaxScale()) {
42 /* existing larger scale key/value, replace */
43 styles.remove(old_style);
44 styles.put(key, style);
45 }
46 }
47 }
48
49 public ElemStyle getStyle (OsmPrimitive p)
50 {
51 if(p.keys!=null)
52 {
53 String classname;
54 String kv = null;
55
56 if(p instanceof org.openstreetmap.josm.data.osm.Node) {
57 classname = "node";
58 } else {
59 classname = "way";
60 }
61 Iterator<String> iterator = p.keys.keySet().iterator();
62 while(iterator.hasNext())
63 {
64 String key = iterator.next();
65 kv = key + "=" + p.keys.get(key) + classname;
66 if(styles.containsKey(kv))
67 {
68 return styles.get(kv);
69 }
70 }
71
72 // not a known key/value combination
73 boolean first_line = true;
74
75 // filter out trivial tags and show the rest
76 iterator = p.keys.keySet().iterator();
77 while(iterator.hasNext())
78 {
79 String key = iterator.next();
80 kv = key + "=" + p.keys.get(key);
81 if( !kv.startsWith("created_by=") &&
82 !kv.startsWith("converted_by=") &&
83 !kv.startsWith("source=") &&
84 !kv.startsWith("note=") &&
85 !kv.startsWith("layer=") &&
86 !kv.startsWith("bridge=") &&
87 !kv.startsWith("tunnel=") &&
88 !kv.startsWith("oneway=") &&
89 !kv.startsWith("speedlimit=") &&
90 !kv.startsWith("motorcar=") &&
91 !kv.startsWith("horse=") &&
92 !kv.startsWith("bicycle=") &&
93 !kv.startsWith("foot=")
94 ) {
95
96 if (first_line) {
97 nr++;
98 //System.out.println("mappaint - rule not found[" + nr + "]: " + kv + " id:" + p.id);
99 } else {
100 //System.out.println("mappaint - rule not found[" + nr + "]: " + kv);
101 }
102 first_line=false;
103 }
104 }
105 }
106
107 return null;
108 }
109
110 public boolean isArea(OsmPrimitive p)
111 {
112 return getStyle(p) instanceof AreaElemStyle;
113 }
114}
Note: See TracBrowser for help on using the repository browser.