//private List<TtPoint> origPoints;
        //private DataAccessLayer _db;
        //Dictionary<string, TtMetaData> metas;
        public SegmentFactory(DataAccessLayer dal)
        {
            Dictionary<string, TtMetaData> meta = dal.GetMetaData().ToDictionary(m => m.CN, m => m);
            polys = dal.GetPolygons().ToDictionary(p => p.CN, p => p);

            List<TtPoint> tmpWayPoints = new List<TtPoint>();
            Dictionary<string, TtPoint> tmpPoints = new Dictionary<string, TtPoint>();

            foreach (TtPoint p in dal.GetPoints())
            {
                if (p.op == OpType.WayPoint)
                {
                    p.CalculatePoint();
                    p.AdjustPoint();
                    tmpWayPoints.Add(p);
                }
                else
                {
                    tmpPoints.Add(p.CN, p);

                    if (p.IsTravType())
                    {
                        ((SideShotPoint)p).Declination = meta[p.MetaDefCN].magDec;
                    }
                }
            }

            if (tmpWayPoints.Count > 0)
            {
                dal.SavePoints(tmpWayPoints, tmpWayPoints);
            }

            QuondamPoint qp;
            foreach (TtPoint p in tmpPoints.Values)
            {
                if (p.op == OpType.Quondam)
                {
                    qp = p as QuondamPoint;
                    qp.ParentPoint = tmpPoints[qp.ParentCN];
                }
            }

            points = tmpPoints.Values.ToList();
        }
        private void loadListbox(DataAccessLayer d)
        {
            dal = d;

            int w = lstPolygons.Width;

            lstPolygons.Columns.Add("Polygons", w / 4, HorizontalAlignment.Left);
            lstPolygons.Columns.Add("Points", w / 5,HorizontalAlignment.Left);
            lstPolygons.Columns.Add("Area (Ac)", -1, HorizontalAlignment.Left);

            /*
            lstPolygons.Columns.Add("Polygons", 100, HorizontalAlignment.Left);
            lstPolygons.Columns.Add("Points",50,HorizontalAlignment.Left);
            lstPolygons.Columns.Add("Area (Ac)", 70, HorizontalAlignment.Left);
            */

            cboLabels.Items.Add("None");
            cboLabels.Items.Add("All");

            if(dal != null)
            {
                List<TtPolygon> polys = dal.GetPolygons();
                allPolyCNs = new List<string>();

                TtPolygon poly;

                for (int i = 0; i < polys.Count; i++)
                {
                    poly = polys[i];

                    ListViewItem l = new ListViewItem(poly.Name);
                    l.SubItems.Add(dal.GetPointCount(poly.CN).ToString());
                    //l.SubItems.Add((polys[i].Area / 1000).ToString());
                    l.SubItems.Add(TtUtils.ConvertMeters2ToAcres(poly.Area).ToString());
                    allPolyCNs.Add(poly.CN);

                    if (i % 2 == 1)
                        l.BackColor = Color.LightGray;

                    lstPolygons.Items.Add(l);
                    cboLabels.Items.Add(poly.Name);

                    if (MapValues.mapPolyLabels == poly.CN)
                        cboLabels.SelectedIndex = i + 2;
                }

                if (MapValues.mapPolyLabels == Values.EmptyGuid)
                    cboLabels.SelectedIndex = 0;

                if (MapValues.mapPolyLabels == Values.FullGuid)
                    cboLabels.SelectedIndex = 1;

                lstPolygons.CheckBoxes = true;
            }

            #if !(PocketPC || WindowsCE || Mobile)
            lstPolygons.Columns[0].Width = -2;
            lstPolygons.Columns[1].Width = -2;
            lstPolygons.Columns[2].Width = -2;
            #endif
        }
