Skip to content

Commit 1838ebb

Browse files
committed
Fix shape using y instead of z coordinates
1 parent 745192e commit 1838ebb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/main/java/de/bluecolored/bluemap/api/gson/MarkerGson.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public Line read(JsonReader in) throws IOException {
134134
}
135135

136136
static class ShapeAdapter extends TypeAdapter<Shape> {
137-
private static final Vector2dAdapter VEC2D_ADAPTER = new Vector2dAdapter();
137+
private static final Vector2dAdapter VEC2D_ADAPTER = new Vector2dAdapter(true);
138138

139139
@Override
140140
public void write(JsonWriter out, Shape value) throws IOException {
@@ -217,6 +217,16 @@ public Color read(JsonReader in) throws IOException {
217217

218218
static class Vector2dAdapter extends TypeAdapter<Vector2d> {
219219

220+
private final boolean useZ;
221+
222+
public Vector2dAdapter() {
223+
this.useZ = false;
224+
}
225+
226+
public Vector2dAdapter(boolean useZ) {
227+
this.useZ = useZ;
228+
}
229+
220230
@Override
221231
public void write(JsonWriter out, Vector2d value) throws IOException {
222232
if (value == null) {
@@ -226,7 +236,7 @@ public void write(JsonWriter out, Vector2d value) throws IOException {
226236

227237
out.beginObject();
228238
out.name("x"); out.value(value.getX());
229-
out.name("y"); out.value(value.getY());
239+
out.name(useZ ? "z" : "y"); out.value(value.getY());
230240
out.endObject();
231241
}
232242

@@ -242,7 +252,8 @@ public Vector2d read(JsonReader in) throws IOException {
242252
while (in.peek() != JsonToken.END_OBJECT) {
243253
switch (in.nextName()) {
244254
case "x" : x = in.nextDouble(); break;
245-
case "y" : y = in.nextDouble(); break;
255+
case "y" : if (!useZ) y = in.nextDouble(); else in.skipValue(); break;
256+
case "z" : if (useZ) y = in.nextDouble(); else in.skipValue(); break;
246257
default : in.skipValue(); break;
247258
}
248259
}

0 commit comments

Comments
 (0)