コード例 #1
0
        private static IEnumerable <ImageOverlay> ReadGroundOverlays(XmlDocument kmlDocument)
        {
            foreach (XmlElement groundOverlayElement in kmlDocument.GetElementsByTagName("GroundOverlay"))
            {
                LatLonBox latLonBox = null;
                string    imagePath = null;
                int       zIndex    = 0;

                foreach (var childElement in groundOverlayElement.ChildNodes.OfType <XmlElement>())
                {
                    switch (childElement.LocalName)
                    {
                    case "LatLonBox":
                        latLonBox = ReadLatLonBox(childElement);
                        break;

                    case "Icon":
                        imagePath = ReadImagePath(childElement);
                        break;

                    case "drawOrder":
                        int.TryParse(childElement.InnerText.Trim(), out zIndex);
                        break;
                    }
                }

                if (latLonBox != null && imagePath != null)
                {
                    yield return(new ImageOverlay(latLonBox, imagePath, zIndex));
                }
            }
        }
コード例 #2
0
        // Rotation of corners of map
        private List <Tuple <double, double> > GetCornersWithRotation(LatLonBox latLonBox)
        {
            double n        = (double)latLonBox.North;
            double s        = (double)latLonBox.South;
            double e        = (double)latLonBox.East;
            double w        = (double)latLonBox.West;
            double rotation = (double)latLonBox.Rotation;

            double a      = (e + w) / 2.0;
            double b      = (n + s) / 2.0;
            double squish = Math.Cos(DegToRad(b));
            double x      = squish * (e - w) / 2.0;
            double y      = (n - s) / 2.0;

            double X, Y;
            List <Tuple <double, double> > corners = new List <Tuple <double, double> >();

            X = b - (x * Math.Sin(DegToRad(rotation)) - y * Math.Cos(DegToRad(rotation)));
            Y = a - (x * Math.Cos(DegToRad(rotation)) + y * Math.Sin(DegToRad(rotation))) / squish;
            corners.Add(Tuple.Create(X, Y));
            X = b + (x * Math.Sin(DegToRad(rotation)) + y * Math.Cos(DegToRad(rotation)));
            Y = a + (x * Math.Cos(DegToRad(rotation)) - y * Math.Sin(DegToRad(rotation))) / squish;
            corners.Add(Tuple.Create(X, Y));
            X = b - (x * Math.Sin(DegToRad(rotation)) + y * Math.Cos(DegToRad(rotation)));
            Y = a - (x * Math.Cos(DegToRad(rotation)) - y * Math.Sin(DegToRad(rotation))) / squish;
            corners.Add(Tuple.Create(X, Y));
            X = b + (x * Math.Sin(DegToRad(rotation)) - y * Math.Cos(DegToRad(rotation)));
            Y = a + (x * Math.Cos(DegToRad(rotation)) + y * Math.Sin(DegToRad(rotation))) / squish;
            corners.Add(Tuple.Create(X, Y));
            X = b - (x * Math.Sin(DegToRad(rotation)) - y * Math.Cos(DegToRad(rotation)));
            Y = a - (x * Math.Cos(DegToRad(rotation)) + y * Math.Sin(DegToRad(rotation))) / squish;
            corners.Add(Tuple.Create(X, Y));;
            return(corners);
        }
コード例 #3
0
        private List <Tuple <double, double> > GetCornersWithoutRotation(LatLonBox latLonBox)
        {
            List <Tuple <double, double> > corners = new List <Tuple <double, double> > ();

            corners.Add(Tuple.Create((double)latLonBox.North, (double)latLonBox.West));
            corners.Add(Tuple.Create((double)latLonBox.North, (double)latLonBox.East));
            corners.Add(Tuple.Create((double)latLonBox.South, (double)latLonBox.East));
            corners.Add(Tuple.Create((double)latLonBox.South, (double)latLonBox.West));
            corners.Add(Tuple.Create((double)latLonBox.North, (double)latLonBox.West));
            return(corners);
        }