Ejemplo n.º 3
0
        public KmlDocument CreateKmlDoc(DataAccessLayer DAL)
        {
            #region Create Document

            KmlDocument doc = new KmlDocument(Values.Settings.ProjectOptions.ProjectName, Values.Settings.ProjectOptions.Description);

            doc.Open = true;
            doc.Properties = new KmlProperties();
            doc.Properties.Snippit = "Generated in TwoTrails";
            doc.Visibility = true;

            #endregion

            #region Create Styles / StyleMaps

            const int AdjLineSize = 5;
            const int UnAdjLineSize = 7;

            KmlStyle sAdjBound = new KmlStyle("AdjBound");
            KmlStyle sUnAdjBound = new KmlStyle("UnAdjBound");
            KmlStyle sAdjNav = new KmlStyle("AdjNav");
            KmlStyle sUnAdjNav = new KmlStyle("UnAdjNav");
            KmlStyle sAdjMisc = new KmlStyle("AdjMisc");
            KmlStyle sUnAdjMisc = new KmlStyle("UnAdjMisc");
            KmlStyle sWay = new KmlStyle("Way");

            KmlColor AdjBoundColor = new KmlColor(27, 211, 224, 255);   //1BD3E0
            KmlColor UnAdjBoundColor = new KmlColor(27, 112, 224, 255); //1B70E0
            KmlColor AdjNavColor = new KmlColor(27, 224, 142, 255);     //1BE08E
            KmlColor UnAdjNavColor = new KmlColor(14, 168, 86, 255);    //0E8A56
            KmlColor AdjMiscColor = new KmlColor(234, 90, 250, 255);    //EA5AFA
            KmlColor UnAdjMiscColor = new KmlColor(164, 29, 179, 255);  //A41DB3
            KmlColor WayColor = new KmlColor(255, 0, 0, 255);           //FF0000
            KmlColor KmlWhite = new KmlColor(255, 255, 255, 255);       //FFFFFF

            sAdjBound.SetColorsILP(AdjBoundColor);
            sAdjBound.IconScale = 1;
            sAdjBound.LineWidth = AdjLineSize;
            sAdjBound.LineLabelVisibility = true;
            sAdjBound.PolygonFill = false;
            sAdjBound.PolygonOutline = true;
            sAdjBound.BalloonDisplayMode = DisplayMode.Default;

            sUnAdjBound.SetColorsILP(UnAdjBoundColor);
            sUnAdjBound.IconScale = 1;
            sUnAdjBound.LineWidth = UnAdjLineSize;
            sUnAdjBound.LineLabelVisibility = false;
            sUnAdjBound.PolygonFill = false;
            sUnAdjBound.PolygonOutline = true;
            sUnAdjBound.BalloonDisplayMode = DisplayMode.Default;

            sAdjNav.SetColorsILP(AdjNavColor);
            sAdjNav.IconScale = 1;
            sAdjNav.LineWidth = AdjLineSize;
            sAdjNav.LineLabelVisibility = false;
            sAdjNav.PolygonFill = false;
            sAdjNav.PolygonOutline = true;
            sAdjNav.BalloonDisplayMode = DisplayMode.Default;

            sUnAdjNav.SetColorsILP(UnAdjNavColor);
            sUnAdjNav.IconScale = 1;
            sUnAdjNav.LineWidth = UnAdjLineSize;
            sUnAdjNav.LineLabelVisibility = false;
            sUnAdjNav.PolygonFill = false;
            sUnAdjNav.PolygonOutline = true;
            sUnAdjNav.BalloonDisplayMode = DisplayMode.Default;

            sUnAdjMisc.IconColorMode = ColorMode.Normal;
            sUnAdjMisc.IconColor = UnAdjMiscColor;
            sUnAdjMisc.IconScale = 1;
            sUnAdjMisc.BalloonDisplayMode = DisplayMode.Default;

            sWay.IconColorMode = ColorMode.Normal;
            sWay.IconColor = WayColor;
            sWay.IconScale = 1;
            sWay.BalloonDisplayMode = DisplayMode.Default;

            KmlStyle sAdjBoundH = new KmlStyle(sAdjBound, "AdjBoundH");
            KmlStyle sUnAdjBoundH = new KmlStyle(sUnAdjBound, "UnAdjBoundH");
            KmlStyle sAdjNavH = new KmlStyle(sAdjNav, "AdjNavH");
            KmlStyle sUnAdjNavH = new KmlStyle(sUnAdjNav, "UnAdjNavH");
            KmlStyle sAdjMiscH = new KmlStyle(sAdjMisc, "AdjMiscH");
            KmlStyle sUnAdjMiscH = new KmlStyle(sUnAdjMisc, "UnAdjMiscH");
            KmlStyle sWayH = new KmlStyle(sWay, "WayH");

            sAdjBoundH.IconScale = 1.1;
            sAdjBoundH.IconColor = KmlWhite;
            sUnAdjBoundH.IconScale = 1.1;
            sUnAdjBoundH.IconColor = KmlWhite;
            sAdjNavH.IconScale = 1.1;
            sAdjNavH.IconColor = KmlWhite;
            sUnAdjNavH.IconScale = 1.1;
            sUnAdjNavH.IconColor = KmlWhite;
            sAdjMiscH.IconScale = 1.1;
            sAdjMiscH.IconColor = KmlWhite;
            sUnAdjMiscH.IconScale = 1.1;
            sUnAdjMiscH.IconColor = KmlWhite;
            sWayH.IconScale = 1.1;
            sWayH.IconColor = KmlWhite;

            doc.AddStyle(sAdjBound);
            doc.AddStyle(sAdjBoundH);
            doc.AddStyle(sUnAdjBound);
            doc.AddStyle(sUnAdjBoundH);
            doc.AddStyle(sAdjNav);
            doc.AddStyle(sAdjNavH);
            doc.AddStyle(sUnAdjNav);
            doc.AddStyle(sUnAdjNavH);
            doc.AddStyle(sAdjMisc);
            doc.AddStyle(sAdjMiscH);
            doc.AddStyle(sUnAdjMisc);
            doc.AddStyle(sUnAdjMiscH);
            doc.AddStyle(sWay);
            doc.AddStyle(sWayH);

            KmlStyleMap sAdjBoundMap = new KmlStyleMap("AdjBoundMap", sAdjBound.StyleUrl, sAdjBoundH.StyleUrl);
            KmlStyleMap sUnAdjBoundMap = new KmlStyleMap("UnAdjBoundMap", sUnAdjBound.StyleUrl, sUnAdjBoundH.StyleUrl);
            KmlStyleMap sAdjNavMap = new KmlStyleMap("AdjNavMap", sAdjNav.StyleUrl, sAdjNavH.StyleUrl);
            KmlStyleMap sUnAdjNavMap = new KmlStyleMap("UnAdjNavMap", sUnAdjNav.StyleUrl, sUnAdjNavH.StyleUrl);
            KmlStyleMap sAdjMiscMap = new KmlStyleMap("AdjMiscMap", sAdjMisc.StyleUrl, sAdjMiscH.StyleUrl);
            KmlStyleMap sUnAdjMiscMap = new KmlStyleMap("UnAdjMiscMap", sUnAdjMisc.StyleUrl, sUnAdjMiscH.StyleUrl);
            KmlStyleMap sWayMap = new KmlStyleMap("WayMap", sWay.StyleUrl, sWayH.StyleUrl);

            doc.AddStyleMap(sAdjBoundMap);
            doc.AddStyleMap(sUnAdjBoundMap);
            doc.AddStyleMap(sAdjNavMap);
            doc.AddStyleMap(sUnAdjNavMap);
            doc.AddStyleMap(sAdjMiscMap);
            doc.AddStyleMap(sUnAdjMiscMap);
            doc.AddStyleMap(sWayMap);

            #endregion

            #region Create Polygons

            List<TtPolygon> polys = DAL.GetPolygons();

            foreach (TtPolygon poly in polys)
            {
                List<TtPoint> points = DAL.GetPointsInPolygon(poly.CN);

                #region Create root Polygon Folder
                KmlFolder folder = new KmlFolder(poly.Name, poly.Description);

                folder.Open = false;
                folder.Visibility = true;

                folder.Properties = new KmlProperties();
                folder.Properties.Snippit = poly.Description;
                folder.Properties.ExtendedData = new KmlExtendedData();
                folder.Properties.ExtendedData.AddData(new KmlExtendedData.Data(" ", "In Meters"));
                folder.Properties.ExtendedData.AddData(new KmlExtendedData.Data("Accuracy", poly.PolyAccu.ToString()));
                folder.Properties.ExtendedData.AddData(new KmlExtendedData.Data("Perimeter", poly.Perimeter.ToString()));
                folder.Properties.ExtendedData.AddData(new KmlExtendedData.Data("Area", poly.Area.ToString()));
                #endregion

                #region Create SubFolders under Polygon root
                KmlFolder fAdjBound = new KmlFolder("AdjBound", "Adjusted Boundary Polygon");
                KmlFolder fUnAdjBound = new KmlFolder("UnAdjBound", "UnAdjusted Boundary Polygon");
                KmlFolder fAdjNav = new KmlFolder("AdjNav", "Adjusted Navigation Polygon");
                KmlFolder fUnAdjNav = new KmlFolder("UnAdjNav", "UnAdjusted Navigation Polygon");
                KmlFolder fMiscPoints = new KmlFolder("Misc", "Misc Points");
                KmlFolder fWayPoints = new KmlFolder("Waypoints", "Waypoints");

                fAdjBound.StyleUrl = sAdjBoundMap.StyleUrl;
                fUnAdjBound.StyleUrl = sUnAdjBoundMap.StyleUrl;
                fAdjNav.StyleUrl = sAdjNavMap.StyleUrl;
                fUnAdjNav.StyleUrl = sUnAdjNavMap.StyleUrl;
                fMiscPoints.StyleUrl = sAdjMiscMap.StyleUrl;
                fWayPoints.StyleUrl = sWayMap.StyleUrl;

                fAdjBound.Visibility = true;
                fUnAdjBound.Visibility = false;
                fAdjNav.Visibility = false;
                fUnAdjNav.Visibility = false;
                fMiscPoints.Visibility = false;
                fWayPoints.Visibility = false;

                fAdjBound.Open = false;
                fUnAdjBound.Open = false;
                fAdjNav.Open = false;
                fUnAdjNav.Open = false;
                fMiscPoints.Open = false;
                fWayPoints.Open = false;

                #endregion

                #region Create SubFolders for Bound, Nav and Misc

                KmlFolder fAdjBoundPoints = new KmlFolder("Points", "Adjusted Boundary Points");
                KmlFolder fUnAdjBoundPoints = new KmlFolder("Points", "UnAdjusted Boundary Points");
                KmlFolder fAdjNavPoints = new KmlFolder("Points", "Adjusted Navigation Points");
                KmlFolder fUnAdjNavPoints = new KmlFolder("Points", "UnAdjusted Navigation Points");
                KmlFolder fAdjMiscPoints = new KmlFolder("Adj Points", "Adjusted Misc Points");
                KmlFolder fUnAdjMiscPoints = new KmlFolder("UnAdj Points", "UnAdjusted Misc Points");

                fAdjBoundPoints.Visibility = true;
                fUnAdjBoundPoints.Visibility = false;
                fAdjNavPoints.Visibility = false;
                fUnAdjNavPoints.Visibility = false;
                fAdjMiscPoints.Visibility = false;
                fUnAdjMiscPoints.Visibility = false;

                fAdjBoundPoints.Open = false;
                fUnAdjBoundPoints.Open = false;
                fAdjNavPoints.Open = false;
                fUnAdjNavPoints.Open = false;
                fAdjMiscPoints.Open = false;
                fUnAdjMiscPoints.Open = false;
                #endregion

                #region Create Geometry

                KmlPolygon AdjBoundPoly = new KmlPolygon("AdjBoundPoly");
                KmlPolygon UnAdjBoundPoly = new KmlPolygon("UnAdjBoundPoly");
                List<Coordinates> AdjBoundPointList = new List<Coordinates>();
                List<Coordinates> UnAdjBoundPointList = new List<Coordinates>();

                KmlPolygon AdjNavPoly = new KmlPolygon("AdjNavPoly");
                KmlPolygon UnAdjNavPoly = new KmlPolygon("UnAdjNavPoly");
                List<Coordinates> AdjNavPointList = new List<Coordinates>();
                List<Coordinates> UnAdjNavPointList = new List<Coordinates>();

                AdjBoundPoly.AltMode = AltitudeMode.clampToGround;
                UnAdjBoundPoly.AltMode = AltitudeMode.clampToGround;
                AdjNavPoly.AltMode = AltitudeMode.clampToGround;
                UnAdjNavPoly.AltMode = AltitudeMode.clampToGround;

                AdjBoundPoly.IsPath = false;
                UnAdjBoundPoly.IsPath = false;
                AdjNavPoly.IsPath = true;
                UnAdjNavPoly.IsPath = true;

                #endregion

                #region Add Placemarks

                TtMetaData md = null;

                if (points.Count > 0)
                {
                    md = DAL.GetMetaDataByCN(Values.EmptyGuid);

                    if (md == null)
                        md = DAL.GetMetaData()[0];

                    if (md == null)
                        throw new Exception("Meta Data is null. Cant obtain UTM Zone");
                }

                foreach (TtPoint point in points)
                {
                    double lat, lon;
                    TtUtils.UTMtoLatLon(point.AdjX, point.AdjY, md.Zone, out lat, out lon);
                    Coordinates adjCoord = new Coordinates(lat, lon, point.AdjZ);

                    TtUtils.UTMtoLatLon(point.UnAdjX, point.UnAdjY, md.Zone, out lat, out lon);
                    Coordinates unAdjCoord = new Coordinates(lat, lon, point.UnAdjZ);

                    string snippit = "Point Operation: " + point.op.ToString();

                    #region Create Placemarks for Bound/Nav

                    KmlPlacemark adjPm = new KmlPlacemark(point.PID.ToString(),
                        String.Format("Point Operation: {0}<br><div>\t     Adjusted<br>UtmX: {1}<br>UtmY: {2}</div><br>{3}",
                            point.op.ToString(), point.AdjX, point.AdjY, point.Comment));
                    adjPm.View = new KmlView();
                    adjPm.View.TimeStamp = point.Time;
                    adjPm.View.Coordinates = adjCoord;
                    adjPm.View.Tilt = 15;
                    adjPm.View.AltMode = AltitudeMode.clampToGround;
                    adjPm.View.Range = 150;

                    adjPm.Properties = new KmlProperties();
                    adjPm.Properties.Snippit = snippit;

                    adjPm.StyleUrl = sAdjBoundMap.StyleUrl;
                    adjPm.Open = false;
                    adjPm.Visibility = false;
                    adjPm.AddPoint(new KmlPoint(adjCoord, AltitudeMode.clampToGround));

                    KmlPlacemark unAdjPm = new KmlPlacemark(point.PID.ToString(),
                        String.Format("Point Operation: {0}<br><div>     Unadjusted<br>UtmX: {1}<br>UtmY: {2}</div><br>{3}",
                            point.op.ToString(), point.UnAdjX, point.UnAdjY, point.Comment));
                    unAdjPm.View = new KmlView();
                    unAdjPm.View.TimeStamp = point.Time;
                    unAdjPm.View.Coordinates = adjCoord;
                    unAdjPm.View.Tilt = 15;
                    unAdjPm.View.AltMode = AltitudeMode.clampToGround;
                    unAdjPm.View.Range = 150;

                    unAdjPm.Properties = new KmlProperties();
                    unAdjPm.Properties.Snippit = snippit;

                    unAdjPm.StyleUrl = sUnAdjBoundMap.StyleUrl;
                    unAdjPm.Open = false;
                    unAdjPm.Visibility = false;
                    unAdjPm.AddPoint(new KmlPoint(adjCoord, AltitudeMode.clampToGround));

                    #endregion

                    #region Add points and placemarks to lists
                    if (point.IsBndPoint())
                    {
                        AdjBoundPointList.Add(adjCoord);
                        UnAdjBoundPointList.Add(unAdjCoord);
                        fAdjBoundPoints.AddPlacemark(new KmlPlacemark(adjPm));
                        fUnAdjBoundPoints.AddPlacemark(new KmlPlacemark(unAdjPm));
                    }

                    unAdjPm.StyleUrl = String.Copy(sUnAdjNavMap.StyleUrl);
                    adjPm.StyleUrl = String.Copy(sAdjNavMap.StyleUrl);
                    adjPm.Visibility = false;

                    if (point.IsNavPoint())
                    {
                        AdjNavPointList.Add(adjCoord);
                        UnAdjNavPointList.Add(unAdjCoord);
                        fAdjNavPoints.AddPlacemark(new KmlPlacemark(adjPm));
                        fUnAdjNavPoints.AddPlacemark(new KmlPlacemark(unAdjPm));
                    }
                    else if (point.op == OpType.Quondam)
                    {
                        QuondamPoint p = point as QuondamPoint;

                        if (p.IsNavPoint())
                        {
                            AdjNavPointList.Add(adjCoord);
                            UnAdjNavPointList.Add(unAdjCoord);
                            fAdjNavPoints.AddPlacemark(new KmlPlacemark(adjPm));
                            fUnAdjNavPoints.AddPlacemark(new KmlPlacemark(unAdjPm));
                        }
                    }

                    #region Create Way / Misc point placemarks

                    unAdjPm.StyleUrl = String.Copy(sWayMap.StyleUrl);

                    if (point.op == OpType.WayPoint)
                    {
                        fWayPoints.AddPlacemark(new KmlPlacemark(unAdjPm));
                    }

                    #endregion
                    #endregion
                }

                #region Create Poly Placemarks

                //assign points to polys

                if(AdjBoundPointList.Count > 0)
                    AdjBoundPointList.Add(AdjBoundPointList[0]);
                if(UnAdjBoundPointList.Count > 0)
                    UnAdjBoundPointList.Add(UnAdjBoundPointList[0]);

                AdjBoundPoly.OuterBoundary = AdjBoundPointList;
                UnAdjBoundPoly.OuterBoundary = UnAdjBoundPointList;
                AdjNavPoly.OuterBoundary = AdjNavPointList;
                UnAdjNavPoly.OuterBoundary = UnAdjNavPointList;

                //get default data for the placemarks
                KmlView.KmlTimeSpan ts = null;
                if(points.Count > 0 )
                    new KmlView.KmlTimeSpan(points[0].Time, points[points.Count - 1].Time);
                KmlPolygon.Dimensions adjDim = AdjBoundPoly.GetOuterDimensions();
                KmlPolygon.Dimensions unAdjDim = UnAdjBoundPoly.GetOuterDimensions();

                double? adjRange = null;
                double? unAdjRange = null;
                double? width;

                if (adjDim != null)
                {
                    adjRange = TtUtils.DistanceLatLon(0, adjDim.North, 0, adjDim.South);
                    width = TtUtils.DistanceLatLon(adjDim.East, 0, adjDim.West, 0);

                    if (width != null && width > adjRange)
                        adjRange = width;
                }

                if (unAdjDim != null)
                {
                    unAdjRange = TtUtils.DistanceLatLon(0, unAdjDim.North, 0, unAdjDim.South);
                    width = TtUtils.DistanceLatLon(unAdjDim.East, 0, unAdjDim.West, 0);

                    if (width != null && width > unAdjRange)
                        unAdjRange = width;
                }

                if (adjRange == null)
                    adjRange = 1000;
                else
                    adjRange *= 1.1;
                if (unAdjRange == null)
                    unAdjRange = 1000;
                else
                    unAdjRange *= 1.1;

                //AdjBoundPlacemark
                KmlPlacemark AdjBoundPlacemark = new KmlPlacemark("AdjBoundPoly", "Adjusted Boundary Polygon", new KmlView());
                AdjBoundPlacemark.View.AltMode = AltitudeMode.clampToGround;
                AdjBoundPlacemark.View.Coordinates = AdjBoundPoly.AveragedCoords;
                if (points.Count > 1)
                    AdjBoundPlacemark.View.TimeSpan = ts;
                AdjBoundPlacemark.View.Range = (double)adjRange;
                AdjBoundPlacemark.View.Tilt = 5;

                AdjBoundPlacemark.Properties = new KmlProperties();
                AdjBoundPlacemark.Properties.Snippit = poly.Description;

                AdjBoundPlacemark.Open = false;
                AdjBoundPlacemark.Visibility = true;
                AdjBoundPlacemark.AddPolygon(AdjBoundPoly);
                AdjBoundPlacemark.StyleUrl = sAdjBoundMap.StyleUrl;

                //UnAdjBoundPlacemark
                KmlPlacemark UnAdjBoundPlacemark = new KmlPlacemark("UnAdjBoundPoly", "UnAdjusted Boundary Polygon", new KmlView());
                UnAdjBoundPlacemark.View.AltMode = AltitudeMode.clampToGround;
                UnAdjBoundPlacemark.View.Coordinates = UnAdjBoundPoly.AveragedCoords;
                if (points.Count > 1)
                    UnAdjBoundPlacemark.View.TimeSpan = ts;
                UnAdjBoundPlacemark.View.Range = (double)unAdjRange;
                UnAdjBoundPlacemark.View.Tilt = 5;

                UnAdjBoundPlacemark.Properties = new KmlProperties();
                UnAdjBoundPlacemark.Properties.Snippit = poly.Description;

                UnAdjBoundPlacemark.Open = false;
                UnAdjBoundPlacemark.Visibility = false;
                UnAdjBoundPlacemark.AddPolygon(UnAdjBoundPoly);
                UnAdjBoundPlacemark.StyleUrl = sUnAdjBoundMap.StyleUrl;

                //AdjNavPlacemark
                KmlPlacemark AdjNavPlacemark = new KmlPlacemark("AdjNavPoly", "Adjusted Navigation Path", new KmlView());
                AdjNavPlacemark.View.AltMode = AltitudeMode.clampToGround;
                AdjNavPlacemark.View.Coordinates = AdjNavPoly.AveragedCoords;
                if (points.Count > 1)
                    AdjNavPlacemark.View.TimeSpan = ts;
                AdjNavPlacemark.View.Range = (double)adjRange;
                AdjNavPlacemark.View.Tilt = 5;

                AdjNavPlacemark.Properties = new KmlProperties();
                AdjNavPlacemark.Properties.Snippit = poly.Description;

                AdjNavPlacemark.Open = false;
                AdjNavPlacemark.Visibility = false;
                AdjNavPlacemark.AddPolygon(AdjNavPoly);
                AdjNavPlacemark.StyleUrl = sAdjNavMap.StyleUrl;

                //UnAdjNavPlacemark
                KmlPlacemark UnAdjNavPlacemark = new KmlPlacemark("UnAdjNavPoly", "UnAdjusted Navigation Path", new KmlView());
                UnAdjNavPlacemark.View.AltMode = AltitudeMode.clampToGround;
                UnAdjNavPlacemark.View.Coordinates = UnAdjNavPoly.AveragedCoords;
                if (points.Count > 1)
                    UnAdjNavPlacemark.View.TimeSpan = ts;
                UnAdjNavPlacemark.View.Range = (double)unAdjRange;
                UnAdjNavPlacemark.View.Tilt = 5;

                UnAdjNavPlacemark.Properties = new KmlProperties();
                UnAdjNavPlacemark.Properties.Snippit = poly.Description;

                UnAdjNavPlacemark.Open = false;
                UnAdjNavPlacemark.Visibility = false;
                UnAdjNavPlacemark.AddPolygon(UnAdjNavPoly);
                UnAdjNavPlacemark.StyleUrl = sUnAdjNavMap.StyleUrl;

                //add placemarks
                fAdjBound.AddPlacemark(AdjBoundPlacemark);
                fUnAdjBound.AddPlacemark(UnAdjBoundPlacemark);
                fAdjNav.AddPlacemark(AdjNavPlacemark);
                fUnAdjNav.AddPlacemark(UnAdjNavPlacemark);

                #endregion

                #endregion

                #region Add Folders To eachother
                //added point folders to bound/nav/misc folders
                fAdjBound.AddFolder(fAdjBoundPoints);
                fUnAdjBound.AddFolder(fUnAdjBoundPoints);
                fAdjNav.AddFolder(fAdjNavPoints);
                fUnAdjNav.AddFolder(fUnAdjNavPoints);
                fMiscPoints.AddFolder(fAdjMiscPoints);
                fMiscPoints.AddFolder(fUnAdjMiscPoints);

                //add bound/nav/misc/way folders to root polygon folder
                folder.AddFolder(fAdjBound);
                folder.AddFolder(fUnAdjBound);
                folder.AddFolder(fAdjNav);
                folder.AddFolder(fUnAdjNav);
                folder.AddFolder(fMiscPoints);
                folder.AddFolder(fWayPoints);

                //add polygon root to KmlDoc
                doc.AddFolder(folder);
                #endregion
            }

            #endregion

            return doc;
        }
