示例#1
0
        /**
         * Determine and set the {@link PointPlacemark} attributes from the KML <i>Feature</i> fields.
         *
         * @param attrType the type of attributes, either {@link KMLConstants#NORMAL} or {@link KMLConstants#HIGHLIGHT}.
         *
         * @return The new attributes, or null if there are no attributes defined. Returns a partially empty attributes
         *         bundle marked unresolved if any of placemark KML styles are unresolved.
         */
        protected PointPlacemarkAttributes makeAttributesCurrent(String attrType)
        {
            bool hasLineStyle  = false;
            bool hasIconStyle  = false;
            bool hasLabelStyle = false;

            PointPlacemarkAttributes attrs = this.getInitialAttributes(
                this.isHighlighted() ? KMLConstants.HIGHLIGHT : KMLConstants.NORMAL);

            // Get the KML sub-style for Line attributes. Map them to Shape attributes.

            KMLAbstractSubStyle subStyle = this.parent.getSubStyle(new KMLLineStyle(null), attrType);

            if (subStyle.hasFields() && (!this.isHighlighted() || KMLUtil.isHighlightStyleState(subStyle)))
            {
                hasLineStyle = true;
                this.assembleLineAttributes(attrs, (KMLLineStyle)subStyle);
                if (subStyle.hasField(AVKey.UNRESOLVED))
                {
                    attrs.setUnresolved(true);
                }
            }

            subStyle = this.parent.getSubStyle(new KMLIconStyle(null), attrType);
            if (subStyle.hasFields() && (!this.isHighlighted() || KMLUtil.isHighlightStyleState(subStyle)))
            {
                hasIconStyle = true;
                this.assemblePointAttributes(attrs, (KMLIconStyle)subStyle);
                if (subStyle.hasField(AVKey.UNRESOLVED))
                {
                    attrs.setUnresolved(true);
                }
            }

            subStyle = this.parent.getSubStyle(new KMLLabelStyle(null), attrType);
            if (subStyle.hasFields() && (!this.isHighlighted() || KMLUtil.isHighlightStyleState(subStyle)))
            {
                hasLabelStyle = true;
                this.assembleLabelAttributes(attrs, (KMLLabelStyle)subStyle);
                if (subStyle.hasField(AVKey.UNRESOLVED))
                {
                    attrs.setUnresolved(true);
                }
            }

            // Return the attributes only if we actually found a KML style. If no style was found, return null instead of an
            // empty attributes bundle. If a style was found, but could not be resolved, we will return a partially empty
            // attributes bundle that is marked unresolved.
            if (hasLineStyle || hasIconStyle || hasLabelStyle)
            {
                return(attrs);
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        /**
         * 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 ArgumentException if the parent overlay or the traversal context is null.
         */
        public KMLSurfaceImageImpl(KMLTraversalContext tc, KMLGroundOverlay overlay)
        {
            this.parent = overlay;

            if (tc == null)
            {
                String msg = Logging.getMessage("nullValue.TraversalContextIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            if (overlay == null)
            {
                String msg = Logging.getMessage("nullValue.ParentIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(msg);
            }

            // Positions are specified either as a kml:LatLonBox or a gx:LatLonQuad
            KMLLatLonBox box = overlay.getLatLonBox();

            if (box != null)
            {
                Sector sector = KMLUtil.createSectorFromLatLonBox(box);
                this.initializeGeometry(sector);

                // Check to see if a rotation is provided. The rotation will be applied when the image is rendered, because
                // how the rotation is performed depends on the globe.
                Double rotation = box.getRotation();
                if (rotation != null)
                {
                    this.mustApplyRotation = true;
                }
            }
            else
            {
                GXLatLongQuad latLonQuad = overlay.getLatLonQuad();
                if (latLonQuad != null && latLonQuad.getCoordinates() != null)
                {
                    this.initializeGeometry(latLonQuad.getCoordinates().list);
                }
            }

            // Apply opacity to the surface image
            String colorStr = overlay.getColor();

            if (!WWUtil.isEmpty(colorStr))
            {
                Color color = WWUtil.decodeColorABGR(colorStr);
                int   alpha = color.getAlpha();

                this.setOpacity((double)alpha / 255);
            }

            this.setPickEnabled(false);
        }
示例#3
0
        /**
         * Apply a rotation to the corner points of the overlay.
         *
         * @param dc Current draw context.
         */
        protected void applyRotation(DrawContext dc)
        {
            KMLLatLonBox box = this.parent.getLatLonBox();

            if (box != null)
            {
                Double rotation = box.getRotation();
                if (rotation != null)
                {
                    List <LatLon> corners = KMLUtil.rotateSector(dc.getGlobe(), this.getSector(),
                                                                 Angle.fromDegrees(rotation));
                    this.setCorners(corners);
                }
            }
        }
示例#4
0
        /**
         * Apply the model's position, orientation, and scale to a COLLADA root.
         *
         * @param root COLLADA root to configure.
         */
        protected void configureColladaRoot(ColladaRoot root)
        {
            root.setResourceResolver(this);

            Position refPosition = this.model.getLocation().getPosition();

            root.setPosition(refPosition);
            root.setAltitudeMode(KMLUtil.convertAltitudeMode(this.model.getAltitudeMode(), WorldWind.CLAMP_TO_GROUND)); // KML default

            KMLOrientation orientation = this.model.getOrientation();

            if (orientation != null)
            {
                Double d = orientation.getHeading();
                if (d != null)
                {
                    root.setHeading(Angle.fromDegrees(d));
                }

                d = orientation.getTilt();
                if (d != null)
                {
                    root.setPitch(Angle.fromDegrees(-d));
                }

                d = orientation.getRoll();
                if (d != null)
                {
                    root.setRoll(Angle.fromDegrees(-d));
                }
            }

            KMLScale scale = this.model.getScale();

            if (scale != null)
            {
                Double x = scale.getX();
                Double y = scale.getY();
                Double z = scale.getZ();

                Vec4 modelScale = new Vec4(
                    x != null ? x : 1.0,
                    y != null ? y : 1.0,
                    z != null ? z : 1.0);

                root.setModelScale(modelScale);
            }
        }
        /**
         * Apply a rotation to the corner points of the overlay. This method is called the first time the polygon is
         * rendered, if the position is specified using a rotated LatLon box.
         *
         * @param dc Current draw context.
         */
        protected void applyRotation(DrawContext dc)
        {
            // Rotation applies only to ground overlay position with a LatLon box.
            if (!(this.parent is KMLGroundOverlay))
            {
                return;
            }

            KMLLatLonBox box = ((KMLGroundOverlay)this.parent).getLatLonBox();

            if (box != null)
            {
                Double rotation = box.getRotation();
                if (rotation != null)
                {
                    Sector sector = KMLUtil.createSectorFromLatLonBox(box);
                    java.util.List <LatLon> corners = KMLUtil.rotateSector(dc.getGlobe(), sector,
                                                                           Angle.fromDegrees(rotation));
                    this.setOuterBoundary(corners);
                }
            }
        }
示例#6
0
        /**
         * Determine and set the {@link Path} highlight attributes from the KML <i>Feature</i> fields.
         *
         * @param attrType the type of attributes, either {@link KMLConstants#NORMAL} or {@link KMLConstants#HIGHLIGHT}.
         *
         * @return the new attributes.
         */
        protected ShapeAttributes makeAttributesCurrent(String attrType)
        {
            ShapeAttributes attrs = this.getInitialAttributes(
                this.isHighlighted() ? KMLConstants.HIGHLIGHT : KMLConstants.NORMAL);

            // Get the KML sub-style for Line attributes. Map them to Shape attributes.

            KMLAbstractSubStyle lineSubStyle = this.parent.getSubStyle(new KMLLineStyle(null), attrType);

            if (!this.isHighlighted() || KMLUtil.isHighlightStyleState(lineSubStyle))
            {
                KMLUtil.assembleLineAttributes(attrs, (KMLLineStyle)lineSubStyle);
                if (lineSubStyle.hasField(AVKey.UNRESOLVED))
                {
                    attrs.setUnresolved(true);
                }
            }

            // Get the KML sub-style for interior attributes. Map them to Shape attributes.

            KMLAbstractSubStyle fillSubStyle = this.parent.getSubStyle(new KMLPolyStyle(null), attrType);

            if (!this.isHighlighted() || KMLUtil.isHighlightStyleState(lineSubStyle))
            {
                KMLUtil.assembleInteriorAttributes(attrs, (KMLPolyStyle)fillSubStyle);
                if (fillSubStyle.hasField(AVKey.UNRESOLVED))
                {
                    attrs.setUnresolved(true);
                }

                attrs.setDrawInterior(((KMLPolyStyle)fillSubStyle).isFill());
                if (this.isExtrude())
                {
                    attrs.setDrawOutline(((KMLPolyStyle)fillSubStyle).isOutline());
                }
            }

            return(attrs);
        }
示例#7
0
        protected PointPlacemarkAttributes assemblePointAttributes(PointPlacemarkAttributes attrs, KMLIconStyle style)
        {
            KMLIcon icon = style.getIcon();

            if (icon != null && icon.getHref() != null)
            {
                // 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 PointPlacemark code resolve the reference.
                String href         = icon.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);
                }
                attrs.setImageAddress((localAddress != null ? localAddress : href));
            }
            // If the Icon element is present, but there is no href, draw a point instead of the default icon.
            else if (icon != null && WWUtil.isEmpty(icon.getHref()))
            {
                attrs.setUsePointAsDefaultImage(true);
            }

            // Assign the other attributes defined in the KML Feature element.

            if (style.getColor() != null)
            {
                attrs.setImageColor(WWUtil.decodeColorABGR(style.getColor()));
            }

            if (style.getColorMode() != null && "random".Equals(style.getColorMode()))
            {
                attrs.setImageColor(WWUtil.makeRandomColor(attrs.getImageColor()));
            }

            if (style.getScale() != null)
            {
                attrs.setScale(style.getScale());
            }

            if (style.getHeading() != null)
            {
                attrs.setHeading(style.getHeading());
                attrs.setHeadingReference(AVKey.RELATIVE_TO_GLOBE); // KML spec is not clear about this
            }

            if (style.getHotSpot() != null)
            {
                KMLVec2 hs = style.getHotSpot();
                attrs.setImageOffset(new Offset(hs.getX(), hs.getY(), KMLUtil.kmlUnitsToWWUnits(hs.getXunits()),
                                                KMLUtil.kmlUnitsToWWUnits(hs.getYunits())));
            }
            else
            {
                // By default, use the center of the image as the offset.
                attrs.setImageOffset(new Offset(0.5, 0.5, AVKey.FRACTION, AVKey.FRACTION));
            }

            return(attrs);
        }
示例#8
0
        /**
         * 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 ArgumentException 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 ArgumentException(msg);
            }

            if (overlay == null)
            {
                String msg = Logging.getMessage("nullValue.ParentIsNull");
                Logging.logger().severe(msg);
                throw new ArgumentException(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);
            }
        }