revisited due to GWT buggy

This commit is contained in:
Francesco Mangiacrapa 2022-10-14 17:18:35 +02:00
parent ae92ea0c3d
commit c1cc4f391a
1 changed files with 133 additions and 83 deletions

View File

@ -2,9 +2,9 @@ package org.gcube.application.geoportalcommon.shared.geoportal.materialization.i
import java.util.HashMap; import java.util.HashMap;
public class BBOXDV extends HashMap<String,Double>{ public class BBOXDV extends HashMap<String, Double> {
/** /**
* *
*/ */
private static final long serialVersionUID = -160255589938251081L; private static final long serialVersionUID = -160255589938251081L;
@ -12,98 +12,148 @@ public class BBOXDV extends HashMap<String,Double>{
public BBOXDV() { public BBOXDV() {
} }
public final String asGeoJSONBBox(){ public final String asGeoJSONBBox() {
StringBuilder builder = new StringBuilder("["); StringBuilder builder = new StringBuilder("[");
builder.append(getMaxX()+","); // W builder.append(getMaxX() + ","); // W
builder.append(getMinY()+","); // S builder.append(getMinY() + ","); // S
if(is3d()) builder.append(getMinZ()+","); // Z if (is3d())
builder.append(getMinZ() + ","); // Z
builder.append(getMinX()+","); // E builder.append(getMinX() + ","); // E
builder.append(getMaxY()+","); // N builder.append(getMaxY() + ","); // N
if(is3d()) builder.append(getMaxZ()+","); // Z if (is3d())
builder.append(getMaxZ() + ","); // Z
builder.deleteCharAt(builder.length());
builder.append("]");
return builder.toString();
}
builder.deleteCharAt(builder.length()); public double[] asGeoJSONArray() {
builder.append("]"); if (is3d()) {
return builder.toString(); return new double[] { getMaxX(), getMinY(), getMinZ(), getMinX(), getMaxY(), getMaxZ() };
} } else
public double[] asGeoJSONArray(){ return new double[] { getMaxX(), getMinY(), getMinX(), getMaxY() };
if(is3d()){ }
return new double[]{getMaxX(),getMinY(),getMinZ(),getMinX(),getMaxY(),getMaxZ()};
}else return new double[]{getMaxX(),getMinY(),getMinX(),getMaxY()};
}
public static final BBOXDV fromGeoJSON(double[] coords){ public static final BBOXDV fromGeoJSON(double[] coords) {
BBOXDV toReturn = new BBOXDV(); BBOXDV toReturn = new BBOXDV();
toReturn.setMaxX(coords[0]); toReturn.setMaxX(coords[0]);
toReturn.setMinY(coords[1]); toReturn.setMinY(coords[1]);
if(coords.length == 6){ if (coords.length == 6) {
// 3D // 3D
toReturn.setMinZ(coords[2]); toReturn.setMinZ(coords[2]);
toReturn.setMinX(coords[3]); toReturn.setMinX(coords[3]);
toReturn.setMaxY(coords[4]); toReturn.setMaxY(coords[4]);
toReturn.setMaxZ(coords[5]); toReturn.setMaxZ(coords[5]);
}else { } else {
toReturn.setMinX(coords[2]); toReturn.setMinX(coords[2]);
toReturn.setMaxY(coords[3]); toReturn.setMaxY(coords[3]);
} }
return toReturn; return toReturn;
} }
public static final BBOXDV WORLD=new BBOXDV(180d,-180d,90d,-90d); public static final BBOXDV WORLD = new BBOXDV(180d, -180d, 90d, -90d);
public static final BBOXDV WORLD_3D=new BBOXDV(180d,-180d,90d,-90d); public static final BBOXDV WORLD_3D = new BBOXDV(180d, -180d, 90d, -90d);
public static final String MAX_X="_maxX"; public static final String MAX_X = "_maxX";
public static final String MAX_Y="_maxY"; public static final String MAX_Y = "_maxY";
public static final String MAX_Z="_maxZ"; public static final String MAX_Z = "_maxZ";
public static final String MIN_X="_minX"; public static final String MIN_X = "_minX";
public static final String MIN_Y="_minY"; public static final String MIN_Y = "_minY";
public static final String MIN_Z="_minZ"; public static final String MIN_Z = "_minZ";
public BBOXDV(Double maxX, Double minX, Double maxY, Double minY, Double maxZ, Double minZ) {
this(maxX, minX, maxY, minY);
setMaxZ(maxZ);
setMinZ(minZ);
}
public BBOXDV(Double maxX,Double minX,Double maxY,Double minY,Double maxZ,Double minZ){ public BBOXDV(Double maxX, Double minX, Double maxY, Double minY) {
this(maxX,minX,maxY,minY); setMaxX(maxX);
setMaxZ(maxZ); setMinX(minX);
setMinZ(minZ); setMaxY(maxY);
} setMinY(minY);
public BBOXDV(Double maxX,Double minX,Double maxY,Double minY){ }
setMaxX(maxX);
setMinX(minX);
setMaxY(maxY);
setMinY(minY);
}
public BBOXDV setMaxX(Double d) {
public BBOXDV setMaxX(Double d){this.put(MAX_X,d);return this;} this.put(MAX_X, d);
return this;
public BBOXDV setMaxY(Double d){this.put(MAX_Y,d);return this;} }
public BBOXDV setMaxZ(Double d){this.put(MAX_Z,d);return this;}
public BBOXDV setMinX(Double d){this.put(MIN_X,d);return this;}
public BBOXDV setMinY(Double d){this.put(MIN_Y,d);return this;}
public BBOXDV setMinZ(Double d){this.put(MIN_Z,d);return this;}
public Double getMinY(){return (Double) this.getOrDefault(MIN_Y,-90d);}
public Double getMaxY(){return (Double) this.getOrDefault(MAX_Y,90d);}
public Double getMinX(){return (Double) this.getOrDefault(MIN_X,-180d);}
public Double getMaxX(){return (Double) this.getOrDefault(MAX_X,180d);}
public Double getMinZ(){return (Double) this.getOrDefault(MIN_Z,null);}
public Double getMaxZ(){return (Double) this.getOrDefault(MAX_Z,null);}
public BBOXDV setMaxY(Double d) {
public Boolean is3d(){ this.put(MAX_Y, d);
return getMinZ()!=null && getMaxZ() !=null; return this;
} }
public BBOXDV setMaxZ(Double d) {
this.put(MAX_Z, d);
return this;
}
public BBOXDV setMinX(Double d) {
this.put(MIN_X, d);
return this;
}
public BBOXDV setMinY(Double d) {
this.put(MIN_Y, d);
return this;
}
public BBOXDV setMinZ(Double d) {
this.put(MIN_Z, d);
return this;
}
public Double getMinY() {
try {
return Double.valueOf(this.get(MIN_Y));
} catch (Exception e) {
}
return new Double(-90d);
}
public Double getMaxY() {
try {
return Double.valueOf(this.get(MAX_Y));
} catch (Exception e) {
}
return new Double(90d);
}
public Double getMinX() {
try {
return Double.valueOf(this.get(MIN_X));
} catch (Exception e) {
}
return new Double(-180d);
}
public Double getMaxX() {
try {
return Double.valueOf(this.get(MAX_X));
} catch (Exception e) {
}
return new Double(180d);
}
public Double getMinZ() {
return (Double) this.getOrDefault(MIN_Z, null);
}
public Double getMaxZ() {
return (Double) this.getOrDefault(MAX_Z, null);
}
public Boolean is3d() {
return getMinZ() != null && getMaxZ() != null;
}
} }