Ejemplo n.º 4
0
        public void WriteShapeFiles(DataAccessLayer DAL)
        {
            #if !(PocketPC || WindowsCE || Mobile)
            List<TtPolygon> polys = DAL.GetPolygons();
            Dictionary<string, TtMetaData> metas = DAL.GetMetaData().ToDictionary(m => m.CN, m => m);

            string folder = SelectedPath + "\\GIS";
            Directory.CreateDirectory(folder);

            foreach (TtPolygon poly in polys)
            {
                string _CurrDir = String.Format("{0}\\{1}\\", folder, poly.Name.ScrubFileName());
                string _File = String.Format("{0}\\{1}\\{1}", folder, poly.Name.ScrubFileName());
                Directory.CreateDirectory(_CurrDir);

                string CurrFileName = System.IO.Path.Combine(folder, poly.Name);

                List<TtPoint> points = DAL.GetPointsInPolygon(poly.CN).ToList();

                List<WayPoint> wayPoints = points.FilterOnly(OpType.WayPoint).Cast<WayPoint>().ToList();
                points = points.FilterOut(OpType.WayPoint).ToList();

                TtMetaData md;

                if (points.Count > 0 || wayPoints.Count > 0)
                {
                    if (points.Count > 0)
                        md = DAL.GetMetaDataByCN(points[0].MetaDefCN);
                    else
                        md = DAL.GetMetaDataByCN(wayPoints[0].MetaDefCN);
                    if (md == null)
                        continue;
                }
                else
                    continue;

                if (wayPoints.Count > 0)
                    WriteWayPoints(_File, wayPoints, md);

                if (points.Count < 1)
                    continue;

                CoordinateList BAdjCoords = new CoordinateList();
                CoordinateList BUnAdjCoords = new CoordinateList();

                CoordinateList NavAdjCoords = new CoordinateList();
                CoordinateList NavUnAdjCoords = new CoordinateList();

                bool hasWayPoints = false;

                TtPoint firstBndPoint = null, lastBntPoint = null;

                foreach (TtPoint point in points)
                {
                    if (point.IsNavPoint())
                    {
                        NavAdjCoords.Add(new Coordinate(point.AdjX, point.AdjY, point.AdjZ));
                        NavUnAdjCoords.Add(new Coordinate(point.UnAdjX, point.UnAdjY, point.UnAdjZ));
                    }

                    if (point.IsBndPoint())
                    {
                        BAdjCoords.Add(new Coordinate(point.AdjX, point.AdjY, point.AdjZ));
                        BUnAdjCoords.Add(new Coordinate(point.UnAdjX, point.UnAdjY, point.UnAdjZ));

                        if (firstBndPoint == null)
                            firstBndPoint = point;

                        lastBntPoint = point;
                    }

                    if (point.op == OpType.WayPoint)
                    {
                        hasWayPoints = true;
                    }
                }

                double polyLinePerim = -1;
                if (firstBndPoint != null)
                    polyLinePerim = poly.Perimeter - TtUtils.Distance(firstBndPoint, lastBntPoint, true);

                #region Navigation

                #region Adj
                string FileName = _File + "_NavAdj";
                GeometryFactory geoFac = new GeometryFactory();
                ShapefileDataWriter sdw;
                Polygonizer polyizer = new Polygonizer();

                ArrayList features = new ArrayList();
                AttributesTable attTable = new AttributesTable();

                attTable.AddAttribute("Poly_Name", poly.Name);
                attTable.AddAttribute("Desc", poly.Description);
                attTable.AddAttribute("Poly", "Navigation Adjusted");
                attTable.AddAttribute("CN", poly.CN);
                attTable.AddAttribute("Perim_M", poly.Perimeter);
                attTable.AddAttribute("PerimLine_M", polyLinePerim);

                Feature feat = new Feature();
                DbaseFileHeader dbh;

                if (NavAdjCoords.Count > 1)
                {
                    sdw = new ShapefileDataWriter(FileName, geoFac);

                    feat.Geometry = new NetTopologySuite.Geometries.LineString(NavAdjCoords.ToArray());

                    feat.Attributes = attTable;

                    features.Add(feat);

                    dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);

                    sdw.Header = dbh;
                    sdw.Write(features);
                    WriteProjection(FileName, md.Zone);

                    //points
                    FileName = _File + "_NavAdj_Points";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable["Poly"] = "Navigation Adjusted Points";

                    features = GetPointFeatures(points.Where(p => p.IsNavPoint()), true, DAL, metas);

                    if (features.Count > 0)
                    {
                        dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                        sdw.Header = dbh;
                        sdw.Write(features);
                        WriteProjection(FileName, md.Zone);
                    }
                }
                #endregion

                #region UnAdj
                if (NavUnAdjCoords.Count > 1)
                {
                    FileName = _File + "_NavUnAdj";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable["Poly"] = "Navigation UnAdjusted";
                    feat = new Feature();
                    feat.Geometry = new NetTopologySuite.Geometries.LineString(NavUnAdjCoords.ToArray());
                    //feat.Geometry = new NetTopologySuite.Geometries.LinearRing(NavUnAdjCoords.ToArray());
                    feat.Attributes = attTable;

                    features.Add(feat);

                    dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                    sdw.Header = dbh;
                    sdw.Write(features);
                    WriteProjection(FileName, md.Zone);

                    //points
                    FileName = _File + "_NavUnAdj_Points";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable["Poly"] = "Navigation UnAdjusted Points";

                    features = GetPointFeatures(points.Where(p => p.IsNavPoint()), false, DAL, metas);

                    if (features.Count > 0)
                    {
                        dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                        sdw.Header = dbh;
                        sdw.Write(features);
                        WriteProjection(FileName, md.Zone);
                    }
                }
                #endregion

                #endregion

                #region Boundary

                #region Adj Line
                if (BAdjCoords.Count > 1)
                {
                    FileName = _File + "_BndAdjLine";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable["Poly"] = "Boundary Adjusted Line";
                    feat = new Feature();
                    feat.Geometry = new NetTopologySuite.Geometries.LineString(BAdjCoords.ToArray());
                    feat.Attributes = attTable;

                    features.Add(feat);

                    dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                    sdw.Header = dbh;
                    sdw.Write(features);
                    WriteProjection(FileName, md.Zone);
                }
                #endregion

                #region UnAdj Line
                if (BUnAdjCoords.Count > 1)
                {
                    FileName = _File + "_BndUnAdjLine";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable["Poly"] = "Boundary UnAdjusted Line";
                    feat = new Feature();
                    feat.Geometry = new NetTopologySuite.Geometries.LineString(BUnAdjCoords.ToArray());
                    feat.Attributes = attTable;

                    features.Add(feat);

                    dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                    sdw.Header = dbh;
                    sdw.Write(features);
                    WriteProjection(FileName, md.Zone);
                }
                #endregion

                #region Adj
                if (BAdjCoords.Count > 3)
                {
                    FileName = _File + "_BndAdj";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable.AddAttribute("Area_MtSq", poly.Area);
                    attTable["Poly"] = "Boundary Adjusted";
                    feat = new Feature();

                    if (BAdjCoords[0] != BAdjCoords[BAdjCoords.Count - 1])
                        BAdjCoords.Add(BAdjCoords[0]);

                    feat.Geometry = new NetTopologySuite.Geometries.Polygon(new NetTopologySuite.Geometries.LinearRing(BAdjCoords.ToArray()));
                    feat.Attributes = attTable;

                    features.Add(feat);

                    dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                    sdw.Header = dbh;
                    sdw.Write(features);
                    WriteProjection(FileName, md.Zone);

                    //points
                    FileName = _File + "_BndAdj_Points";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable["Poly"] = "Boundary Adjusted Points";

                    features = GetPointFeatures(points.Where(p => p.IsBndPoint()), true, DAL, metas);

                    if (features.Count > 0)
                    {
                        dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                        sdw.Header = dbh;
                        sdw.Write(features);
                        WriteProjection(FileName, md.Zone);
                    }
                }
                #endregion

                #region UnAdj
                if (BUnAdjCoords.Count > 3)
                {
                    FileName = _File + "_BndUnAdj";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable["Poly"] = "Boundary UnAdjusted";
                    feat = new Feature();

                    if (BUnAdjCoords[0] != BUnAdjCoords[BUnAdjCoords.Count - 1])
                        BUnAdjCoords.Add(BUnAdjCoords[0]);

                    feat.Geometry = new NetTopologySuite.Geometries.Polygon(new LinearRing(BUnAdjCoords.ToArray()));
                    feat.Attributes = attTable;

                    features.Add(feat);

                    dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                    sdw.Header = dbh;
                    sdw.Write(features);
                    WriteProjection(FileName, md.Zone);

                    //points
                    FileName = _File + "_BndUnAdj_Points";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable["Poly"] = "Boundary UnAdjusted Points";

                    features = GetPointFeatures(points.Where(p => p.IsBndPoint()), false, DAL, metas);

                    if (features.Count > 0)
                    {
                        dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                        sdw.Header = dbh;
                        sdw.Write(features);
                        WriteProjection(FileName, md.Zone);
                    }
                }
                #endregion

                #region WayPoints
                if (hasWayPoints)
                {
                    //points
                    FileName = _File + "_WayPoints";
                    geoFac = new GeometryFactory();
                    sdw = new ShapefileDataWriter(FileName, geoFac);
                    features = new ArrayList();
                    attTable["Poly"] = "WayPoints";

                    features = GetPointFeatures(points.Where(p => p.op == OpType.WayPoint), false, DAL, metas);

                    if (features.Count > 0)
                    {
                        dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count);
                        sdw.Header = dbh;
                        sdw.Write(features);
                        WriteProjection(FileName, md.Zone);
                    }
                }
                #endregion
                #endregion
            }
            #endif
        }
