Beispiel #1
0
        public override void Initialize(DrawArgs drawArgs)
        {
            if (m_polygonFeature == null)
            {
                double    offset = 0.02;
                Point3d[] points = new Point3d[4];

                points[0] = new Point3d(
                    m_longitude - offset,
                    m_latitude - offset,
                    200000);

                points[1] = new Point3d(
                    m_longitude - offset,
                    m_latitude + offset,
                    200000);

                points[2] = new Point3d(
                    m_longitude + offset,
                    m_latitude + offset,
                    200000);

                points[3] = new Point3d(
                    m_longitude + offset,
                    m_latitude - offset,
                    200000);

                LinearRing outerRing = new LinearRing();
                outerRing.Points = points;

                m_polygonFeature = new PolygonFeature(
                    name,
                    World,
                    outerRing,
                    null,
                    System.Drawing.Color.Chocolate);

                m_polygonFeature.AltitudeMode = AltitudeMode.Absolute;
                m_polygonFeature.Extrude      = true;
                m_polygonFeature.Outline      = true;
                m_polygonFeature.OutlineColor = System.Drawing.Color.Chocolate;
            }

            FileInfo savedFlagFile   = new FileInfo(SavedImagePath);
            FileInfo placeHolderFile = new FileInfo(SavedImagePath + ".blk");

            if (savedFlagFile.Exists)
            {
                try
                {
                    m_texture = ImageHelper.LoadTexture(
                        savedFlagFile.FullName,
                        System.Drawing.Color.Black.ToArgb());
                }
                catch
                {
                    savedFlagFile.Delete();
                    savedFlagFile.Refresh();
                }
            }

            if (!savedFlagFile.Exists && !placeHolderFile.Exists)
            {
                if (!savedFlagFile.Directory.Exists)
                {
                    savedFlagFile.Directory.Create();
                }
                try
                {
                    // Offline check
                    if (World.Settings.WorkOffline)
                    {
                        throw new Exception("Offline mode active.");
                    }

                    WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri);
                    download.DownloadFile(savedFlagFile.FullName);
                    download.Dispose();
                    savedFlagFile.Refresh();
                }
                catch
                {
                    FileStream fs = placeHolderFile.Create();
                    fs.Close();
                    fs = null;
                    placeHolderFile.Refresh();
                }

                if (savedFlagFile.Exists)
                {
                    m_texture = ImageHelper.LoadTexture(
                        savedFlagFile.FullName,
                        System.Drawing.Color.Black.ToArgb());
                }
            }

            if (m_vertexDeclaration == null)
            {
                VertexElement[] velements = new VertexElement[]
                {
                    new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                    new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
                    new VertexElement(0, 24, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                    VertexElement.VertexDeclarationEnd
                };
                m_vertexDeclaration = new VertexDeclaration(drawArgs.device, velements);
            }

            UpdateVertices();
            isInitialized = true;
        }
