From c4af58c1e1a8f54bdde2ecc7c13cb43b17555bc4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 11 Nov 2022 15:08:49 +0100 Subject: [PATCH] revisited BBOXDV --- .../materialization/innerobject/BBOXDV.java | 247 +++++++++--------- .../shared/geoportal/view/SectionView.java | 13 + 2 files changed, 138 insertions(+), 122 deletions(-) diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/materialization/innerobject/BBOXDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/materialization/innerobject/BBOXDV.java index d525990..8a3e62b 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/materialization/innerobject/BBOXDV.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/materialization/innerobject/BBOXDV.java @@ -1,18 +1,141 @@ package org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject; +import java.io.Serializable; import java.util.HashMap; -public class BBOXDV extends HashMap { +public class BBOXDV implements Serializable { /** * */ - private static final long serialVersionUID = -160255589938251081L; + private static final long serialVersionUID = -4438327945612263171L; + + public static final String MAX_X = "_maxX"; + public static final String MAX_Y = "_maxY"; + public static final String MAX_Z = "_maxZ"; + public static final String MIN_X = "_minX"; + public static final String MIN_Y = "_minY"; + public static final String MIN_Z = "_minZ"; + + public static final BBOXDV WORLD = new BBOXDV(180d, -180d, 90d, -90d); + + public static final BBOXDV WORLD_3D = new BBOXDV(180d, -180d, 90d, -90d); + + private HashMap bbox = new HashMap(); public BBOXDV() { } + public static final BBOXDV fromGeoJSON(double[] coords) { + BBOXDV toReturn = new BBOXDV(); + toReturn.setMaxX(coords[0]); + toReturn.setMinY(coords[1]); + + if (coords.length == 6) { + // 3D + toReturn.setMinZ(coords[2]); + toReturn.setMinX(coords[3]); + toReturn.setMaxY(coords[4]); + toReturn.setMaxZ(coords[5]); + } else { + toReturn.setMinX(coords[2]); + toReturn.setMaxY(coords[3]); + } + return toReturn; + } + + 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) { + setMaxX(maxX); + setMinX(minX); + setMaxY(maxY); + setMinY(minY); + } + + public BBOXDV setMaxX(Double d) { + this.bbox.put(MAX_X, d); + return this; + } + + public BBOXDV setMaxY(Double d) { + this.bbox.put(MAX_Y, d); + return this; + } + + public BBOXDV setMaxZ(Double d) { + this.bbox.put(MAX_Z, d); + return this; + } + + public BBOXDV setMinX(Double d) { + this.bbox.put(MIN_X, d); + return this; + } + + public BBOXDV setMinY(Double d) { + this.bbox.put(MIN_Y, d); + return this; + } + + public BBOXDV setMinZ(Double d) { + this.bbox.put(MIN_Z, d); + return this; + } + + public Double getMinY() { + try { + return Double.valueOf(this.bbox.get(MIN_Y)); + } catch (Exception e) { + + } + return new Double(-90d); + } + + public Double getMaxY() { + try { + return Double.valueOf(this.bbox.get(MAX_Y)); + } catch (Exception e) { + + } + return new Double(90d); + } + + public Double getMinX() { + try { + return Double.valueOf(this.bbox.get(MIN_X)); + } catch (Exception e) { + + } + return new Double(-180d); + } + + public Double getMaxX() { + try { + return Double.valueOf(this.bbox.get(MAX_X)); + } catch (Exception e) { + + } + return new Double(180d); + } + + public Double getMinZ() { + return (Double) this.bbox.getOrDefault(MIN_Z, null); + } + + public Double getMaxZ() { + return (Double) this.bbox.getOrDefault(MAX_Z, null); + } + + public Boolean is3d() { + return getMinZ() != null && getMaxZ() != null; + } + public final String asGeoJSONBBox() { StringBuilder builder = new StringBuilder("["); builder.append(getMaxX() + ","); // W @@ -36,124 +159,4 @@ public class BBOXDV extends HashMap { } else return new double[] { getMaxX(), getMinY(), getMinX(), getMaxY() }; } - - public static final BBOXDV fromGeoJSON(double[] coords) { - BBOXDV toReturn = new BBOXDV(); - toReturn.setMaxX(coords[0]); - toReturn.setMinY(coords[1]); - - if (coords.length == 6) { - // 3D - toReturn.setMinZ(coords[2]); - toReturn.setMinX(coords[3]); - toReturn.setMaxY(coords[4]); - toReturn.setMaxZ(coords[5]); - } else { - toReturn.setMinX(coords[2]); - toReturn.setMaxY(coords[3]); - } - return toReturn; - } - - 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 String MAX_X = "_maxX"; - public static final String MAX_Y = "_maxY"; - public static final String MAX_Z = "_maxZ"; - public static final String MIN_X = "_minX"; - public static final String MIN_Y = "_minY"; - 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) { - setMaxX(maxX); - setMinX(minX); - setMaxY(maxY); - setMinY(minY); - } - - public BBOXDV setMaxX(Double d) { - 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() { - 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; - } } \ No newline at end of file diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/view/SectionView.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/view/SectionView.java index 0d4197b..7bf3f03 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/view/SectionView.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/view/SectionView.java @@ -33,6 +33,19 @@ public class SectionView implements Serializable, CheckEmpty { return false; } + + public boolean hasSpatialLayers(){ + if (listSubDocuments == null) + return false; + + for (SubDocumentView subDocumentView : listSubDocuments) { + boolean hasLayers = subDocumentView.getListLayers()!=null && subDocumentView.getListLayers().size()>0; + if(hasLayers) + return true; + } + + return false; + } public String getSectionTitle() { return sectionTitle;