Ejemplo n.º 5
0
        public void WritePolygons(DataAccessLayer DAL)
        {
            List<TtPolygon> polys = DAL.GetPolygons();

            if (polys != null && polys.Count > 0)
            {
                List<string> Columns = new List<string>();
                List<List<string>> data = new List<List<string>>();

                #region Columns
                Columns.Add("Name");
                Columns.Add("Accuracy");
                Columns.Add("Area_MtSq");
                Columns.Add("Perimeter_M");
                Columns.Add("Description");
                Columns.Add("CN");
                #endregion

                #region Add Data
                foreach (TtPolygon poly in polys)
                {
                    List<string> polyData = new List<string>();

                    polyData.Add(poly.Name.Scrub());
                    polyData.Add(poly.PolyAccu.ToString());
                    polyData.Add(poly.Area.ToString());
                    polyData.Add(poly.Perimeter.ToString());
                    polyData.Add(poly.Description.Scrub());
                    polyData.Add(poly.CN);

                    data.Add(polyData);
                }
                #endregion

                WriteCsvFile("Polygons", Columns, data);
            }
        }
Ejemplo n.º 6
0
        public GpxDocument CreateGpxDoc(DataAccessLayer DAL)
        {
            GpxDocument doc = new GpxDocument("USFS TwoTrails - http://www.fs.fed.us/fmsc/measure/geospatial/twotrails/");

            doc.MetaData = new GpxMetadata();
            doc.MetaData.Time = DateTime.Now;
            doc.MetaData.Name = Values.Settings.ProjectOptions.ProjectName;
            doc.MetaData.Link = "http://www.fs.fed.us/fmsc/measure/geospatial/twotrails/";

            #region Create Polygons

            List<TtPolygon> polys = DAL.GetPolygons();

            foreach (TtPolygon poly in polys)
            {
                GpxRoute AdjRoute = new GpxRoute(poly.Name + " - Adj Boundary", poly.Description);
                GpxTrack AdjTrack = new GpxTrack(poly.Name + " - Adj Navigation", poly.Description);

                GpxRoute UnAdjRoute = new GpxRoute(poly.Name + " - UnAdj Boundary", poly.Description);
                GpxTrack UnAdjTrack = new GpxTrack(poly.Name + " - UnAdj Navigation", poly.Description);

                AdjTrack.Segments.Add(new GpxTrackSeg());
                UnAdjTrack.Segments.Add(new GpxTrackSeg());

                List<TtPoint> points = DAL.GetPointsInPolygon(poly.CN);
                TtMetaData md = null;

                if (points.Count > 0)
                {
                    md = DAL.GetMetaDataByCN(points[0].MetaDefCN);

                    if (md == null)
                        throw new Exception("Meta Data is null.  Cant obtain UTM Zone");
                }

                if (points != null && points.Count > 0)
                {
                    foreach (TtPoint point in points)
                    {
                        double lat, lon;
                        TtUtils.UTMtoLatLon(point.AdjX, point.AdjY, md.Zone, out lat, out lon);
                        GpxPoint adjpoint = new GpxPoint(lat, lon, point.AdjZ);

                        TtUtils.UTMtoLatLon(point.UnAdjX, point.UnAdjY, md.Zone, out lat, out lon);
                        GpxPoint unAdjpoint = new GpxPoint(lat, lon, point.UnAdjZ);

                        adjpoint.Name = point.PID.ToString();
                        adjpoint.Time = point.Time;
                        adjpoint.Comment = point.Comment;
                        adjpoint.Description = "Point Operation: " + point.op.ToString() + "<br>UtmX:" + point.AdjX +
                            "<br>UtmY: " + point.AdjY;

                        unAdjpoint.Name = point.PID.ToString();
                        unAdjpoint.Time = point.Time;
                        unAdjpoint.Comment = point.Comment;
                        unAdjpoint.Description = "Point Operation: " + point.op.ToString() + "<br>UtmX:" + point.UnAdjX +
                            "<br>UtmY: " + point.UnAdjY;

                        #region Add points to lists
                        if (point.IsBndPoint())
                        {
                            AdjRoute.Points.Add(adjpoint);
                            UnAdjRoute.Points.Add(unAdjpoint);
                        }

                        if (point.IsNavPoint())
                        {
                            AdjTrack.Segments[0].Points.Add(adjpoint);
                            UnAdjTrack.Segments[0].Points.Add(unAdjpoint);
                        }
                        else if (point.op == OpType.Quondam)
                        {
                            QuondamPoint p = (QuondamPoint)point;

                            if (p.IsNavPoint())
                            {
                                AdjTrack.Segments[0].Points.Add(adjpoint);
                                UnAdjTrack.Segments[0].Points.Add(unAdjpoint);
                            }
                        }

                        if (point.op == OpType.WayPoint)
                        {
                            doc.AddPoint(unAdjpoint);
                        }
                        #endregion
                    }
                }

                doc.AddRoute(AdjRoute);
                doc.AddRoute(UnAdjRoute);
                doc.AddTrack(AdjTrack);
                doc.AddTrack(UnAdjTrack);
            }

            #endregion

            return doc;
        }
        public void Init(DataAccessLayer dal)
        {
            this.DialogResult = DialogResult.Abort;

            DAL = dal;
            _recalc = false;

            List<TtPolygon> polys = DAL.GetPolygons();

            if (polys.Count < 1)
            {
                MessageBox.Show("There are no Polygons to edit from.");
                return;
            }

            Polygons = new Dictionary<string, TtPolygon>();
            PolyNames = new Dictionary<string, string>();
            Points = new Dictionary<string, Dictionary<string, TtPoint>>();
            OldPoints = new Dictionary<string, Dictionary<string, TtPoint>>();

            _DeleteNmea = new List<string>();

            try
            {
                foreach (TtPolygon poly in polys)
                {
                    Polygons.Add(poly.CN, poly);
                    PolyNames.Add(poly.Name, poly.CN);
                    Points.Add(poly.CN, new Dictionary<string, TtPoint>());
                    OldPoints.Add(poly.CN, new Dictionary<string, TtPoint>());
                    foreach (TtPoint point in DAL.GetPointsInPolygon(poly.CN))
                    {
                        Points[poly.CN].Add(point.CN, point);
                        OldPoints[poly.CN].Add(point.CN, point);
                    }

                    cboPoly.Items.Add(poly.Name);
                }
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "MassEditFormLogic:Init");
                return;
            }

            if (Values.Settings.DeviceOptions.UseSelection)
            {
                cboPoly.Visible = false;

                btnPolygon.Visible = true;
            }
            else
            {
                cboPoly.Visible = true;

                btnPolygon.Visible = false;
            }

            CurrPoly = Polygons.First().Value;
            btnPolygon.Text = CurrPoly.Name;

            lstPoints.Columns.Add("Point", 70, HorizontalAlignment.Left);
            lstPoints.Columns.Add("Polygon", 70, HorizontalAlignment.Left);
            lstPoints.Columns.Add("Type", 70, HorizontalAlignment.Left);
            lstPoints.Columns.Add("OnBound", 50, HorizontalAlignment.Left);
            lstPoints.Columns.Add("CN", 180, HorizontalAlignment.Left);

            LoadPolygon();

            btnBnd.Text = "On";
            onBnd = true;

            this.DialogResult = DialogResult.Cancel;
        }
        public static void Adjust(DataAccessLayer dal, bool updateIndexes, System.Windows.Forms.Form form)
        {
            if (form != null && !Values.AdjustingPolygons)
            {
                new Thread(() =>
                {
                    Values.GlobalCancelToken = false;
                    Values.AdjustingPolygons = true;

            #if !(PocketPC || WindowsCE || Mobile)
                    Values.UpdateStatusText("Adjusting Polygons (Do NOT close Program)");
            #endif
                    if (updateIndexes && Values.Settings.DeviceOptions.AutoUpdateIndex)
                    {
                        List<TtPoint> iPoints = new List<TtPoint>();

                        foreach (TtPolygon poly in dal.GetPolygons())
                        {
                            int index = 0;
                            foreach (TtPoint p in dal.GetPointsInPolygon(poly.CN))
                            {
                                if (p.Index != index)
                                {
                                    p.Index = index;
                                    iPoints.Add(p);
                                }

                                index++;
                            }
                        }

                        dal.SavePoints(iPoints, ref Values.GlobalCancelToken);
                    }

                    bool result = CalculateSegmentsInOrderByWeight(dal);

                    if (Values.GlobalCancelToken)
                    {
            #if !(PocketPC || WindowsCE || Mobile)
                        Values.UpdateStatusText("Polygons Adjustment Canceled");
                    }
                    else
                    {
                        if (result)
                            Values.UpdateStatusText("Polygons Adjusted");
            #endif
                    }

                    Values.AdjustingPolygons = false;
                    Values.GlobalCancelToken = false;

                    form.GuiInvoke(() =>
                    {
                        TtUtils.HideWaitCursor();
                        form.Close();
                    });

                    GC.Collect();

                }).Start();
            }
            else
            {
                Values.AdjustingPolygons = true;

            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusText("Adjusting Polygons (Do NOT close Program)");
            #endif
                bool result = CalculateSegmentsInOrderByWeight(dal);

            #if !(PocketPC || WindowsCE || Mobile)
                if (Values.GlobalCancelToken)
                {
                    Values.UpdateStatusText("Polygons Adjustment Canceled");
                }
                else
                {
                    if (result)
                        Values.UpdateStatusText("Polygons Adjusted");
                }
            #endif

                Values.AdjustingPolygons = false;
                GC.Collect();
            }
        }
        private static void CalculateAreaAndPerimeter(DataAccessLayer DAL)
        {
            List<TtPolygon> polys = DAL.GetPolygons();

            if (polys != null && polys.Count > 0)
            {
                foreach (TtPolygon poly in polys)
                {
                    try
                    {
                        TtPolygon newPoly = new TtPolygon(poly);
                        List<TtPoint> points = DAL.GetBoundaryPoints(poly.CN).FilterOut(OpType.WayPoint).ToList();

                        if (points.Count > 2)
                        {
                            double perim = 0, area = 0;

                            points.Add(points[0]);
                            TtPoint p1, p2;
                            for (int i = 0; i < points.Count - 1; i++)
                            {
                                p1 = points[i];
                                p2 = points[i + 1];

                                perim += TtUtils.Distance(p1, p2);
                                area += ((p2.AdjX - p1.AdjX) * (p2.AdjY + p1.AdjY) / 2);
                            }

                            newPoly.Perimeter = perim;
                            newPoly.Area = Math.Abs(area);
                        }
                        else
                        {
                            newPoly.Perimeter = 0;
                            newPoly.Area = 0;
                        }

                        DAL.SavePolygon(poly, newPoly);
                    }
                    catch (Exception ex)
                    {
                        TtUtils.WriteError(ex.Message, "SegmentFactory:CalculateAreaAndPerimeter", ex.StackTrace);
                    }
                }
            }
        }
        public static bool CanAdjust(DataAccessLayer dal)
        {
            foreach (TtPolygon poly in dal.GetPolygons())
            {
                if (dal.GetPointCount(poly.CN) > 0)
                {
                    TtPoint p = dal.GetFirstPointInPolygon(poly.CN);
                    if (p != null)
                    {
                        if (p.IsTravType())
                        {
                            System.Windows.Forms.MessageBox.Show(String.Format("Polygon {0} can not start with a {1}. Point {2} must derive from a GPS type or Quondam.",
                                poly.Name, p.op.ToString(), p.PID), "Bad Polygon Start");
                            return false;
                        }
                        /*
                        else if (p.op == OpType.Quondam)
                        {
                            if (((QuondamPoint)p).ParentOp == OpType.Traverse)
                            {
                                System.Windows.Forms.MessageBox.Show(String.Format("Polygon {0} can not start with a Quondam to a Traverse. Point {2} must derive from a GPS type.",
                                    poly.Name, p.op.ToString(), p.PID), "Bad Polygon Start");
                                return false;
                            }
                        }
                        */
                    }
                    else
                    {
                        //no point
                        return false;
                    }
                }
            }

            return true;
        }
        public static string GenerateHtml(DataAccessLayer DAL)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<html><head>");
            sb.AppendLine(String.Format("<title>TwoTrails Draw For Web Browsers (Project: {0})</title>",DAL.GetProjectID()));
            sb.AppendLine(@"<style type=""text/css"">");
            sb.AppendLine(CSS);
            sb.AppendLine(CSSTREE);
            sb.AppendLine("</style>");
            sb.AppendLine(@"<script src=""https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false""></script>");
            sb.AppendLine("<script>");
            sb.AppendLine(JQUERY);
            sb.AppendLine(JSTREE);
            sb.AppendLine();
            sb.AppendLine(JSGEOM);
            sb.AppendLine();
            sb.AppendLine(JSGEO);
            sb.AppendLine();
            sb.AppendLine(JSINIT);
            sb.AppendLine();

            sb.AppendLine("function create(){");

            sb.AppendLine("function makeMapListener(window, map, markers) {");
            sb.AppendLine("\treturn function() { window.open(map, markers); };");
            sb.AppendLine("}");
            sb.AppendLine();

            sb.AppendLine("var bounds = new google.maps.LatLngBounds();");
            sb.AppendLine("function AutoCenter(coordList) {");
            sb.AppendLine("for(var i=0; i < coordList.length; i++){");
            sb.AppendLine("\tif(coordList[i].lat() != 0 && coordList[i].lng() != 0)");
            sb.AppendLine("\t{");
            sb.AppendLine("\t\tbounds.extend(coordList[i]);");
            sb.AppendLine("}}}");
            sb.AppendLine();

            sb.AppendLine("function FitMap(boundary) {");
            sb.AppendLine("map.fitBounds(boundary);");
            sb.AppendLine("}");
            sb.AppendLine();

            //html for tree
            StringBuilder jst = new StringBuilder();

            string id = String.Empty;
            int _id = 1;

            if (DAL.GetPolyCount() > 0)
            {
                jst.AppendLine("<ul>");

                List<TtPoint> points, tmpPoints;
                List<string> checkedPolys = new List<string>();
                bool hasWaypoints = false, hasMiscPoints;

                string idAdjBnd, idUnadjBnd, idAdjNav, idUnadjNav, idAdjBndPt, idUnadjBndPt,
                    idAdjNavPt, idUnadjNavPt, idWayPt, idMiscAdjPt, idMiscUnadjPt, idAllPt;

                foreach (TtPolygon poly in DAL.GetPolygons())
                {
                    jst.AppendLine(String.Format("<li class=\"jstree-open\">{0}<ul>", poly.Name));

                    points = DAL.GetPointsInPolygon(poly.CN);

                    if (points.Count > 0)
                    {
                        hasWaypoints = (points.Where(p => p.op == TwoTrails.Engine.OpType.WayPoint).Any());
                        hasMiscPoints = (points.Where(p => p.op == TwoTrails.Engine.OpType.SideShot && !p.OnBnd).Any());

                        StringBuilder coordArray = new StringBuilder();
                        StringBuilder pmArray = new StringBuilder();
                        StringBuilder infoArray = new StringBuilder();

                        TtPoint tmpPoint;
                        double lat, lon;

                        TtMetaData meta = DAL.GetMetaDataByCN(Engine.Values.EmptyGuid);
                        if (meta == null)
                            meta = DAL.GetMetaData()[0];

                        int zone = meta.Zone;

                        #region Adjusted Boundary

                        tmpPoints = points.Where(p => p.IsBndPoint()).ToList();

                        if (tmpPoints.Count > 0)
                        {
                            idAdjBnd = GetId(ref _id);
                            checkedPolys.Add(idAdjBnd);
                            idAdjBndPt = GetId(ref _id);
                            //checkedPolys.Add(idAdjBndPt);
                            jst.AppendLine(String.Format("<li>Adj Boundary<ul><li id =\"{0}\">Polygon</li><li id=\"{1}\">Points</li></ul></li>", idAdjBnd, idAdjBndPt));

                            coordArray.AppendFormat("var {0} = [", GetCoordId(idAdjBnd));
                            pmArray.AppendFormat("var {0} = [", GetPlacemarkId(idAdjBnd));
                            infoArray.AppendFormat("var {0} = [", GetInfoId(idAdjBnd));

                            for (int i = 0; i < tmpPoints.Count - 1; i++)
                            {
                                tmpPoint = tmpPoints[i];

                                TtUtils.UTMtoLatLon(tmpPoint.AdjX, tmpPoint.AdjY, zone, out lat, out lon);

                                coordArray.AppendFormat("new google.maps.LatLng({0}, {1}),", lat, lon);
                                pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }}),",
                                    lat, lon, tmpPoint.PID);
                                infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }}),", GetPointInfo(tmpPoint, true));
                            }

                            TtUtils.UTMtoLatLon(tmpPoints[tmpPoints.Count - 1].AdjX, tmpPoints[tmpPoints.Count - 1].AdjY, zone, out lat, out lon);
                            coordArray.AppendFormat("new google.maps.LatLng({0}, {1})", lat, lon);
                            pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }})", lat, lon, tmpPoints[tmpPoints.Count - 1].PID);
                            infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }})", GetPointInfo(tmpPoints[tmpPoints.Count - 1], true));

                            coordArray.AppendLine("];");
                            pmArray.AppendLine("];");
                            infoArray.AppendLine("];");

                            sb.AppendLine(coordArray.ToString());
                            sb.AppendLine(pmArray.ToString());
                            sb.AppendLine(infoArray.ToString());

                            sb.AppendLine(String.Format("for(var i=0; i < {0}.length; i++){{", GetCoordId(idAdjBnd)));
                            sb.AppendLine(String.Format("\tgoogle.maps.event.addListener(pm[i], 'click', makeMapListener(info[i], map, pm[i]));"));
                            sb.AppendLine("}");
                            sb.AppendLine();

                            sb.AppendLine(String.Format("objlist.push(new GPoly(\"{0}\", map, true, {1}, '#{2}', {3}, 3, '#{2}', {4}));",
                                idAdjBnd, GetCoordId(idAdjBnd), AdjBoundaryColor, BoundaryOpacity, PolygonOpacity));
                            sb.AppendLine(String.Format("objlist.push(new GMarkers(\"{0}\", map, false, {1}));", idAdjBndPt, GetPlacemarkId(idAdjBnd)));
                            sb.AppendLine();

                            sb.AppendLine("AutoCenter(coord);");
                            sb.AppendLine();
                        }
                        #endregion

                        #region Adjusted Navigation
                        tmpPoints = points.Where(p => p.IsNavPoint()).ToList();

                        if (tmpPoints.Count > 0)
                        {
                            coordArray = new StringBuilder();
                            pmArray = new StringBuilder();
                            infoArray = new StringBuilder();

                            idAdjNav = GetId(ref _id);
                            idAdjNavPt = GetId(ref _id);
                            jst.AppendLine(String.Format("<li>Adj Navigation<ul><li id =\"{0}\">Path</li><li id=\"{1}\">Points</li></ul></li>", idAdjNav, idAdjNavPt));

                            coordArray.AppendFormat("{0} = [", GetCoordId(idAdjNav));
                            pmArray.AppendFormat("{0} = [", GetPlacemarkId(idAdjNav));
                            infoArray.AppendFormat("{0} = [", GetInfoId(idAdjNav));

                            for (int i = 0; i < tmpPoints.Count - 1; i++)
                            {
                                tmpPoint = tmpPoints[i];

                                TtUtils.UTMtoLatLon(tmpPoint.AdjX, tmpPoint.AdjY, zone, out lat, out lon);

                                coordArray.AppendFormat("new google.maps.LatLng({0}, {1}),", lat, lon);
                                pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }}),",
                                    lat, lon, tmpPoint.PID);
                                infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }}),", GetPointInfo(tmpPoint, true));
                            }

                            TtUtils.UTMtoLatLon(tmpPoints[tmpPoints.Count - 1].AdjX, tmpPoints[tmpPoints.Count - 1].AdjY, zone, out lat, out lon);
                            coordArray.AppendFormat("new google.maps.LatLng({0}, {1})", lat, lon);
                            pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }})", lat, lon, tmpPoints[tmpPoints.Count - 1].PID);
                            infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }})", GetPointInfo(tmpPoints[tmpPoints.Count - 1], true));

                            coordArray.AppendLine("];");
                            pmArray.AppendLine("];");
                            infoArray.AppendLine("];");

                            sb.AppendLine(coordArray.ToString());
                            sb.AppendLine(pmArray.ToString());
                            sb.AppendLine(infoArray.ToString());

                            sb.AppendLine(String.Format("for(var i=0; i < {0}.length; i++){{", GetCoordId(idAdjNav)));
                            sb.AppendLine(String.Format("\tgoogle.maps.event.addListener(pm[i], 'click', makeMapListener(info[i], map, pm[i]));"));
                            sb.AppendLine("}");
                            sb.AppendLine();

                            sb.AppendLine(String.Format("objlist.push(new GPath(\"{0}\", map, false, {1}, '#{2}', {3}));",
                                idAdjNav, GetCoordId(idAdjNav), AdjNavigationColor, NavigationOpacity));
                            sb.AppendLine(String.Format("objlist.push(new GMarkers(\"{0}\", map, false, {1}));", idAdjNavPt, GetPlacemarkId(idAdjNav)));
                            sb.AppendLine();
                        }
                        #endregion

                        #region Unadjusted Boundary
                        tmpPoints = points.Where(p => p.IsBndPoint()).ToList();
                        if (tmpPoints.Count > 0)
                        {
                            coordArray = new StringBuilder();
                            pmArray = new StringBuilder();
                            infoArray = new StringBuilder();

                            idUnadjBnd = GetId(ref _id);
                            idUnadjBndPt = GetId(ref _id);
                            jst.AppendLine(String.Format("<li>UnAdj Boundary<ul><li id =\"{0}\">Polygon</li><li id=\"{1}\">Points</li></ul></li>", idUnadjBnd, idUnadjBndPt));

                            coordArray.AppendFormat("{0} = [", GetCoordId(idUnadjBnd));
                            pmArray.AppendFormat("{0} = [", GetPlacemarkId(idUnadjBnd));
                            infoArray.AppendFormat("{0} = [", GetInfoId(idUnadjBnd));

                            for (int i = 0; i < tmpPoints.Count - 1; i++)
                            {
                                tmpPoint = tmpPoints[i];

                                TtUtils.UTMtoLatLon(tmpPoint.UnAdjX, tmpPoint.UnAdjY, zone, out lat, out lon);

                                coordArray.AppendFormat("new google.maps.LatLng({0}, {1}),", lat, lon);
                                pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }}),",
                                    lat, lon, tmpPoint.PID);
                                infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }}),", GetPointInfo(tmpPoint, false));
                            }

                            TtUtils.UTMtoLatLon(tmpPoints[tmpPoints.Count - 1].UnAdjX, tmpPoints[tmpPoints.Count - 1].UnAdjY, zone, out lat, out lon);
                            coordArray.AppendFormat("new google.maps.LatLng({0}, {1})", lat, lon);
                            pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }})", lat, lon, tmpPoints[tmpPoints.Count - 1].PID);
                            infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }})", GetPointInfo(tmpPoints[tmpPoints.Count - 1], false));

                            coordArray.AppendLine("];");
                            pmArray.AppendLine("];");
                            infoArray.AppendLine("];");

                            sb.AppendLine(coordArray.ToString());
                            sb.AppendLine(pmArray.ToString());
                            sb.AppendLine(infoArray.ToString());

                            sb.AppendLine(String.Format("for(var i=0; i < {0}.length; i++){{", GetCoordId(idUnadjBnd)));
                            sb.AppendLine(String.Format("\tgoogle.maps.event.addListener(pm[i], 'click', makeMapListener(info[i], map, pm[i]));"));
                            sb.AppendLine("}");
                            sb.AppendLine();

                            sb.AppendLine(String.Format("objlist.push(new GPoly(\"{0}\", map, false, {1}, '#{2}', {3}, 3, '#{2}', {4}));",
                                idUnadjBnd, GetCoordId(idUnadjBnd), UnAdjBoundaryColor, BoundaryOpacity, PolygonOpacity));
                            sb.AppendLine(String.Format("objlist.push(new GMarkers(\"{0}\", map, false, {1}));", idUnadjBndPt, GetPlacemarkId(idUnadjBnd)));
                            sb.AppendLine();
                        }
                        #endregion

                        #region Unadjusted Navigation
                        tmpPoints = points.Where(p => p.IsNavPoint()).ToList();

                        if (tmpPoints.Count > 0)
                        {
                            coordArray = new StringBuilder();
                            pmArray = new StringBuilder();
                            infoArray = new StringBuilder();

                            idUnadjNav = GetId(ref _id);
                            idUnadjNavPt = GetId(ref _id);
                            jst.AppendLine(String.Format("<li>UnAdj Navigation<ul><li id =\"{0}\">Path</li><li id=\"{1}\">Points</li></ul></li>", idUnadjNav, idUnadjNavPt));

                            coordArray.AppendFormat("{0} = [", GetCoordId(idUnadjNav));
                            pmArray.AppendFormat("{0} = [", GetPlacemarkId(idUnadjNav));
                            infoArray.AppendFormat("{0} = [", GetInfoId(idUnadjNav));

                            for (int i = 0; i < tmpPoints.Count - 1; i++)
                            {
                                tmpPoint = tmpPoints[i];

                                TtUtils.UTMtoLatLon(tmpPoint.UnAdjX, tmpPoint.UnAdjY, zone, out lat, out lon);

                                coordArray.AppendFormat("new google.maps.LatLng({0}, {1}),", lat, lon);
                                pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }}),",
                                    lat, lon, tmpPoint.PID);
                                infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }}),", GetPointInfo(tmpPoint, false));
                            }

                            TtUtils.UTMtoLatLon(tmpPoints[tmpPoints.Count - 1].UnAdjX, tmpPoints[tmpPoints.Count - 1].UnAdjY, zone, out lat, out lon);
                            coordArray.AppendFormat("new google.maps.LatLng({0}, {1})", lat, lon);
                            pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }})", lat, lon, tmpPoints[tmpPoints.Count - 1].PID);
                            infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }})", GetPointInfo(tmpPoints[tmpPoints.Count - 1], false));

                            coordArray.AppendLine("];");
                            pmArray.AppendLine("];");
                            infoArray.AppendLine("];");

                            sb.AppendLine(coordArray.ToString());
                            sb.AppendLine(pmArray.ToString());
                            sb.AppendLine(infoArray.ToString());

                            sb.AppendLine(String.Format("for(var i=0; i < {0}.length; i++){{", GetCoordId(idUnadjNav)));
                            sb.AppendLine(String.Format("\tgoogle.maps.event.addListener(pm[i], 'click', makeMapListener(info[i], map, pm[i]));"));
                            sb.AppendLine("}");
                            sb.AppendLine();

                            sb.AppendLine(String.Format("objlist.push(new GPath(\"{0}\", map, false, {1}, '#{2}', {3}));",
                                idUnadjNav, GetCoordId(idUnadjNav), UnAdjNavigationColor, NavigationOpacity));
                            sb.AppendLine(String.Format("objlist.push(new GMarkers(\"{0}\", map, false, {1}));", idUnadjNavPt, GetPlacemarkId(idUnadjNav)));
                            sb.AppendLine();
                        }
                        #endregion

                        #region MiscPoints
                        if (hasMiscPoints)
                        {
                            tmpPoints = (points.Where(p => p.op == TwoTrails.Engine.OpType.SideShot && !p.OnBnd)).ToList();

                            if (tmpPoints.Count > 0)
                            {
                                coordArray = new StringBuilder();
                                pmArray = new StringBuilder();
                                infoArray = new StringBuilder();

                                #region Adjusted
                                idMiscAdjPt = GetId(ref _id);
                                idMiscUnadjPt = GetId(ref _id);
                                jst.AppendLine(String.Format("<li>Misc Points<ul><li id =\"{0}\">Adjusted</li><li id=\"{1}\">Unadjusted</li></ul></li>", idMiscAdjPt, idMiscUnadjPt));

                                coordArray.AppendFormat("{0} = [", GetCoordId(idMiscAdjPt));
                                pmArray.AppendFormat("{0} = [", GetPlacemarkId(idMiscAdjPt));
                                infoArray.AppendFormat("{0} = [", GetInfoId(idMiscAdjPt));

                                for (int i = 0; i < tmpPoints.Count - 1; i++)
                                {
                                    tmpPoint = tmpPoints[i];

                                    TtUtils.UTMtoLatLon(tmpPoint.AdjX, tmpPoint.AdjY, zone, out lat, out lon);

                                    coordArray.AppendFormat("new google.maps.LatLng({0}, {1}),", lat, lon);
                                    pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }}),",
                                        lat, lon, tmpPoint.PID);
                                    infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }}),", GetPointInfo(tmpPoint, true));
                                }

                                TtUtils.UTMtoLatLon(tmpPoints[tmpPoints.Count - 1].AdjX, tmpPoints[tmpPoints.Count - 1].AdjY, zone, out lat, out lon);
                                coordArray.AppendFormat("new google.maps.LatLng({0}, {1})", lat, lon);
                                pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }})", lat, lon, tmpPoints[tmpPoints.Count - 1].PID);
                                infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }})", GetPointInfo(tmpPoints[tmpPoints.Count - 1], true));

                                coordArray.AppendLine("];");
                                pmArray.AppendLine("];");
                                infoArray.AppendLine("];");

                                sb.AppendLine(coordArray.ToString());
                                sb.AppendLine(pmArray.ToString());
                                sb.AppendLine(infoArray.ToString());

                                sb.AppendLine(String.Format("for(var i=0; i < {0}.length; i++){{", GetCoordId(idMiscAdjPt)));
                                sb.AppendLine(String.Format("\tgoogle.maps.event.addListener(pm[i], 'click', makeMapListener(info[i], map, pm[i]));"));
                                sb.AppendLine("}");
                                sb.AppendLine();

                                sb.AppendLine(String.Format("objlist.push(new GMarkers(\"{0}\", map, false, {1}));", idMiscAdjPt, GetPlacemarkId(idMiscAdjPt)));
                                sb.AppendLine();
                                #endregion

                                #region Unadjsuted

                                coordArray.AppendFormat("{0} = [", GetCoordId(idMiscUnadjPt));
                                pmArray.AppendFormat("{0} = [", GetPlacemarkId(idMiscUnadjPt));
                                infoArray.AppendFormat("{0} = [", GetInfoId(idMiscUnadjPt));

                                for (int i = 0; i < tmpPoints.Count - 1; i++)
                                {
                                    tmpPoint = tmpPoints[i];

                                    TtUtils.UTMtoLatLon(tmpPoint.UnAdjX, tmpPoint.UnAdjY, zone, out lat, out lon);

                                    coordArray.AppendFormat("new google.maps.LatLng({0}, {1}),", lat, lon);
                                    pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }}),",
                                        lat, lon, tmpPoint.PID);
                                    infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }}),", GetPointInfo(tmpPoint, false));
                                }

                                TtUtils.UTMtoLatLon(tmpPoints[tmpPoints.Count - 1].UnAdjX, tmpPoints[tmpPoints.Count - 1].UnAdjY, zone, out lat, out lon);
                                coordArray.AppendFormat("new google.maps.LatLng({0}, {1})", lat, lon);
                                pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }})", lat, lon, tmpPoints[tmpPoints.Count - 1].PID);
                                infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }})", GetPointInfo(tmpPoints[tmpPoints.Count - 1], false));

                                coordArray.AppendLine("];");
                                pmArray.AppendLine("];");
                                infoArray.AppendLine("];");

                                sb.AppendLine(coordArray.ToString());
                                sb.AppendLine(pmArray.ToString());
                                sb.AppendLine(infoArray.ToString());

                                sb.AppendLine(String.Format("for(var i=0; i < {0}.length; i++){{", GetCoordId(idMiscUnadjPt)));
                                sb.AppendLine(String.Format("\tgoogle.maps.event.addListener(pm[i], 'click', makeMapListener(info[i], map, pm[i]));"));
                                sb.AppendLine("}");
                                sb.AppendLine();

                                sb.AppendLine(String.Format("objlist.push(new GMarkers(\"{0}\", map, false, {1}));", idMiscUnadjPt, GetPlacemarkId(idMiscUnadjPt)));
                                sb.AppendLine();
                            }
                            #endregion
                        }
                        #endregion

                        #region Waypoints
                        if (hasWaypoints)
                        {
                            tmpPoints = points.Where(p => p.op == TwoTrails.Engine.OpType.WayPoint).ToList();

                            if (tmpPoints.Count > 0)
                            {
                                coordArray = new StringBuilder();
                                pmArray = new StringBuilder();
                                infoArray = new StringBuilder();

                                idWayPt = GetId(ref _id);
                                jst.AppendLine(String.Format("<li id=\"{0}\">Waypoints</li>", idWayPt));

                                coordArray.AppendFormat("{0} = [", GetCoordId(idWayPt));
                                pmArray.AppendFormat("{0} = [", GetPlacemarkId(idWayPt));
                                infoArray.AppendFormat("{0} = [", GetInfoId(idWayPt));

                                for (int i = 0; i < tmpPoints.Count - 1; i++)
                                {
                                    tmpPoint = tmpPoints[i];

                                    TtUtils.UTMtoLatLon(tmpPoint.AdjX, tmpPoint.AdjY, zone, out lat, out lon);

                                    coordArray.AppendFormat("new google.maps.LatLng({0}, {1}),", lat, lon);
                                    pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }}),",
                                        lat, lon, tmpPoint.PID);
                                    infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }}),", GetPointInfo(tmpPoint, true));
                                }

                                TtUtils.UTMtoLatLon(tmpPoints[tmpPoints.Count - 1].AdjX, tmpPoints[tmpPoints.Count - 1].AdjY, zone, out lat, out lon);
                                coordArray.AppendFormat("new google.maps.LatLng({0}, {1})", lat, lon);
                                pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }})", lat, lon, tmpPoints[tmpPoints.Count - 1].PID);
                                infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }})", GetPointInfo(tmpPoints[tmpPoints.Count - 1], true));

                                coordArray.AppendLine("];");
                                pmArray.AppendLine("];");
                                infoArray.AppendLine("];");

                                sb.AppendLine(coordArray.ToString());
                                sb.AppendLine(pmArray.ToString());
                                sb.AppendLine(infoArray.ToString());

                                sb.AppendLine(String.Format("for(var i=0; i < {0}.length; i++){{", GetCoordId(idWayPt)));
                                sb.AppendLine(String.Format("\tgoogle.maps.event.addListener(pm[i], 'click', makeMapListener(info[i], map, pm[i]));"));
                                sb.AppendLine("}");
                                sb.AppendLine();

                                sb.AppendLine(String.Format("objlist.push(new GMarkers(\"{0}\", map, false, {1}));", idWayPt, GetPlacemarkId(idWayPt)));
                                sb.AppendLine();
                            }
                        }
                        #endregion

                        #region All Points
                        coordArray = new StringBuilder();
                        pmArray = new StringBuilder();
                        infoArray = new StringBuilder();

                        idAllPt = GetId(ref _id);
                        jst.AppendLine(String.Format("<li id=\"{0}\">All Points</li>", idAllPt));

                        coordArray.AppendFormat("{0} = [", GetCoordId(idAllPt));
                        pmArray.AppendFormat("{0} = [", GetPlacemarkId(idAllPt));
                        infoArray.AppendFormat("{0} = [", GetInfoId(idAllPt));

                        tmpPoints = points;

                        for (int i = 0; i < tmpPoints.Count - 1; i++)
                        {
                            tmpPoint = tmpPoints[i];

                            TtUtils.UTMtoLatLon(tmpPoint.AdjX, tmpPoint.AdjY, zone, out lat, out lon);

                            coordArray.AppendFormat("new google.maps.LatLng({0}, {1}),", lat, lon);
                            pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }}),",
                                lat, lon, tmpPoint.PID);
                            infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }}),", GetPointInfo(tmpPoint, true));
                        }

                        TtUtils.UTMtoLatLon(tmpPoints[tmpPoints.Count - 1].AdjX, tmpPoints[tmpPoints.Count - 1].AdjY, zone, out lat, out lon);
                        coordArray.AppendFormat("new google.maps.LatLng({0}, {1})", lat, lon);
                        pmArray.AppendFormat("new google.maps.Marker({{position : new google.maps.LatLng({0}, {1}), map : null, title : 'Point {2}' }})", lat, lon, tmpPoints[tmpPoints.Count - 1].PID);
                        infoArray.AppendFormat("new google.maps.InfoWindow({{ content : '{0}' }})", GetPointInfo(tmpPoints[tmpPoints.Count - 1], true));

                        coordArray.AppendLine("];");
                        pmArray.AppendLine("];");
                        infoArray.AppendLine("];");

                        sb.AppendLine(coordArray.ToString());
                        sb.AppendLine(pmArray.ToString());
                        sb.AppendLine(infoArray.ToString());

                        sb.AppendLine(String.Format("for(var i=0; i < {0}.length; i++){{", GetCoordId(idAllPt)));
                        sb.AppendLine(String.Format("\tgoogle.maps.event.addListener(pm[i], 'click', makeMapListener(info[i], map, pm[i]));"));
                        sb.AppendLine("}");
                        sb.AppendLine();

                        sb.AppendLine(String.Format("objlist.push(new GMarkers(\"{0}\", map, false, {1}));", idAllPt, GetPlacemarkId(idAllPt)));
                        sb.AppendLine();
                        #endregion

                        //map move listener for utmXYZ
                        sb.AppendLine(@"google.maps.event.addListener(map, 'mousemove', function(event){var ll=new LatLng(event.latLng.lat(), event.latLng.lng());var utm=ll.toUTMRef();document.getElementById('utmX').innerHTML=""UTM X: ""+utm.easting.toFixed(2);document.getElementById('utmY').innerHTML=""UTM Y: ""+utm.northing.toFixed(2);document.getElementById('zone').innerHTML=""Zone: ""+utm.lngZone;});");
                        //poly move listener for utmXYZ -poly overrides map so it needs a listener
                        sb.AppendLine(@"for(var i=0;i<objlist.length;i++){if(objlist[i].type == 'gpoly'){google.maps.event.addListener(objlist[i].poly, 'mousemove', function(event){var ll=new LatLng(event.latLng.lat(), event.latLng.lng());var utm=ll.toUTMRef();document.getElementById('utmX').innerHTML=""UTM X: ""+utm.easting.toFixed(2);document.getElementById('utmY').innerHTML=""UTM Y: ""+utm.northing.toFixed(2);document.getElementById('zone').innerHTML=""Zone: ""+utm.lngZone;});}}");

                        sb.AppendLine();
                        sb.AppendLine("FitMap(bounds);");
                    }
                    else
                    {
                        jst.AppendLine("<li>No Points</li>");
                    }

                    jst.AppendLine("</ul></li>");
                }
                jst.AppendLine("</ul>");

                sb.AppendLine("}");

                sb.AppendLine("function treeLoaded(event, data) {");
                sb.Append("\tdata.instance.select_node([");

                if (checkedPolys.Count > 0)
                {
                    for (int i = 0; i < checkedPolys.Count - 1; i++)
                    {
                        sb.AppendFormat("'{0}',", checkedPolys[i]);
                    }

                    sb.AppendFormat("'{0}'", checkedPolys[checkedPolys.Count - 1]);
                }

                sb.AppendLine("]);");
                sb.AppendLine("}");
            }
            else
            {
                jst = null;
                sb.AppendLine("}");
            }

            sb.AppendLine("</script>");
            sb.AppendLine("</head>");
            sb.AppendLine("<body>");
            sb.AppendLine(@"<div id=""map-canvas""></div>");
            sb.AppendLine(@"<div id=""loc"">");
            sb.AppendLine(@"<div id=""utmX"" class=""utm""></div>");
            sb.AppendLine(@"<div id=""utmY"" class=""utm""></div>");
            sb.AppendLine(@"<div id=""zone""></div>");
            sb.AppendLine(@"</div>");
            sb.AppendLine(@"<div id=""menu"" class=""dropSheet"">");
            sb.AppendLine(@"<div id=""innerdiv"">");
            sb.AppendLine(@"<div id=""title"" style=""text"">Polygons</div>");

            if (jst != null)
            {
                sb.AppendLine(@"<div id=""jstree_div"">");
                sb.AppendLine(jst.ToString());
                sb.AppendLine("</div>");
            }
            else
            {
                sb.AppendLine("No Polygons");
            }

            sb.AppendLine("</div>");
            sb.AppendLine("</div>");
            sb.AppendLine("</body>");
            sb.AppendLine("</html>");

            return sb.ToString();
        }