示例#1
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);
        }