/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param placemark the <i>Placemark</i> element containing the <i>LineString</i>. * @param geom the {@link gov.nasa.worldwind.ogc.kml.KMLPolygon} geometry. * @throws NullPointerException if the geometry is null. * @throws IllegalArgumentException if the parent placemark or the traversal context is null. */ public KMLSurfacePolygonImpl( KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) { if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } if (placemark == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } this.parent = placemark; KMLPolygon polygon = (KMLPolygon) geom; // KMLPolygon's use linear interpolation between corners by definition. Configure the World Wind // SurfacePolygon // to use the appropriate path type for linear interpolation in geographic coordinates. this.setPathType(AVKey.LINEAR); // Note: SurfacePolygon implies altitude mode "clampToGround", therefore KMLSurfacePolygonImpl // ignores the // KMLPolygon's altitude mode property. KMLLinearRing outerBoundary = polygon.getOuterBoundary(); if (outerBoundary != null) { Position.PositionList coords = outerBoundary.getCoordinates(); if (coords != null && coords.list != null) this.setOuterBoundary(outerBoundary.getCoordinates().list); } Iterable<? extends KMLLinearRing> innerBoundaries = polygon.getInnerBoundaries(); if (innerBoundaries != null) { for (KMLLinearRing ring : innerBoundaries) { Position.PositionList coords = ring.getCoordinates(); if (coords != null && coords.list != null) this.addInnerBoundary(ring.getCoordinates().list); } } if (placemark.getName() != null) this.setValue(AVKey.DISPLAY_NAME, placemark.getName()); if (placemark.getDescription() != null) this.setValue(AVKey.DESCRIPTION, placemark.getDescription()); if (placemark.getSnippetText() != null) this.setValue(AVKey.SHORT_DESCRIPTION, placemark.getSnippetText()); this.setValue(AVKey.CONTEXT, this.parent); }
public void run() { if (Thread.currentThread().isInterrupted()) return; // the task was cancelled because it's a duplicate or for some other reason try { this.placemark.retrieveModel(this.address); } catch (IOException e) { String message = Logging.getMessage("generic.ExceptionWhileReading", e.getMessage()); Logging.logger().warning(message); } catch (XMLStreamException e) { String message = Logging.getMessage("generic.ExceptionAttemptingToParseXml", e.getMessage()); Logging.logger().warning(message); } }
/** * Resolve the HREF in this overlay's Icon element against the KML root. * * @return The resolved path to the image source. */ protected String resolveHref() { // The icon reference may be to a support file within a KMZ file, so check for that. If it's // not, then just // let the normal ScreenImage code resolve the reference. String href = this.parent.getIcon().getHref(); String localAddress = null; try { localAddress = this.parent.getRoot().getSupportFilePath(href); } catch (IOException e) { String message = Logging.getMessage("generic.UnableToResolveReference", href); Logging.logger().warning(message); } return localAddress != null ? localAddress : href; }
/** * Construct a request task for a specified network link resource. * * @param placemark the placemark for which to construct the request task. * @param address the address of the resource to request. */ protected RequestTask(KMLModelPlacemarkImpl placemark, String address) { if (placemark == null) { String message = Logging.getMessage("nullValue.ObjectIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (address == null) { String message = Logging.getMessage("nullValue.PathIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.placemark = placemark; this.address = address; }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param placemark the <i>Placemark</i> element containing the <i>Point</i>. * @param geom the {@link gov.nasa.worldwind.ogc.kml.KMLPoint} geometry. * @throws NullPointerException if the geometry is null. * @throws IllegalArgumentException if the parent placemark or the traversal context is null. */ public KMLModelPlacemarkImpl( KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) { if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } if (placemark == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } if (geom == null) { String msg = Logging.getMessage("nullValue.GeometryIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } this.model = (KMLModel) geom; this.parent = placemark; this.resourceMap = this.createResourceMap(this.model); }
/** * Create a surface polygon from a KML GroundOverlay. * * @param tc the current {@link KMLTraversalContext}. * @param overlay the {@link gov.nasa.worldwind.ogc.kml.KMLGroundOverlay} to render as a polygon. * @throws NullPointerException if the geometry is null. * @throws IllegalArgumentException if the parent placemark or the traversal context is null. */ public KMLSurfacePolygonImpl(KMLTraversalContext tc, KMLGroundOverlay overlay) { if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } if (overlay == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } this.parent = overlay; // Positions are specified either as a kml:LatLonBox or a gx:LatLonQuad Position.PositionList corners = overlay.getPositions(); this.setOuterBoundary(corners.list); if (overlay.getName() != null) this.setValue(AVKey.DISPLAY_NAME, overlay.getName()); if (overlay.getDescription() != null) this.setValue(AVKey.BALLOON_TEXT, overlay.getDescription()); if (overlay.getSnippetText() != null) this.setValue(AVKey.SHORT_DESCRIPTION, overlay.getSnippetText()); String colorStr = overlay.getColor(); if (!WWUtil.isEmpty(colorStr)) { Color color = WWUtil.decodeColorABGR(colorStr); ShapeAttributes attributes = new BasicShapeAttributes(); attributes.setDrawInterior(true); attributes.setInteriorMaterial(new Material(color)); this.setAttributes(attributes); } }
/** * Create an screen image. * * @param tc the current {@link KMLTraversalContext}. * @param overlay the <i>Overlay</i> element containing. * @throws NullPointerException if the traversal context is null. * @throws IllegalArgumentException if the parent overlay or the traversal context is null. */ public KMLScreenImageImpl(KMLTraversalContext tc, KMLScreenOverlay overlay) { this.parent = overlay; if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } if (overlay == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } KMLVec2 xy = this.parent.getScreenXY(); if (xy != null) { this.screenOffset = new Offset( xy.getX(), xy.getY(), KMLUtil.kmlUnitsToWWUnits(xy.getXunits()), KMLUtil.kmlUnitsToWWUnits(xy.getYunits())); } xy = this.parent.getOverlayXY(); if (xy != null) { this.imageOffset = new Offset( xy.getX(), xy.getY(), KMLUtil.kmlUnitsToWWUnits(xy.getXunits()), KMLUtil.kmlUnitsToWWUnits(xy.getYunits())); } this.setRotation(overlay.getRotation()); xy = this.parent.getRotationXY(); if (xy != null) { setRotationOffset( new Offset( xy.getX(), xy.getY(), KMLUtil.kmlUnitsToWWUnits(xy.getXunits()), KMLUtil.kmlUnitsToWWUnits(xy.getYunits()))); } String colorStr = overlay.getColor(); if (colorStr != null) { Color color = WWUtil.decodeColorABGR(colorStr); this.setColor(color); } // Compute desired image size, and the scale factor that will make it that size KMLVec2 kmlSize = this.parent.getSize(); if (kmlSize != null) { Size size = new Size(); size.setWidth( getSizeMode(kmlSize.getX()), kmlSize.getX(), KMLUtil.kmlUnitsToWWUnits(kmlSize.getXunits())); size.setHeight( getSizeMode(kmlSize.getY()), kmlSize.getY(), KMLUtil.kmlUnitsToWWUnits(kmlSize.getYunits())); this.setSize(size); } }