- Timestamp:
- 2021-03-16T21:56:55+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/importexport/GeoJSONExporter.java
r12806 r17570 11 11 12 12 import org.openstreetmap.josm.actions.ExtensionFileFilter; 13 import org.openstreetmap.josm.data.osm.DataSet; 13 14 import org.openstreetmap.josm.gui.layer.Layer; 14 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 35 36 public void exportData(File file, Layer layer) throws IOException { 36 37 if (layer instanceof OsmDataLayer) { 38 DataSet data = ((OsmDataLayer) layer).data; 37 39 try (Writer out = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) { 38 out.write(new GeoJSONWriter(((OsmDataLayer) layer).data).write());40 new GeoJSONWriter(data).write(true, out); 39 41 } 40 42 } else { -
trunk/src/org/openstreetmap/josm/io/GeoJSONWriter.java
r17320 r17570 4 4 import java.io.StringReader; 5 5 import java.io.StringWriter; 6 import java.io.Writer; 6 7 import java.math.BigDecimal; 7 8 import java.math.RoundingMode; … … 96 97 public String write(boolean pretty) { 97 98 StringWriter stringWriter = new StringWriter(); 99 write(pretty, stringWriter); 100 return stringWriter.toString(); 101 } 102 103 /** 104 * Writes OSM data as a GeoJSON string (prettified or not). 105 * @param pretty {@code true} to have pretty output, {@code false} otherwise 106 * @param writer The writer used to write results 107 */ 108 public void write(boolean pretty, Writer writer) { 98 109 Map<String, Object> config = Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, pretty); 99 try (JsonWriter writer = Json.createWriterFactory(config).createWriter(stringWriter)) {110 try (JsonWriter jsonWriter = Json.createWriterFactory(config).createWriter(writer)) { 100 111 JsonObjectBuilder object = Json.createObjectBuilder() 101 112 .add("type", "FeatureCollection") … … 103 114 appendLayerBounds(data, object); 104 115 appendLayerFeatures(data, object); 105 writer.writeObject(object.build()); 106 return stringWriter.toString(); 116 jsonWriter.writeObject(object.build()); 107 117 } 108 118 }
Note:
See TracChangeset
for help on using the changeset viewer.