Changeset 14484 in josm for trunk/src/org/openstreetmap/josm/data/osm
- Timestamp:
- 2018-12-02T02:32:13+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java
r14238 r14484 113 113 114 114 /** 115 * Creates a new OSM primitive according to the given assertion. Originally written for unit tests, 115 * Creates a new OSM primitive around (0,0) according to the given assertion. Originally written for unit tests, 116 116 * this can also be used in another places like validation of local MapCSS validator rules. 117 117 * @param assertion The assertion describing OSM primitive (ex: "way name=Foo railway=rail") … … 121 121 */ 122 122 public static OsmPrimitive createPrimitive(String assertion) { 123 return createPrimitive(assertion, LatLon.ZERO); 124 } 125 126 /** 127 * Creates a new OSM primitive according to the given assertion. Originally written for unit tests, 128 * this can also be used in another places like validation of local MapCSS validator rules. 129 * @param assertion The assertion describing OSM primitive (ex: "way name=Foo railway=rail") 130 * @param around the coordinate at which the primitive will be located 131 * @return a new OSM primitive according to the given assertion 132 * @throws IllegalArgumentException if assertion is null or if the primitive type cannot be deduced from it 133 * @since 14484 134 */ 135 public static OsmPrimitive createPrimitive(String assertion, LatLon around) { 123 136 CheckParameterUtil.ensureParameterNotNull(assertion, "assertion"); 124 137 final String[] x = assertion.split("\\s+", 2); 125 138 final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0]) 126 ? new Node( LatLon.ZERO)139 ? new Node(around) 127 140 : "w".equals(x[0]) || "way".equals(x[0]) || /*for MapCSS related usage*/ "area".equals(x[0]) 128 ? new Way()141 ? newWay(around) 129 142 : "r".equals(x[0]) || "relation".equals(x[0]) 130 ? new 143 ? newRelation(around) 131 144 : null; 132 145 if (p == null) { … … 139 152 } 140 153 return p; 154 } 155 156 private static Node newNode(LatLon around) { 157 return new Node(around); 158 } 159 160 private static Way newWay(LatLon around) { 161 Way w = new Way(); 162 w.addNode(newNode(new LatLon(around.lat()+0.1, around.lon()))); 163 w.addNode(newNode(new LatLon(around.lat()-0.1, around.lon()))); 164 return w; 165 } 166 167 private static Relation newRelation(LatLon around) { 168 Relation r = new Relation(); 169 r.addMember(new RelationMember(null, newNode(around))); 170 return r; 141 171 } 142 172
Note:
See TracChangeset
for help on using the changeset viewer.