Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gx:drawOrder on any geometry type #19

Closed
yskific opened this issue Jul 23, 2019 · 3 comments
Closed

Support gx:drawOrder on any geometry type #19

yskific opened this issue Jul 23, 2019 · 3 comments

Comments

@yskific
Copy link

yskific commented Jul 23, 2019

Hi there,

Is there a way to extend GXDrawOrder property on all types derived from Geometry ?
link

Thanks

@samcragg
Copy link
Owner

Looking at the latest documentation, I still can only see it on the LineString type, so I don't think it's something that the library will support out of the box.

However, if you wanted to add support for any other Geometry type, then you might be able to do something like the FeatureExtension from the examples, e.g. to add it to the Point type

[KmlElement("drawOrder", KmlNamespaces.GX22Namespace)]
public class PointExtension : Element
{
    public int? Value
    {
        get
        {
            if (int.TryParse(this.InnerText, out int value))
            {
                return value;
            }
            else
            {
                return null;
            }
        }

        set
        {
            this.ClearInnerText();
            this.AddInnerText(value.ToString());
        }
    }
}

// Somewhere in your main function
KmlFactory.RegisterExtension<Point, PointExtension>();

This would allow you to add a PointExtension to the Point class, via it's AddChild method. To simplify this, I'd use a couple of extension methods:

public static class PointExtensions
{
    public static int? DrawOrder(this Point point)
    {
        return point.Children
            .OfType<PointExtension>()
            .FirstOrDefault()
            ?.Value;
    }

    public static void DrawOrder(this Point point, int value)
    {
        PointExtension extension =
            point.Children
                    .OfType<PointExtension>()
                    .FirstOrDefault();

        if (extension == null)
        {
            extension = new PointExtension();
            point.AddChild(extension);
        }

        extension.Value = value;
    }
}

Usage would then be relativly simple:

var point = new Point
{
    Id = "point123",
    AltitudeMode = AltitudeMode.Absolute,
};
point.DrawOrder(123);

Hope that helps and gets you going in the right direction.

@yskific
Copy link
Author

yskific commented Jul 27, 2019

Thanks for your answer.
Even if not documented, if you give geometries a draworder google earth will render it correctly between various ClampedToGround geometries.
There is a difference between the stand-alone and the Online version of GE.
The stand-alone will order Linestring and Polygon type geometries separatly, and you can't be sure to get a the correct order between a LineString and a Polygon. The Online version seems to order all geometries globaly.

@samcragg
Copy link
Owner

samcragg commented Aug 2, 2019

Seeing how the behaviour is not documented and differs between different versions of GE, I don't think it's a feature that can be added to the library (as it will open up questions about it not working correctly).

Thanks for the suggestion though, I hope the workaround code is useful and lets you get closer to achieving your requirements.

@samcragg samcragg closed this as completed Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants