Exemplo n.º 1
0
        public void WriteProject(DataAccessLayer DAL)
        {
            if (Values.Settings.ProjectOptions != null && Values.Settings.DeviceOptions != null)
            {
                List<string> Columns = new List<string>();
                List<List<string>> data = new List<List<string>>();

                #region Columns
                Columns.Add("Project ID");
                Columns.Add("Description");
                Columns.Add("Region");
                Columns.Add("Forest");
                Columns.Add("District");
                Columns.Add("Year");
                Columns.Add("DropZero");
                Columns.Add("GPS COM");
                Columns.Add("GPS Baud");
                Columns.Add("Laser COM");
                Columns.Add("Laser Baud");
                Columns.Add("TtVersion");
                //Columns.Add("Build Date");
                Columns.Add("TtDbVersion");
                #endregion

                #region Add Data
                List<string> info = new List<string>();
                info.Add(DAL.GetProjectID().Scrub());
                info.Add(DAL.GetProjectDescription().Scrub());
                info.Add(DAL.GetProjectRegion().Scrub());
                info.Add(DAL.GetProjectForest().Scrub());
                info.Add(DAL.GetProjectDistrict().Scrub());
                info.Add(DAL.GetProjectYear());
                info.Add(Values.Settings.ProjectOptions.DropZero.ToString());
                info.Add(Values.Settings.DeviceOptions.GpsComPort.Scrub());
                info.Add(Values.Settings.DeviceOptions.GpsBaud.ToString());
                info.Add(Values.Settings.DeviceOptions.LaserComPort.Scrub());
                info.Add(Values.Settings.DeviceOptions.LaserBaud.ToString());
                info.Add(DAL.GetProjectTtStartVersion());
                //info.Add(Values.TwoTrailsBuildDate);
                info.Add(DAL.DalVersion.ToString());
                data.Add(info);
                #endregion

                WriteCsvFile("ProjectInfo", Columns, data);
            }
        }
        private void OpenTtFile(string filename)
        {
            if (filename == "Recent Items")
                return;

            bool skip = false;
            try
            {
                TtUtils.ShowWaitCursor();
                _FileName = filename;
                Values.CurrentTtFileName = _FileName;

            #if !(PocketPC || WindowsCE || Mobile)
                FileAttributes attributes = File.GetAttributes(_FileName);

                if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    attributes = attributes & ~FileAttributes.ReadOnly;

                    File.SetAttributes(_FileName, attributes);
                }
            #endif

                if (data != null && data.IsOpen)
                    data.CloseDB();
                data = new DataAccessLayer(_FileName);
                data.OpenDAL();
                Values.CurrentDbVersion = false;
                FileLoaded = true;

                Values.DataExport.FolderName = System.IO.Path.GetFileNameWithoutExtension(_FileName);

                TtUtils.HideWaitCursor();

                try
                {
                    if (data.DalVersion != TwoTrailsSchema.SchemaVersion)
                    {
                        bool closefile = false;

                        if (data.DalVersion < TwoTrailsSchema.SchemaVersion)
                        {
            #if !(PocketPC || WindowsCE || Mobile)
                            pnlInfo.Visible = false;
            #endif
                            if (MessageBox.Show(String.Format("Old Project Version ({1}). Would you like to upgrade to version {0}?", TwoTrailsSchema.SchemaVersion, data.DalVersion), "Old Project Version", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                            {
                                UpgradeTtFile(_FileName);
                            }
                            else
                            {
                                closefile = true;
                            }
                        }
                        else
                        {
                            MessageBox.Show(
                                String.Format("This project file ({0}) requires a newer version of TwoTrails to open.",
                                data.DalVersion), "incompatible file", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                            closefile = true;
                        }

                        if (closefile)
                        {
                            if (data != null && data.IsOpen)
                            {
                                data.CloseDB();
                            }

                            FileLoaded = false;
                        }

                        skip = true;
                    }
                    else
                    {
                        Values.CurrentDbVersion = true;

                    #if !(PocketPC || WindowsCE || Mobile)
                        Values.UpdateStatusText(String.Format("File {0} Loaded.", Path.GetFileName(_FileName)));
                        pnlInfo.Visible = true;
                        UpdateInfo(File.GetCreationTime(_FileName));
                        ChangeTitle(System.IO.Path.GetFileName(filename));
                    #else
                        tbTtFileName.Text = System.IO.Path.GetFileName(filename);
                    #endif
                    }
                }
                catch
                {
                    MessageBox.Show("Unable to get Project Version");
                    skip = true;
                }

                if(!skip)
                {
                    tabControl1.SelectedIndex = 1;

                    cboRecOpen.Items.Clear();
                    cboRecOpen.Items.Add(Values.Settings.ProjectOptions.RecOpen[0].File);
                    Values.Settings.ProjectOptions.AddToRecent(filename, data.GetProjectID());

                    foreach (RecentProject rec in Values.Settings.ProjectOptions.RecOpen)
                    {
                        if (rec.Name != "___")
                            cboRecOpen.Items.Add(System.IO.Path.GetFileName(rec.File));
                    }

                    cboRecOpen.SelectedIndex = 0;

                    #if (PocketPC || WindowsCE || Mobile)
                    btnRecOpen.Enabled = true;
                    #endif
                    cboRecOpen.Enabled = true;
                    Values.Settings.WriteProjectSettings();
                    Values.GPSA.LogFilename = Path.Combine(System.IO.Path.GetDirectoryName(filename), "GPS_Log.txt");
                }
            }
            catch (SQLiteException sqlEx)
            {
            #if !(PocketPC || WindowsCE || Mobile)
                pnlInfo.Visible = false;
            #endif
                switch (sqlEx.ResultCode)
                {
                    case SQLiteErrorCode.NotADb:
                        MessageBox.Show("Database error, not a TwoTrails File");
                        TtUtils.WriteError("SQLiteErrorCode.NotADatabase: Database error, not a TwoTrails File", "MainFormLogic");
                        break;
                    default:
                        MessageBox.Show(sqlEx.Message);
                        break;
                }

                #if (PocketPC || WindowsCE || Mobile)
                tbTtFileName.Text = "";
                #else
                ChangeTitle("");
                #endif
            }
            catch (Exception ex)
            {
            #if !(PocketPC || WindowsCE || Mobile)
                pnlInfo.Visible = false;
            #endif
                MessageBox.Show(ex.Message);
                #if (PocketPC || WindowsCE || Mobile)
                tbTtFileName.Text = "";
                #else
                ChangeTitle("");
                #endif
            }
            finally
            {
                TtUtils.HideWaitCursor();
            }
        }
        private void UpgradeTtFile(string filename)
        {
            DataAccessLayer oldData = null;

            string oldFile = System.IO.Path.GetDirectoryName(filename) + "\\" + System.IO.Path.GetFileNameWithoutExtension(filename) + ".old.tt2";

            try
            {
            #if !(PocketPC || WindowsCE || Mobile)
            tsProg.Value = 0;
            tsProg.Visible = true;
            #endif

                FileLoaded = false;

                TtUtils.WriteEvent("Database upgrade started.", true);

                if (data != null && data.IsOpen)
                    data.CloseDB();

                if (File.Exists(oldFile))
                {
                    if (MessageBox.Show(String.Format("File '{0}' already exists. Would you like to overwrite it?", System.IO.Path.GetFileNameWithoutExtension(oldFile)), "", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        File.Delete(oldFile);
                    }
                    else
                    {
                        int count = 2;
                        while (File.Exists(oldFile))
                        {
                            oldFile = System.IO.Path.GetDirectoryName(filename) + "\\" + System.IO.Path.GetFileNameWithoutExtension(filename) + String.Format(".old_{0}.tt2", count);
                            count++;
                        }
                    }
                }

                TtUtils.ShowWaitCursor();

            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusText(String.Format("Upgrading file {0}.", Path.GetFileName(_FileName)));
            #endif
                TtUtils.ShowWaitCursor();
                string fileNoPath = System.IO.Path.GetFileName(filename);
                string oldFileNoPath = System.IO.Path.GetFileName(oldFile);

                Application.DoEvents();

            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusProgress();
            #endif

                File.Move(filename, oldFile);
                TtUtils.WriteEvent(String.Format("File Renamed: {0} to {1}.", fileNoPath, oldFileNoPath), true);
                oldData = new DataAccessLayer(oldFile);
                oldData.OpenDAL();

            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusProgress();
            #endif
                data = NewOpenLogic.NewTwoTrailsFile(filename);
                if (data == null)
                    throw new Exception(String.Format("Failed to create TtFile ", filename));
                data.OpenDAL();

                bool upgraded = data.Upgrade(oldData);
                TtUtils.WriteEvent("Upgrade proccess finished.", true);
                TtUtils.HideWaitCursor();

            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusProgress();
            #endif

                if (upgraded)
                {
                    Values.CurrentDbVersion = true;
                    FileLoaded = true;

                    oldData.CloseDB();

                    TtUtils.WriteMessage(String.Format("{0} Upgraded to version {1}.", fileNoPath, TwoTrailsSchema.SchemaVersion));
                    MessageBox.Show("File upgraded successfully.");
                    tabControl1.SelectedIndex = 1;
                    Values.Settings.ProjectOptions.AddToRecent(filename, data.GetProjectID());

            #if !(PocketPC || WindowsCE || Mobile)
                    UpdateInfo(File.GetCreationTime(_FileName));
                    Values.UpdateStatusText(String.Format("File {0} Upgraded.", Path.GetFileName(_FileName)));
                    tsProg.Visible = false;
                    ChangeTitle(Path.GetFileName(_FileName));
            #else
                    tbTtFileName.Text = Path.GetFileName(_FileName);
            #endif
                }
                else
                {
                    if (oldData != null && oldData.IsOpen)
                        oldData.CloseDB();
                    if (data != null && data.IsOpen)
                        data.CloseDB();

                    oldData = null;
                    data = null;

                    GC.Collect();

                    File.Delete(filename);
                    File.Move(oldFile, filename);
                    TtUtils.WriteMessage("File failed to upgrade.");

            #if !(PocketPC || WindowsCE || Mobile)
                    tsProg.Value = 0;
            #endif

                    MessageBox.Show("File failed to upgrade.");
                }
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "MainFormLogic:TtFileUpgrade");
                if (oldData != null && oldData.IsOpen)
                    oldData.CloseDB();
                if (data != null && data.IsOpen)
                    data.CloseDB();

                MessageBox.Show("An error has occured. Please see error log for details.");
            #if !(PocketPC || WindowsCE || Mobile)
                Values.UpdateStatusText("Upgrade Error.");
            #endif
            }
            finally
            {
                TtUtils.HideWaitCursor();

            #if !(PocketPC || WindowsCE || Mobile)
            tsProg.Visible = false;
            #endif
            }
        }
        private void NewTtFile()
        {
            string fileName;

            if(data != null)
                data.CloseDB();
            FileLoaded = false;

            #if (PocketPC || WindowsCE || Mobile)
            SelectFileDialogEx saveFileDialog1 = new SelectFileDialogEx(null, Values.DefaultSaveFolder);
            //Kb.SetKeyboardToRegularOverride();  //set regular keyboard
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            #else
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "TwoTrails 2 Files|*.tt2";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            #endif
            {
                TtUtils.ShowWaitCursor();
                fileName = saveFileDialog1.FileName;

                if (fileName.Length > 4)
                {
                    if (fileName.Substring(fileName.Length - 4, 4) != ".tt2")
                        fileName += ".tt2";
                }
                else
                {
                    fileName += ".tt2";
                }

                data = NewOpenLogic.NewTwoTrailsFile(fileName);
                if (data != null)
                {
                    _FileName = fileName;

            #if (PocketPC || WindowsCE || Mobile)
                    tbTtFileName.Text = System.IO.Path.GetFileName(_FileName);
            #else
                    ChangeTitle(_FileName);
            #endif
                    data.OpenDAL();
                    tabControl1.SelectedIndex = 1;

                    Values.CurrentDbVersion = true;
                    FileLoaded = true;
                    Values.Settings.ProjectOptions.AddToRecent(_FileName, data.GetProjectID());
                    TtUtils.HideWaitCursor();

            #if !(PocketPC || WindowsCE || Mobile)
                    Values.UpdateStatusText(String.Format("File {0} Loaded.", Path.GetFileName(_FileName)));
                    pnlInfo.Visible = true;
                    UpdateInfo(File.GetCreationTime(_FileName));
                    ChangeTitle(Path.GetFileName(_FileName));
            #else
                        tbTtFileName.Text = System.IO.Path.GetFileName(fileName);
            #endif

                    using (ProjectInfoForm form = new ProjectInfoForm(data))
                    {
                        form.ShowDialog();
            #if!(PocketPC || WindowsCE || Mobile)
                        UpdateInfo();
            #endif
                    }

                    Values.DataExport.FolderName = System.IO.Path.GetFileNameWithoutExtension(_FileName);
                }
                else
                {
            #if!(PocketPC || WindowsCE || Mobile)
                    UpdateInfo();
            #endif
                }
            }
        }
        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();
        }