Пример #1
0
        public void render(KMLTraversalContext tc, DrawContext dc)
        {
            // If the attributes are not inline or internal then they might not be resolved until the external KML
            // document is resolved. Therefore check to see if resolution has occurred.

            if (this.isHighlighted())
            {
                if (!this.highlightAttributesResolved)
                {
                    PointPlacemarkAttributes a = this.getHighlightAttributes();
                    if (a == null || a.isUnresolved())
                    {
                        a = this.makeAttributesCurrent(KMLConstants.HIGHLIGHT);
                        if (a != null)
                        {
                            this.setHighlightAttributes(a);
                            if (!a.isUnresolved())
                            {
                                this.highlightAttributesResolved = true;
                            }
                        }
                        else
                        {
                            // There are no highlight attributes, so we can stop looking for them. Note that this is
                            // different from having unresolved highlight attributes (handled above).
                            this.highlightAttributesResolved = true;
                        }
                    }
                }
            }
            else
            {
                if (!this.normalAttributesResolved)
                {
                    PointPlacemarkAttributes a = this.getAttributes();
                    if (a == null || a.isUnresolved())
                    {
                        a = this.makeAttributesCurrent(KMLConstants.NORMAL);
                        if (a != null)
                        {
                            this.setAttributes(a);
                            if (!a.isUnresolved())
                            {
                                this.normalAttributesResolved = true;
                            }
                        }
                        else
                        {
                            // There are no normal attributes, so we can stop looking for them.  Note that this is different
                            // from having unresolved attributes (handled above).
                            this.normalAttributesResolved = true;
                        }
                    }
                }
            }

            this.render(dc);
        }
Пример #2
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);
            }
        }
Пример #3
0
        protected PointPlacemarkAttributes assembleLabelAttributes(PointPlacemarkAttributes attrs, KMLLabelStyle style)
        {
            // Assign the attributes defined in the KML Feature element.

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

            if (style.getColor() != null)
            {
                attrs.setLabelColor(style.getColor());
            }

            if (style.getColorMode() != null && "random".Equals(style.getColorMode()))
            {
                attrs.setLabelMaterial(new Material(WWUtil.makeRandomColor(attrs.getLabelColor())));
            }

            return(attrs);
        }
Пример #4
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);
        }