コード例 #4
0
        private List <Tuple <double, double> > GetMapCorners(LatLonBox latLonBox)
        {
            if (latLonBox != null)
            {
                if (latLonBox.North != null &&
                    latLonBox.South != null &&
                    latLonBox.East != null &&
                    latLonBox.West != null)
                {
                    if (latLonBox.Rotation != null)
                    {
                        return(GetCornersWithRotation(latLonBox));
                    }

                    return(GetCornersWithoutRotation(latLonBox));
                }
            }
            return(null);
        }
コード例 #5
0
 public ImageOverlay(LatLonBox latLonBox, string imagePath, int zIndex)
 {
     LatLonBox = latLonBox;
     ImagePath = imagePath;
     ZIndex    = zIndex;
 }
コード例 #6
0
    /// <summary>
    /// This method stores the given box into the database
    /// </summary>
    /// <param name="box">Box to be saved</param>
    /// <param name="insertedKmlId">The KmlId to connect this object to</param>
    /// <param name="con">Sql connection</param>
    /// <param name="tran">Sql transaction</param>
    /// <returns>The database id which is assigned to the given box</returns>
    protected static int?SaveLatLonBox(Geography box, int insertedKmlId, SqlConnection con, SqlTransaction tran)
    {
        #region Insert Geography

        int?insertedGeographyId = null;

        if (box != null)
        {
            SqlCommand saveGeographyCmd =
                new SqlCommand(
                    " insert into Geographies(Geography, KmlId) " +
                    " values(geography::Parse('" + box.ToString() + "'), @KmlId);select scope_identity()", con, tran);

            AddParameter(saveGeographyCmd, "KmlId", insertedKmlId, DbType.Int32);

            insertedGeographyId = (int)((decimal)saveGeographyCmd.ExecuteScalar());
            box.DbId            = insertedGeographyId;
        }

        #endregion

        #region Insert Lat Lon Box

        SqlCommand saveLatLonBox =
            new SqlCommand(
                " insert into LatLonBoxes(BoxType, GeographyId, rotation, MinAlt, MaxAlt, AltitudeMode) " +
                " values(@BoxType, @GeographyId, @rotation, @MinAlt, @MaxAlt, @AltitudeMode);select scope_identity()",
                con, tran);

        AddParameter(saveLatLonBox, "GeographyId", insertedGeographyId, DbType.Int32);

        LatLonBox    latLonBox    = box as LatLonBox;
        LatLonAltBox latLonAltBox = box as LatLonAltBox;
        LatLonQuad   latLonQuad   = box as LatLonQuad;

        string BoxType = "";

        if (latLonBox != null)
        {
            BoxType = "LatLonBox";
            AddParameter(saveLatLonBox, "rotation", latLonBox.Rotation, DbType.Double);
        }
        else
        {
            AddParameter(saveLatLonBox, "rotation", null, DbType.Double);
        }

        if (latLonAltBox != null)
        {
            BoxType = "LatLonAltBox";

            AddParameter(saveLatLonBox, "MinAlt", latLonAltBox.MinAltitude, DbType.Double);
            AddParameter(saveLatLonBox, "MaxAlt", latLonAltBox.MaxAltitude, DbType.Double);
            AddParameter(saveLatLonBox, "AltitudeMode", latLonAltBox.AltitudeMode.ToString(), DbType.String);
        }
        else
        {
            AddParameter(saveLatLonBox, "MinAlt", null, DbType.Double);
            AddParameter(saveLatLonBox, "MaxAlt", null, DbType.Double);
            AddParameter(saveLatLonBox, "AltitudeMode", null, DbType.Double);
        }

        if (latLonQuad != null)
        {
            BoxType = "LatLonQuad";
        }

        AddParameter(saveLatLonBox, "BoxType", BoxType, DbType.String);

        int?insertedLatLonBox = (int)((decimal)saveLatLonBox.ExecuteScalar());

        #endregion

        return(insertedLatLonBox);
    }