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; }
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 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 }
public PolyWPoints(TtPolygon poly, DataAccessLayer DAL) { this.polygon = poly; this.points = DAL.GetPointsInPolygon(poly.CN); for (int i = 0; i < points.Count; i++) { //points[i].AdjX *= -1; points[i].AdjY *= -1; //points[i].AdjZ *= -1; //points[i].UnAdjX *= -1; points[i].UnAdjY *= -1; //points[i].UnAdjZ *= -1; } }
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 void Init(TtPolygon poly, DataAccessLayer dal, TtMetaData meta, int currIndex) { this.Icon = Properties.Resources.Map; TtUtils.ShowWaitCursor(); Values.GPSA.BurstReceived += GPSA_BurstReceived; Values.GPSA.InvalidStringFound += GPSA_InvalidStringFound; Values.GPSA.ComTimeout += GPSA_ComTimeout; Values.GPSA.GpsStarted += GPSA_GpsStarted; Values.GPSA.GpsEnded += GPSA_GpsEnded; Values.GPSA.GpsError += GPSA_GpsError; Polygon = poly; DAL = dal; _currmeta = meta; logging = false; this.DialogResult = DialogResult.Cancel; OnBound = true; lblPoly.Text = "Poly: " + Polygon.Name; logged = 0; _locked = true; _sound = true; #if (PocketPC || WindowsCE || Mobile) player = new SoundPlayer(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ring.wav")); #else player = new SoundPlayer(Properties.Resources.Ring); #endif #if !(PocketPC || WindowsCE || Mobile) picBox.SizeMode = PictureBoxSizeMode.StretchImage; picBox.Image = Properties.Resources.Walking_Transparent; #else animation = new AnimationCtrl(); animation.Location = new Point((this.Width - Properties.Resources.walking1.Width / 5) - 10, 0); this.Controls.Add(animation); animation.BringToFront(); animation.LoadImage(new List<Bitmap>() { Properties.Resources.walking1, Properties.Resources.walking2, Properties.Resources.walking3 ,Properties.Resources.walking4, Properties.Resources.walking5, Properties.Resources.walking6, Properties.Resources.walking7,}, Properties.Resources.walking1.Width / 5, Properties.Resources.walking1.Height / 5, 75, -1); #endif CurrentPoint = null; List<TtPoint> points = DAL.GetPointsInPolygon(Polygon); _index = currIndex; if (_index > 0) { TtPoint lPoint = (points[_index - 1]); LastPoint = new WalkPoint(); LastPoint.PID = lPoint.PID; LastPoint.Index = lPoint.Index; } cboDOP.SelectedIndex = Values.Settings.DeviceOptions.Filter_WALK_DOP_TYPE; cboFixType.SelectedIndex = Values.Settings.DeviceOptions.Filter_WALK_FixType; #if (PocketPC || WindowsCE || Mobile) btnDOP.Text = cboDOP.Text; btnFixType.Text = cboFixType.Text; #endif txtDOP.Text = Values.Settings.DeviceOptions.Filter_WALK_DOP_VALUE.ToString(); txtAcc.Text = Values.Settings.DeviceOptions.Filter_Accuracy.ToString(); txtFreq.Text = Values.Settings.DeviceOptions.Filter_Frequency.ToString(); txtIncrement.Text = Values.Settings.DeviceOptions.WalkIncrement.ToString(); _increment = Values.Settings.DeviceOptions.WalkIncrement; gpsInfoAdvCtrl.SetZone(_currmeta.Zone); gpsInfoAdvCtrl.StartControl(); TtUtils.HideWaitCursor(); }
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(); } }
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(); }