From 452a4f08690360f160063bd09a013501ebe70d67 Mon Sep 17 00:00:00 2001 From: markpet49 Date: Thu, 7 Sep 2023 21:59:31 -0500 Subject: [PATCH] Add ability to get extents for KML files --- src/gov/nasa/worldwind/Version.java | 33 ++++++----- .../ogc/kml/KMLAbstractContainer.java | 57 +++++++++++++++--- .../worldwind/ogc/kml/KMLAbstractFeature.java | 22 ++++--- .../ogc/kml/KMLAbstractGeometry.java | 13 +++-- .../worldwind/ogc/kml/KMLGroundOverlay.java | 22 +++++-- .../nasa/worldwind/ogc/kml/KMLLineString.java | 23 ++++++-- src/gov/nasa/worldwind/ogc/kml/KMLModel.java | 29 ++++++++-- .../worldwind/ogc/kml/KMLMultiGeometry.java | 26 +++++++-- .../worldwind/ogc/kml/KMLPhotoOverlay.java | 25 ++++++-- .../nasa/worldwind/ogc/kml/KMLPlacemark.java | 20 +++++-- src/gov/nasa/worldwind/ogc/kml/KMLPoint.java | 21 +++++-- .../nasa/worldwind/ogc/kml/KMLPolygon.java | 22 +++++-- src/gov/nasa/worldwind/ogc/kml/KMLRoot.java | 33 +++++++---- .../worldwind/ogc/kml/KMLScreenOverlay.java | 17 ++++-- src/gov/nasa/worldwind/ogc/kml/gx/GXTour.java | 17 ++++-- .../worldwindx/examples/kml/KMLViewer.java | 58 +++++++++++++------ 16 files changed, 325 insertions(+), 113 deletions(-) diff --git a/src/gov/nasa/worldwind/Version.java b/src/gov/nasa/worldwind/Version.java index 7fc7e9cb24..fd8d4a6601 100644 --- a/src/gov/nasa/worldwind/Version.java +++ b/src/gov/nasa/worldwind/Version.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -31,35 +31,42 @@ * @author tag * @version $Id: Version.java 1171 2013-02-11 21:45:02Z dcollins $ */ -public class Version { +public class Version +{ private static final String MAJOR_VALUE = "2"; private static final String MINOR_VALUE = "2"; - private static final String DOT_VALUE = "1"; + private static final String DOT_VALUE = "2"; private static final String versionNumber = "v" + MAJOR_VALUE + "." + MINOR_VALUE + "." + DOT_VALUE; private static final String versionName = "NASA WorldWind Java"; - public static String getVersion() { + public static String getVersion() + { return versionName + " " + versionNumber; } - public static String getVersionName() { + public static String getVersionName() + { return versionName; } - public static String getVersionNumber() { + public static String getVersionNumber() + { return versionNumber; } - public static String getVersionMajorNumber() { + public static String getVersionMajorNumber() + { return MAJOR_VALUE; } - public static String getVersionMinorNumber() { + public static String getVersionMinorNumber() + { return MINOR_VALUE; } - public static String getVersionDotNumber() { + public static String getVersionDotNumber() + { return DOT_VALUE; } } diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLAbstractContainer.java b/src/gov/nasa/worldwind/ogc/kml/KMLAbstractContainer.java index 76f5893368..140000edd1 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLAbstractContainer.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLAbstractContainer.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -29,6 +29,7 @@ package gov.nasa.worldwind.ogc.kml; import gov.nasa.worldwind.event.Message; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.ogc.kml.impl.KMLTraversalContext; import gov.nasa.worldwind.render.DrawContext; import gov.nasa.worldwind.util.*; @@ -156,6 +157,12 @@ protected void doRender(KMLTraversalContext tc, DrawContext dc) } } + @Override + public Sector getExtent() + { + return this.getFeaturesExtent(); + } + /** * Prepares this KML container for rendering. This pushes this container's Region on the KML traversal context's * region stack. Descendant features use the KML traversal context's region stack to inherit Regions from parent @@ -164,7 +171,10 @@ protected void doRender(KMLTraversalContext tc, DrawContext dc) * @param tc the current KML traversal context. * @param dc the current draw context. */ - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings( + { + "UnusedDeclaration" + }) protected void beginRendering(KMLTraversalContext tc, DrawContext dc) { if (this.getRegion() != null) @@ -179,7 +189,10 @@ protected void beginRendering(KMLTraversalContext tc, DrawContext dc) * @param tc the current KML traversal context. * @param dc the current draw context. */ - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings( + { + "UnusedDeclaration" + }) protected void endRendering(KMLTraversalContext tc, DrawContext dc) { if (this.getRegion() != null) @@ -246,6 +259,36 @@ protected void renderFeatures(KMLTraversalContext tc, DrawContext dc) } } + protected Sector getFeaturesExtent() + { + List containers = new ArrayList<>(); + Sector fullExtent = null; + // Render non-container child features first, and containers second. This ensures that features closer to the + // root are rendered before features deeper in the tree. In the case of an image pyramid of GroundOverlays, + // this causes the deeper nested overlays (which are typically more detailed) to render on top of the more + // general overlay that is higher in the tree. + for (KMLAbstractFeature feature : this.getFeatures()) + { + if (feature instanceof KMLAbstractContainer) + { + containers.add(feature); + } + else + { + Sector featureExtent = feature.getExtent(); + fullExtent = (fullExtent == null) ? featureExtent : fullExtent.union(featureExtent); + } + } + + // Now render the containers + for (KMLAbstractFeature feature : containers) + { + Sector featureExtent = feature.getExtent(); + fullExtent = (fullExtent == null) ? featureExtent : fullExtent.union(featureExtent); + } + return fullExtent; + } + @Override public void applyChange(KMLAbstractObject sourceValues) { diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLAbstractFeature.java b/src/gov/nasa/worldwind/ogc/kml/KMLAbstractFeature.java index 13f3b22ba5..706193e135 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLAbstractFeature.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLAbstractFeature.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -29,6 +29,7 @@ package gov.nasa.worldwind.ogc.kml; import gov.nasa.worldwind.event.Message; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.ogc.kml.impl.*; import gov.nasa.worldwind.render.*; import gov.nasa.worldwind.util.*; @@ -374,7 +375,10 @@ protected void doRender(KMLTraversalContext tc, DrawContext dc) * @param tc the current KML traversal context. * @param dc the current draw context. */ - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings( + { + "UnusedDeclaration" + }) protected void renderBalloon(KMLTraversalContext tc, DrawContext dc) { if (this.getBalloon() != null) @@ -442,8 +446,8 @@ public void applyChange(KMLAbstractObject sourceValues) protected void mergeStyleSelectors(KMLAbstractFeature sourceFeature) { // Make a copy of the existing list so we can modify it as we traverse the copy. - List styleSelectorsCopy = - new ArrayList(this.getStyleSelectors().size()); + List styleSelectorsCopy + = new ArrayList(this.getStyleSelectors().size()); styleSelectorsCopy.addAll(this.getStyleSelectors()); for (KMLAbstractStyleSelector sourceSelector : sourceFeature.getStyleSelectors()) @@ -464,4 +468,6 @@ protected void mergeStyleSelectors(KMLAbstractFeature sourceFeature) this.getStyleSelectors().add(sourceSelector); } } + + public abstract Sector getExtent(); } diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLAbstractGeometry.java b/src/gov/nasa/worldwind/ogc/kml/KMLAbstractGeometry.java index 46775f7f1c..8bf8a72210 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLAbstractGeometry.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLAbstractGeometry.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -29,6 +29,7 @@ package gov.nasa.worldwind.ogc.kml; import gov.nasa.worldwind.event.Message; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.util.Logging; /** @@ -63,4 +64,6 @@ public void applyChange(KMLAbstractObject sourceValues) this.onChange(new Message(KMLAbstractObject.MSG_GEOMETRY_CHANGED, this)); } + + public abstract Sector getExtent(); } diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLGroundOverlay.java b/src/gov/nasa/worldwind/ogc/kml/KMLGroundOverlay.java index b746b9fd13..88d325a0a6 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLGroundOverlay.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLGroundOverlay.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -191,6 +191,17 @@ public Position.PositionList getPositions() return new Position.PositionList(corners); } + @Override + public Sector getExtent() + { + Position.PositionList positions = this.getPositions(); + if (positions != null) + { + return Sector.boundingSector(positions.list); + } + return null; + } + @Override public void applyChange(KMLAbstractObject sourceValues) { @@ -218,4 +229,3 @@ public void onChange(Message msg) super.onChange(msg); } } - diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLLineString.java b/src/gov/nasa/worldwind/ogc/kml/KMLLineString.java index 306297c03f..9088c5d1f4 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLLineString.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLLineString.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -29,6 +29,7 @@ package gov.nasa.worldwind.ogc.kml; import gov.nasa.worldwind.geom.Position; +import gov.nasa.worldwind.geom.Sector; /** * Represents the KML LineString element and provides access to its contents. @@ -72,4 +73,16 @@ public Position.PositionList getCoordinates() { return (Position.PositionList) this.getField("coordinates"); } + + @Override + public Sector getExtent() + { + Position.PositionList positions = this.getCoordinates(); + if (positions != null) + { + return Sector.boundingSector(positions.list); + } + + return null; + } } diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLModel.java b/src/gov/nasa/worldwind/ogc/kml/KMLModel.java index 97d911d4a7..81639639ec 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLModel.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLModel.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -28,6 +28,9 @@ package gov.nasa.worldwind.ogc.kml; +import gov.nasa.worldwind.geom.Position; +import gov.nasa.worldwind.geom.Sector; + /** * Represents the KML Model element and provides access to its contents. * @@ -60,6 +63,22 @@ public KMLLocation getLocation() return (KMLLocation) this.getField("Location"); } + @Override + public Sector getExtent() + { + KMLLocation kmlLoc = this.getLocation(); + if (kmlLoc != null) + { + Position pos = kmlLoc.getPosition(); + if (pos != null) + { + return new Sector(pos.latitude, pos.latitude, pos.longitude, pos.longitude); + } + } + + return null; + } + public KMLOrientation getOrientation() { return (KMLOrientation) this.getField("Orientation"); diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLMultiGeometry.java b/src/gov/nasa/worldwind/ogc/kml/KMLMultiGeometry.java index 9f6c37f019..22495c4b39 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLMultiGeometry.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLMultiGeometry.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -28,6 +28,7 @@ package gov.nasa.worldwind.ogc.kml; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.util.*; import gov.nasa.worldwind.util.xml.XMLEventParserContext; @@ -75,6 +76,21 @@ public List getGeometries() return this.geometries; } + @Override + public Sector getExtent() + { + Sector fullExtent = null; + if (this.geometries != null) + { + for (KMLAbstractGeometry geometry : this.geometries) + { + Sector geometryExtent = geometry.getExtent(); + fullExtent = (fullExtent == null) ? geometryExtent : fullExtent.union(geometryExtent); + } + } + return fullExtent; + } + @Override public void applyChange(KMLAbstractObject sourceValues) { diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLPhotoOverlay.java b/src/gov/nasa/worldwind/ogc/kml/KMLPhotoOverlay.java index bbb44bbd65..2254044551 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLPhotoOverlay.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLPhotoOverlay.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -28,6 +28,10 @@ package gov.nasa.worldwind.ogc.kml; +import gov.nasa.worldwind.geom.Angle; +import gov.nasa.worldwind.geom.Position; +import gov.nasa.worldwind.geom.Sector; + /** * Represents the KML PhotoOverlay element and provides access to its contents. * @@ -70,4 +74,15 @@ public String getShape() { return (String) this.getField("shape"); } + + @Override + public Sector getExtent() + { + KMLPoint point = this.getPoint(); + if (point != null) + { + return point.getExtent(); + } + return null; + } } diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLPlacemark.java b/src/gov/nasa/worldwind/ogc/kml/KMLPlacemark.java index c0f69e552b..240e103cce 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLPlacemark.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLPlacemark.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -31,6 +31,7 @@ import gov.nasa.worldwind.WorldWind; import gov.nasa.worldwind.avlist.AVKey; import gov.nasa.worldwind.event.Message; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.ogc.kml.impl.*; import gov.nasa.worldwind.render.DrawContext; import gov.nasa.worldwind.util.Logging; @@ -86,6 +87,15 @@ public KMLAbstractGeometry getGeometry() return this.geometry; } + public Sector getExtent() + { + if (this.geometry != null) + { + return this.geometry.getExtent(); + } + return null; + } + public KMLSimpleData getSimpleData() // Included for test purposes only { return (KMLSimpleData) this.getField("SimpleData"); diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLPoint.java b/src/gov/nasa/worldwind/ogc/kml/KMLPoint.java index 30e9b715be..cf44658b51 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLPoint.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLPoint.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -29,6 +29,7 @@ package gov.nasa.worldwind.ogc.kml; import gov.nasa.worldwind.geom.Position; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.util.Logging; import gov.nasa.worldwind.util.xml.XMLEventParserContext; @@ -85,6 +86,16 @@ public Position getCoordinates() return this.coordinates; } + public Sector getExtent() + { + Position pos = this.getCoordinates(); + if (pos != null) + { + return new Sector(pos.latitude, pos.latitude, pos.longitude, pos.longitude); + } + return null; + } + protected void setCoordinates(Position.PositionList coordsList) { if (coordsList != null && coordsList.list.size() > 0) diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLPolygon.java b/src/gov/nasa/worldwind/ogc/kml/KMLPolygon.java index be883b5284..1b364d43fd 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLPolygon.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLPolygon.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -28,6 +28,7 @@ package gov.nasa.worldwind.ogc.kml; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.util.*; import gov.nasa.worldwind.util.xml.XMLEventParserContext; @@ -104,6 +105,17 @@ public KMLLinearRing getOuterBoundary() return o != null ? ((KMLBoundary) o).getLinearRing() : null; } + @Override + public Sector getExtent() + { + KMLLinearRing boundary = this.getOuterBoundary(); + if (boundary != null) + { + return boundary.getExtent(); + } + return null; + } + @Override public void applyChange(KMLAbstractObject sourceValues) { diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLRoot.java b/src/gov/nasa/worldwind/ogc/kml/KMLRoot.java index 38f6bf29bf..7e00cc397c 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLRoot.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLRoot.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -32,6 +32,7 @@ import gov.nasa.worldwind.avlist.AVKey; import gov.nasa.worldwind.event.Message; import gov.nasa.worldwind.exception.*; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.ogc.kml.impl.*; import gov.nasa.worldwind.ogc.kml.io.*; import gov.nasa.worldwind.render.DrawContext; @@ -492,16 +493,17 @@ protected XMLEventReader createReader(Object docSource, boolean namespaceAware) */ protected KMLParserContext createParserContext(XMLEventReader reader) { - KMLParserContext ctx = (KMLParserContext) - XMLEventParserContextFactory.createParserContext(KMLConstants.KML_MIME_TYPE, this.getNamespaceURI()); + KMLParserContext ctx = (KMLParserContext) XMLEventParserContextFactory.createParserContext(KMLConstants.KML_MIME_TYPE, this.getNamespaceURI()); if (ctx == null) { // Register a parser context for this root's default namespace - String[] mimeTypes = new String[] {KMLConstants.KML_MIME_TYPE, KMLConstants.KMZ_MIME_TYPE}; + String[] mimeTypes = new String[] + { + KMLConstants.KML_MIME_TYPE, KMLConstants.KMZ_MIME_TYPE + }; XMLEventParserContextFactory.addParserContext(mimeTypes, new KMLParserContext(this.getNamespaceURI())); - ctx = (KMLParserContext) - XMLEventParserContextFactory.createParserContext(KMLConstants.KML_MIME_TYPE, this.getNamespaceURI()); + ctx = (KMLParserContext) XMLEventParserContextFactory.createParserContext(KMLConstants.KML_MIME_TYPE, this.getNamespaceURI()); } ctx.setEventReader(reader); @@ -1261,10 +1263,19 @@ public void render(KMLTraversalContext tc, DrawContext dc) this.getFeature().render(tc, dc); } + public Sector getExtent() + { + if (this.getFeature() != null) + { + return this.getFeature().getExtent(); + } + + return null; + } + //********************************************************************** //********************* Property change support ************************ //********************************************************************** - /** * {@inheritDoc} *

diff --git a/src/gov/nasa/worldwind/ogc/kml/KMLScreenOverlay.java b/src/gov/nasa/worldwind/ogc/kml/KMLScreenOverlay.java index 57983635a2..543d0562f0 100644 --- a/src/gov/nasa/worldwind/ogc/kml/KMLScreenOverlay.java +++ b/src/gov/nasa/worldwind/ogc/kml/KMLScreenOverlay.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -29,6 +29,7 @@ package gov.nasa.worldwind.ogc.kml; import gov.nasa.worldwind.event.Message; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.ogc.kml.impl.*; import gov.nasa.worldwind.render.DrawContext; import gov.nasa.worldwind.util.Logging; @@ -98,6 +99,12 @@ protected void doPreRender(KMLTraversalContext tc, DrawContext dc) } } + @Override + public Sector getExtent() + { + return null; + } + /** * Renders the screen overlay geometry represented by this KMLScreenOverlay. * diff --git a/src/gov/nasa/worldwind/ogc/kml/gx/GXTour.java b/src/gov/nasa/worldwind/ogc/kml/gx/GXTour.java index 443640b687..6aebba6348 100644 --- a/src/gov/nasa/worldwind/ogc/kml/gx/GXTour.java +++ b/src/gov/nasa/worldwind/ogc/kml/gx/GXTour.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -28,6 +28,7 @@ package gov.nasa.worldwind.ogc.kml.gx; +import gov.nasa.worldwind.geom.Sector; import gov.nasa.worldwind.ogc.kml.KMLAbstractFeature; /** @@ -45,4 +46,10 @@ public GXPlaylist getPlaylist() { return (GXPlaylist) this.getField("Playlist"); } + + @Override + public Sector getExtent() + { + return null; + } } diff --git a/src/gov/nasa/worldwindx/examples/kml/KMLViewer.java b/src/gov/nasa/worldwindx/examples/kml/KMLViewer.java index 759426f6f4..4bc109f67a 100644 --- a/src/gov/nasa/worldwindx/examples/kml/KMLViewer.java +++ b/src/gov/nasa/worldwindx/examples/kml/KMLViewer.java @@ -2,25 +2,25 @@ * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the * Administrator of the National Aeronautics and Space Administration. * All rights reserved. - * + * * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. - * + * * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source * software: - * + * * Jackson Parser – Licensed under Apache 2.0 * GDAL – Licensed under MIT * JOGL – Licensed under Berkeley Software Distribution (BSD) * Gluegen – Licensed under Berkeley Software Distribution (BSD) - * + * * A complete listing of 3rd Party software notices and licenses included in * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party * notices and licenses PDF found in code directory. @@ -30,6 +30,10 @@ import gov.nasa.worldwind.WorldWind; import gov.nasa.worldwind.avlist.AVKey; +import gov.nasa.worldwind.geom.LatLon; +import gov.nasa.worldwind.geom.Position; +import gov.nasa.worldwind.layers.Layer; +import gov.nasa.worldwind.layers.LayerList; import gov.nasa.worldwind.retrieve.RetrievalService; import gov.nasa.worldwindx.examples.ApplicationTemplate; import gov.nasa.worldwindx.examples.util.*; @@ -37,7 +41,10 @@ import gov.nasa.worldwind.layers.RenderableLayer; import gov.nasa.worldwind.ogc.kml.*; import gov.nasa.worldwind.ogc.kml.impl.KMLController; +import gov.nasa.worldwind.render.Size; import gov.nasa.worldwind.util.*; +import gov.nasa.worldwind.util.tree.BasicTreeLayout; +import gov.nasa.worldwind.util.tree.ScrollFrame; import javax.swing.*; import javax.swing.filechooser.*; @@ -72,12 +79,23 @@ public AppFrame() { super(true, false, false); // Don't include the layer panel; we're using the on-screen layer tree. + LayerList layers = this.getWwd().getModel().getLayers(); + for (Layer l : layers) + { + if (l.getName().equals("Bing Imagery")) + { + l.setEnabled(true); + } + + } // Add the on-screen layer tree, refreshing model with the WorldWindow's current layer list. We // intentionally refresh the tree's model before adding the layer that contains the tree itself. This // prevents the tree's layer from being displayed in the tree itself. this.layerTree = new LayerTree(new Point(20, 160)); this.layerTree.getModel().refresh(this.getWwd().getModel().getLayers()); - + BasicTreeLayout treeLayout = (BasicTreeLayout) this.layerTree.getLayout(); + ScrollFrame frame = treeLayout.getFrame(); + frame.setSize(Size.fromPixels(320, 600)); // Set up a layer to display the on-screen layer tree in the WorldWindow. This layer is not displayed in // the layer tree's model. Doing so would enable the user to hide the layer tree display with no way of // bringing it back. @@ -108,7 +126,7 @@ protected void addDocumentLayer(KMLRoot document) this.kmlAppController.setBalloonController(balloonController); // Size the WorldWindow to take up the space typically used by the layer panel. - Dimension size = new Dimension(1400, 800); + Dimension size = new Dimension(1400, 1024); this.setPreferredSize(size); this.pack(); WWUtil.alignComponent(null, this, AVKey.CENTER); @@ -119,7 +137,7 @@ protected void addDocumentLayer(KMLRoot document) WorldWind.getRetrievalService().setSSLExceptionListener(new RetrievalService.SSLExceptionListener() { @Override - public void onException(Throwable e, String path) + public void onException(Throwable e, String path) { System.out.println(path); System.out.println(e); @@ -156,7 +174,9 @@ protected void addKMLLayer(KMLRoot kmlRoot) this.layerTree.getModel().addLayer(layerNode); this.layerTree.makeVisible(layerNode.getPath()); layerNode.expandOpenContainers(this.layerTree); - + LatLon kmlLocation = kmlRoot.getExtent().getCentroid(); + Position eyePosition = new Position(kmlLocation.latitude, kmlLocation.longitude, 10000); + this.getWwd().getView().setEyePosition(eyePosition); // Listens to refresh property change events from KML network link nodes. Upon receiving such an event this // expands any tree paths that represent open KML containers. When a KML network link refreshes, its tree // node replaces its children with new nodes created from the refreshed content, then sends a refresh @@ -165,7 +185,7 @@ protected void addKMLLayer(KMLRoot kmlRoot) layerNode.addPropertyChangeListener(AVKey.RETRIEVAL_STATE_SUCCESSFUL, new PropertyChangeListener() { @Override - public void propertyChange(final PropertyChangeEvent event) + public void propertyChange(final PropertyChangeEvent event) { if (event.getSource() instanceof KMLNetworkLinkTreeNode) { @@ -173,7 +193,7 @@ public void propertyChange(final PropertyChangeEvent event) SwingUtilities.invokeLater(new Runnable() { @Override - public void run() + public void run() { ((KMLNetworkLinkTreeNode) event.getSource()).expandOpenContainers(layerTree); getWwd().redraw(); @@ -216,7 +236,7 @@ public WorkerThread(Object kmlSource, AppFrame appFrame) * but otherwise does nothing. */ @Override - public void run() + public void run() { try { @@ -230,7 +250,7 @@ public void run() SwingUtilities.invokeLater(new Runnable() { @Override - public void run() + public void run() { appFrame.addKMLLayer(finalKMLRoot); } @@ -292,7 +312,7 @@ protected static void makeMenu(final AppFrame appFrame) JMenuItem openFileMenuItem = new JMenuItem(new AbstractAction("Open File...") { @Override - public void actionPerformed(ActionEvent actionEvent) + public void actionPerformed(ActionEvent actionEvent) { try { @@ -317,7 +337,7 @@ public void actionPerformed(ActionEvent actionEvent) JMenuItem openURLMenuItem = new JMenuItem(new AbstractAction("Open URL...") { @Override - public void actionPerformed(ActionEvent actionEvent) + public void actionPerformed(ActionEvent actionEvent) { try { @@ -339,8 +359,10 @@ public void actionPerformed(ActionEvent actionEvent) public static void main(String[] args) { - //noinspection UnusedDeclaration - @SuppressWarnings("unused") - final AppFrame af = (AppFrame) start("WorldWind KML Viewer", AppFrame.class); + final KMLViewer.AppFrame app = (KMLViewer.AppFrame) start("WorldWind KML Viewer", AppFrame.class); + if (args.length > 0) + { + new WorkerThread(args[0], app).start(); + } } }