- Timestamp:
- 2021-07-13T22:49:09+02:00 (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/style/MapboxVectorStyle.java
r17990 r18011 17 17 import java.util.List; 18 18 import java.util.Map; 19 import java.util.Map.Entry; 19 20 import java.util.Objects; 20 21 import java.util.Optional; … … 24 25 import javax.imageio.ImageIO; 25 26 import javax.json.Json; 26 import javax.json.JsonArray;27 27 import javax.json.JsonObject; 28 28 import javax.json.JsonReader; 29 import javax.json.JsonStructure;30 29 import javax.json.JsonValue; 31 30 … … 60 59 BufferedReader reader = style.getContentReader(); 61 60 JsonReader jsonReader = Json.createReader(reader)) { 62 JsonStructure structure = jsonReader.read(); 63 return new MapboxVectorStyle(structure.asJsonObject()); 61 return new MapboxVectorStyle(jsonReader.read().asJsonObject()); 64 62 } catch (IOException e) { 65 63 Logging.error(e); … … 100 98 final List<Source> sourceList; 101 99 if (jsonObject.containsKey("sources") && jsonObject.get("sources").getValueType() == JsonValue.ValueType.OBJECT) { 102 final JsonObject sourceObj = jsonObject.getJsonObject("sources");103 sourceList = sourceObj.entrySet().stream().filter(entry -> entry.getValue().getValueType() == JsonValue.ValueType.OBJECT)100 sourceList = jsonObject.getJsonObject("sources").entrySet().stream() 101 .filter(entry -> entry.getValue().getValueType() == JsonValue.ValueType.OBJECT) 104 102 .map(entry -> { 105 103 try { … … 119 117 final List<Layers> layers; 120 118 if (jsonObject.containsKey("layers") && jsonObject.get("layers").getValueType() == JsonValue.ValueType.ARRAY) { 121 JsonArray lArray = jsonObject.getJsonArray("layers");122 layers = lArray.stream().filter(JsonObject.class::isInstance).map(JsonObject.class::cast).map(obj -> new Layers(id, obj))119 layers = jsonObject.getJsonArray("layers").stream() 120 .filter(JsonObject.class::isInstance).map(JsonObject.class::cast).map(obj -> new Layers(id, obj)) 123 121 .collect(Collectors.toList()); 124 122 } else { … … 130 128 // Abuse HashMap null (null == default) 131 129 this.sources = new LinkedHashMap<>(); 132 for ( Map.Entry<Optional<Source>, List<Layers>> entry : sourceLayer.entrySet()) {130 for (Entry<Optional<Source>, List<Layers>> entry : sourceLayer.entrySet()) { 133 131 final Source source = entry.getKey().orElse(null); 134 132 final String data = entry.getValue().stream().map(Layers::toString).collect(Collectors.joining()); … … 159 157 // HiDPI images first -- if this succeeds, don't bother with the lower resolution (JOSM has no method to switch) 160 158 try (CachedFile spriteJson = new CachedFile(this.spriteUrl + "@2x.json"); 161 CachedFile spritePng = new CachedFile(this.spriteUrl + "@2x.png")) {159 CachedFile spritePng = new CachedFile(this.spriteUrl + "@2x.png")) { 162 160 if (parseSprites(spriteJson, spritePng)) { 163 161 return; … … 165 163 } 166 164 try (CachedFile spriteJson = new CachedFile(this.spriteUrl + ".json"); 167 CachedFile spritePng = new CachedFile(this.spriteUrl + ".png")) {165 CachedFile spritePng = new CachedFile(this.spriteUrl + ".png")) { 168 166 parseSprites(spriteJson, spritePng); 169 167 } … … 193 191 return false; 194 192 } 195 for ( Map.Entry<String, JsonValue> entry : spriteObject.entrySet()) {193 for (Entry<String, JsonValue> entry : spriteObject.entrySet()) { 196 194 final JsonObject info = entry.getValue().asJsonObject(); 197 195 int width = info.getInt("width"); … … 218 216 } 219 217 final File toSave = new File(location, name); 218 Logging.debug("Saving {0} to {1}...", object.getClass().getSimpleName(), toSave); 220 219 try { 221 220 if (object instanceof BufferedImage) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r17994 r18011 95 95 static final Set<String> SUPPORTED_KEYS = new HashSet<>(); 96 96 static { 97 Field[] declaredFields = StyleKeys.class.getDeclaredFields(); 98 for (Field f : declaredFields) { 97 for (Field f : StyleKeys.class.getDeclaredFields()) { 99 98 try { 100 99 SUPPORTED_KEYS.add((String) f.get(null)); -
trunk/test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/style/MapboxVectorStyleTest.java
r17990 r18011 21 21 import java.util.ArrayList; 22 22 import java.util.Collection; 23 import java.util.List; 23 24 import java.util.Map; 24 25 import java.util.Objects; … … 127 128 MapCSSStyleSource styleSource2 = (MapCSSStyleSource) sources.get(source2).getStyleSources().get(0); 128 129 130 awaitSaveFinished(); 131 132 assertTrue(styleSource1.url.endsWith("source1.mapcss")); 133 assertTrue(styleSource2.url.endsWith("source2.mapcss")); 134 135 MapCSSStyleSource mapCSSStyleSource1 = new MapCSSStyleSource(styleSource1.url, styleSource1.name, styleSource1.title); 136 MapCSSStyleSource mapCSSStyleSource2 = new MapCSSStyleSource(styleSource2.url, styleSource2.name, styleSource2.title); 137 138 assertEquals(styleSource1, mapCSSStyleSource1); 139 assertEquals(styleSource2, mapCSSStyleSource2); 140 } 141 142 private static void awaitSaveFinished() { 129 143 AtomicBoolean saveFinished = new AtomicBoolean(); 130 144 MainApplication.worker.execute(() -> saveFinished.set(true)); 131 145 Awaitility.await().atMost(Durations.ONE_SECOND).until(saveFinished::get); 132 133 assertTrue(styleSource1.url.endsWith("source1.mapcss"));134 assertTrue(styleSource2.url.endsWith("source2.mapcss"));135 136 MapCSSStyleSource mapCSSStyleSource1 = new MapCSSStyleSource(styleSource1.url, styleSource1.name, styleSource1.title);137 MapCSSStyleSource mapCSSStyleSource2 = new MapCSSStyleSource(styleSource2.url, styleSource2.name, styleSource2.title);138 139 assertEquals(styleSource1, mapCSSStyleSource1);140 assertEquals(styleSource2, mapCSSStyleSource2);141 146 } 142 147 … … 165 170 assertEquals(spritePath, style.getSpriteUrl()); 166 171 167 AtomicBoolean saveFinished = new AtomicBoolean(); 168 MainApplication.worker.execute(() -> saveFinished.set(true)); 169 Awaitility.await().atMost(Durations.ONE_SECOND).until(saveFinished::get); 172 awaitSaveFinished(); 170 173 171 174 int scalar = 28; // 255 / 9 (could be 4, but this was a nicer number) … … 246 249 assertNotNull(mapillarySource, style.toString()); 247 250 mapillarySource.getStyleSources().forEach(StyleSource::loadStyleSource); 248 assertEquals(1, mapillarySource.getStyleSources().size()); 249 final MapCSSStyleSource mapillaryCssSource = (MapCSSStyleSource) mapillarySource.getStyleSources().get(0); 251 List<StyleSource> styleSources = mapillarySource.getStyleSources(); 252 assertEquals(1, styleSources.size()); 253 final MapCSSStyleSource mapillaryCssSource = (MapCSSStyleSource) styleSources.get(0); 254 255 awaitSaveFinished(); 256 250 257 assertTrue(mapillaryCssSource.getErrors().isEmpty(), mapillaryCssSource.getErrors().toString()); 251 258 final MapCSSRule mapillaryOverview = getRule(mapillaryCssSource, "node", "mapillary-overview");
Note:
See TracChangeset
for help on using the changeset viewer.