Changeset 4318 in josm for trunk/src/org
- Timestamp:
- 2011-08-15T18:53:30+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r4180 r4318 24 24 private boolean drawMultipolygon; 25 25 26 private int cacheIdx; 26 private int cacheIdx = 1; 27 28 private boolean defaultNodes, defaultLines; 29 private int defaultNodesIdx, defaultLinesIdx; 27 30 28 31 public ElemStyles() … … 39 42 } 40 43 44 /** 45 * Create the list of styles for one primitive. 46 * 47 * @param osm the primitive 48 * @param scale the scale (in meters per 100 pixel) 49 * @param nc 50 * @return 51 */ 41 52 public StyleList get(OsmPrimitive osm, double scale, NavigatableComponent nc) { 42 53 return getStyleCacheWithRange(osm, scale, nc).a; 43 54 } 44 55 56 /** 57 * Create the list of styles and its valid scale range for one primitive. 58 * 59 * Automatically adds default styles in case no proper style was found. 60 * Uses the cache, if possible, and saves the results to the cache. 61 */ 45 62 public Pair<StyleList, Range> getStyleCacheWithRange(OsmPrimitive osm, double scale, NavigatableComponent nc) { 46 63 if (osm.mappaintStyle == null || osm.mappaintCacheIdx != cacheIdx) { … … 52 69 } 53 70 Pair<StyleList, Range> p = getImpl(osm, scale, nc); 54 if (osm instanceof Node ) {71 if (osm instanceof Node && isDefaultNodes()) { 55 72 boolean hasNonModifier = false; 56 73 for (ElemStyle s : p.a) { … … 63 80 p.a = new StyleList(p.a, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE); 64 81 } 65 } else if (osm instanceof Way ) {82 } else if (osm instanceof Way && isDefaultLines()) { 66 83 boolean hasProperLineStyle = false; 67 84 for (ElemStyle s : p.a) { … … 73 90 if (!hasProperLineStyle) { 74 91 AreaElemStyle area = Utils.find(p.a, AreaElemStyle.class); 75 LineElemStyle line = (area == null ? LineElemStyle.UNTAGGED_WAY : LineElemStyle.createSimpleLineStyle(area.color, true)); 92 LineElemStyle line = null; 93 line = (area == null ? LineElemStyle.UNTAGGED_WAY : LineElemStyle.createSimpleLineStyle(area.color, true)); 76 94 p.a = new StyleList(p.a, line); 77 95 } … … 82 100 } 83 101 102 /** 103 * Create the list of styles and its valid scale range for one primitive. 104 * 105 * This method does multipolygon handling. 106 * 107 * 108 * There are different tagging styles for multipolygons, that have to be respected: 109 * - tags on the relation 110 * - tags on the outer way 111 * - tags on both, the outer and the inner way (very old style) 112 * 113 * If the primitive is a way, look for multipolygon parents. In case it 114 * is indeed member of some multipolygon as role "outer", all area styles 115 * are removed. (They apply to the multipolygon area.) 116 * Outer ways can have their own independent line styles, e.g. a road as 117 * boundary of a forest. Otherwise, in case, the way does not have an 118 * independent line style, take a line style from the multipolygon. 119 * If the multipolygon does not have a line style either, at least create a 120 * default line style from the color of the area. 121 * 122 * Now consider the case that the way is not an outer way of any multipolygon, 123 * but is member of a multipolygon as "inner". 124 * First, the style list is regenerated, considering only tags of this way 125 * minus the tags of outer way of the multipolygon (to care for the "very 126 * old style"). 127 * Then check, if the way describes something in its own right. (linear feature 128 * or area) If not, add a default line style from the area color of the multipolygon. 129 * 130 */ 84 131 private Pair<StyleList, Range> getImpl(OsmPrimitive osm, double scale, NavigatableComponent nc) { 85 132 if (osm instanceof Node) … … 131 178 p.b = Range.cut(p.b, mpElemStyles.b); 132 179 break; 133 } else if (wayColor == null ) {180 } else if (wayColor == null && isDefaultLines()) { 134 181 AreaElemStyle mpArea = Utils.find(mpElemStyles.a, AreaElemStyle.class); 135 182 if (mpArea != null) { … … 142 189 } 143 190 if (isOuterWayOfSomeMP) { 144 boolean hasLineStyle = false; 145 for (ElemStyle s : p.a) { 146 if (s.isProperLineStyle()) { 147 hasLineStyle = true; 148 break; 149 } 150 } 151 if (!hasLineStyle) { 152 p.a = new StyleList(p.a, LineElemStyle.createSimpleLineStyle(wayColor, true)); 191 if (isDefaultLines()) { 192 boolean hasLineStyle = false; 193 for (ElemStyle s : p.a) { 194 if (s.isProperLineStyle()) { 195 hasLineStyle = true; 196 break; 197 } 198 } 199 if (!hasLineStyle) { 200 p.a = new StyleList(p.a, LineElemStyle.createSimpleLineStyle(wayColor, true)); 201 } 153 202 } 154 203 return p; 155 204 } 205 206 if (!isDefaultLines()) return p; 156 207 157 208 for (OsmPrimitive referrer : osm.getReferrers()) { … … 213 264 214 265 /** 266 * Create the list of styles and its valid scale range for one primitive. 267 * 268 * Loops over the list of style sources, to generate the map of properties. 269 * From these properties, it generates the different types of styles. 270 * 215 271 * @param multipolyOuterWay support for a very old multipolygon tagging style 216 272 * where you add the tags both to the outer and the inner way. … … 268 324 } 269 325 326 /** 327 * Draw a default node symbol for nodes that have no style? 328 */ 329 private boolean isDefaultNodes() { 330 if (defaultNodesIdx == cacheIdx) { 331 return defaultNodes; 332 } 333 defaultNodes = fromCanvas("default-points", true, Boolean.class); 334 defaultNodesIdx = cacheIdx; 335 return defaultNodes; 336 } 337 338 /** 339 * Draw a default line for ways that do not have an own line style? 340 */ 341 private boolean isDefaultLines() { 342 if (defaultLinesIdx == cacheIdx) { 343 return defaultLines; 344 } 345 defaultLines = fromCanvas("default-lines", true, Boolean.class); 346 defaultLinesIdx = cacheIdx; 347 return defaultLines; 348 } 349 350 private <T> T fromCanvas(String key, T def, Class<T> c) { 351 MultiCascade mc = new MultiCascade(); 352 Relation r = new Relation(); 353 r.put("#canvas", "query"); 354 355 for (StyleSource s : styleSources) { 356 if (s.active) { 357 s.apply(mc, r, 1, null, false); 358 } 359 } 360 T res = mc.getCascade("default").get(key, def, c); 361 return res; 362 } 363 270 364 public boolean isDrawMultipolygon() { 271 365 return drawMultipolygon; -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r4272 r4318 164 164 } 165 165 166 private static NodeElemStyle create(Environment env, boolean allow OnlyText) {166 private static NodeElemStyle create(Environment env, boolean allowDefault) { 167 167 initDefaultParameters(); 168 168 Cascade c = env.mc.getCascade(env.layer); … … 175 175 176 176 NodeTextElement text = null; 177 TextElement te = TextElement.create(c, DEFAULT_TEXT_COLOR, symbol == null && icon == null );177 TextElement te = TextElement.create(c, DEFAULT_TEXT_COLOR, symbol == null && icon == null && allowDefault); 178 178 // optimization: if we neither have a symbol, nor an icon, nor a text element 179 179 // we don't have to check for the remaining style properties and we don't -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r4191 r4318 265 265 266 266 public boolean matchesBase(Environment e){ 267 if (base.equals("*")) 268 return true; 269 if (base.equals("area")) { 270 if (e.osm instanceof Way) 267 if (e.osm instanceof Node) { 268 return base.equals("node") || base.equals("*"); 269 } else if (e.osm instanceof Way) { 270 return base.equals("way") || base.equals("area") || base.equals("*"); 271 } else if (e.osm instanceof Relation) { 272 if (base.equals("area")) { 273 return ((Relation) e.osm).isMultipolygon(); 274 } else if (base.equals("relation")) { 271 275 return true; 272 if (e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon()) 273 return true; 274 } 275 if (base.equals(OsmPrimitiveType.from(e.osm).getAPIName())) 276 return true; 276 } else if (base.equals("canvas")) { 277 return e.osm.get("#canvas") != null; 278 } 279 } 277 280 return false; 278 281 }
Note:
See TracChangeset
for help on using the changeset viewer.