Beispiel #2
0
        public override void Initialize(DrawArgs drawArgs)
        {
            if (m_polygonFeature == null)
            {
                double offset = 0.02;

                Point3d[] points = new Point3d[4];



                points[0] = new Point3d(

                    m_longitude - offset,

                    m_latitude - offset,

                    200000);



                points[1] = new Point3d(

                    m_longitude - offset,

                    m_latitude + offset,

                    200000);



                points[2] = new Point3d(

                    m_longitude + offset,

                    m_latitude + offset,

                    200000);



                points[3] = new Point3d(

                    m_longitude + offset,

                    m_latitude - offset,

                    200000);



                LinearRing outerRing = new LinearRing();

                outerRing.Points = points;



                m_polygonFeature = new PolygonFeature(

                    name,

                    World,

                    outerRing,

                    null,

                    System.Drawing.Color.Chocolate);



                m_polygonFeature.AltitudeMode = AltitudeMode.Absolute;

                m_polygonFeature.Extrude = true;

                m_polygonFeature.Outline = true;

                m_polygonFeature.OutlineColor = System.Drawing.Color.Chocolate;
            }



            FileInfo savedFlagFile = new FileInfo(SavedImagePath);

            FileInfo placeHolderFile = new FileInfo(SavedImagePath + ".blk");



            if (savedFlagFile.Exists)
            {
                try
                {
                    m_texture = ImageHelper.LoadTexture(

                        savedFlagFile.FullName,

                        System.Drawing.Color.Black.ToArgb());
                }

                catch
                {
                    savedFlagFile.Delete();

                    savedFlagFile.Refresh();
                }
            }



            if (!savedFlagFile.Exists && !placeHolderFile.Exists)
            {
                if (!savedFlagFile.Directory.Exists)
                {
                    savedFlagFile.Directory.Create();
                }



                try
                {
                    WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri);

                    download.DownloadFile(savedFlagFile.FullName);

                    download.Dispose();



                    savedFlagFile.Refresh();
                }

                catch
                {
                    FileStream fs = placeHolderFile.Create();

                    fs.Close();

                    fs = null;



                    placeHolderFile.Refresh();
                }



                if (savedFlagFile.Exists)
                {
                    m_texture = ImageHelper.LoadTexture(

                        savedFlagFile.FullName,

                        System.Drawing.Color.Black.ToArgb());
                }
            }



            UpdateVertices();

            isInitialized = true;
        }
        private static void addPolygonFeature(XPathNodeIterator iter, World parentWorld, RenderableObjectList parentRenderable)
        {
            if (iter.Count > 0) {
                while (iter.MoveNext()) {
                    string name = getInnerTextFromFirstChild(iter.Current.Select("Name"));

                    string distanceAboveSurfaceString = getInnerTextFromFirstChild(iter.Current.Select("DistanceAboveSurface"));
                    string minimumDisplayAltitudeString = getInnerTextFromFirstChild(iter.Current.Select("MinimumDisplayAltitude"));
                    string maximumDisplayAltitudeString = getInnerTextFromFirstChild(iter.Current.Select("MaximumDisplayAltitude"));
                    string opacityString = getInnerTextFromFirstChild(iter.Current.Select("Opacity"));
                    string extrudeHeightString = getInnerTextFromFirstChild(iter.Current.Select("ExtrudeHeight"));
                    string extrudeUpwardsString = getInnerTextFromFirstChild(iter.Current.Select("ExtrudeUpwards"));
                    string imageUri = getInnerTextFromFirstChild(iter.Current.Select("ImageUri"));
                    string outlineString = getInnerTextFromFirstChild(iter.Current.Select("Outline"));

                    XPathNodeIterator posListIter = iter.Current.Select("exterior/LinearRing/posList");
                    posListIter.MoveNext();

                    string lineString = getInnerTextFromFirstChild(posListIter);

                    string[] lineParts = lineString.Split(' ');
                    Point3d[] points = new Point3d[lineParts.Length];

                    for (int i = 0; i < lineParts.Length; i++) {
                        string[] pointParts = lineParts[i].Split(',');
                        points[i] = new Point3d();
                        points[i].X = ParseDouble(pointParts[0]);
                        points[i].Y = ParseDouble(pointParts[1]);

                        if (pointParts.Length > 2) {
                            points[i].Z = ParseDouble(pointParts[2]);
                        }
                    }

                    Color c = Color.Black;
                    Color outlineColor = Color.Black;

                    if (iter.Current.Select("FeatureColor").Count > 0) {
                        c = getColor(iter.Current.Select("FeatureColor"));
                    }

                    if (iter.Current.Select("OutlineColor").Count > 0) {
                        outlineColor = getColor(iter.Current.Select("OutlineColor"));
                    }

                    PolygonFeature pf = null;

                    pf = new PolygonFeature(name, parentWorld, points, c);

                    pf.OutlineColor = outlineColor;

                    if (outlineString != null
                        && outlineString.Length > 0) {
                        pf.Outline = ParseBool(outlineString);
                    }

                    if (extrudeHeightString != null
                        && extrudeHeightString.Length > 0) {
                        pf.ExtrudeHeight = ParseDouble(extrudeHeightString);
                    }

                    if (opacityString != null
                        && opacityString.Length > 0) {
                        pf.Opacity = byte.Parse(opacityString);
                    }

                    if (distanceAboveSurfaceString != null
                        && distanceAboveSurfaceString.Length > 0) {
                        pf.DistanceAboveSurface = ParseDouble(distanceAboveSurfaceString);
                    }

                    if (minimumDisplayAltitudeString != null
                        && minimumDisplayAltitudeString.Length > 0) {
                        pf.MinimumDisplayAltitude = ParseDouble(minimumDisplayAltitudeString);
                    }

                    if (maximumDisplayAltitudeString != null
                        && maximumDisplayAltitudeString.Length > 0) {
                        pf.MaximumDisplayAltitude = ParseDouble(maximumDisplayAltitudeString);
                    }

                    if (extrudeUpwardsString != null
                        && extrudeUpwardsString.Length > 0) {
                        pf.ExtrudeUpwards = ParseBool(extrudeUpwardsString);
                    }

                    addExtendedInformation(iter.Current.Select("ExtendedInformation"), pf);

                    string infoUri = iter.Current.GetAttribute("InfoUri", "");

                    if (infoUri != null
                        && infoUri.Length > 0) {
                        if (pf.MetaData.Contains("InfoUri")) {
                            pf.MetaData["InfoUri"] = infoUri;
                        }
                        else {
                            pf.MetaData.Add("InfoUri", infoUri);
                        }
                    }

                    pf.MetaData.Add("XmlSource", (string) parentRenderable.MetaData["XmlSource"]);
                    pf.ParentList = parentRenderable;

                    if (World.Settings.useDefaultLayerStates) {
                        pf.IsOn = ParseBool(iter.Current.GetAttribute("ShowAtStartup", ""));
                    }
                    else {
                        pf.IsOn = IsLayerOn(pf);
                    }
                    parentRenderable.ChildObjects.Add(pf);

                    parentRenderable.RenderPriority = RenderPriority.LinePaths;
                }
            }
        }