private void AddTiledLayer(WMS.Layer wmsLayer, WMS.Style style) { double baseTileDegrees = 180; int totalLevels = 12; string styles = style != null ? style.Name : ""; string url = FillBoundingBoxUrl(MakeWmsGetMapUrl(wmsLayer.Name, styles, 0, 0, 0, 0, 256, 256, "", "")); int baseLevel = 1; string imageType = ".png"; double meanRadius = 300000000; //todo string referenceFrame = LayerManager.CurrentMap; string thumbUrl = "http://www.worldwidetelescope.org/wwtweb/thumbnail.aspx?name=" + referenceFrame; ImageSetHelper ish = new ImageSetHelper(wmsLayer.Title, url, ImageSetType.Planet, BandPass.Visible, ProjectionType.Equirectangular, (int)(uint)url.GetHashCode32(), baseLevel, totalLevels, 512, baseTileDegrees, imageType, true, "", 0, 0, 0, false, thumbUrl, false, false, 1, 0, 0, wmsLayer.Abstract, "", "", "", meanRadius, referenceFrame); if (AddAsLayer.Checked == false) { Earth3d.MainWindow.CurrentImageSet = ish; } else { ImageSetLayer layer = new ImageSetLayer(ish); layer.Enabled = true; layer.Name = wmsLayer.Title; layer.ReferenceFrame = LayerManager.CurrentMap; LayerManager.Add(layer, true); } }
private void AddTiledLayer(WMS_Tile_ServiceTiledPatternsTiledGroup tileGroup) { string tilePatern = GetPattern(tileGroup.TilePattern[0].Value); double degrees = GetLngDegrees(tilePatern); foreach (WMS_Tile_ServiceTiledPatternsTiledGroupTilePattern pat in tileGroup.TilePattern) { double deg = GetLngDegrees(pat.Value); if (deg < degrees) { degrees = deg; } } double baseTileDegrees = degrees; int totalLevels = -1; while (baseTileDegrees < 180) { totalLevels++; baseTileDegrees *= 2; } string url = serviceUrl + FillBoundingBoxUrl(tilePatern.Replace("&time=${time}", "")); int baseLevel = 3; //if (tileGroup.TilePattern.Length > totalLevels) { // baseLevel = (totalLevels +8) - tileGroup.TilePattern.Length; } string imageType = ".png"; double meanRadius = 300000000; //todo string referenceFrame = LayerManager.CurrentMap; string thumbUrl = "http://www.worldwidetelescope.org/wwtweb/thumbnail.aspx?name=" + referenceFrame; ImageSetHelper ish = new ImageSetHelper(tileGroup.Title, url, ImageSetType.Planet, BandPass.Visible, ProjectionType.Equirectangular, (int)(uint)url.GetHashCode32(), baseLevel, totalLevels, 512, baseTileDegrees, imageType, true, "", 0, 0, 0, false, thumbUrl, false, false, 1, 0, 0, tileGroup.Abstract, "", "", "", meanRadius, referenceFrame); if (AddAsLayer.Checked == false) { Earth3d.MainWindow.CurrentImageSet = ish; } else { ImageSetLayer layer = new ImageSetLayer(ish); layer.Enabled = true; layer.Name = tileGroup.Title; layer.ReferenceFrame = LayerManager.CurrentMap; LayerManager.Add(layer, true); } }
private void add_Click(object sender, EventArgs e) { if (LayersTree.SelectedNode == null) { return; } WMS_Tile_ServiceTiledPatternsTiledGroup tileGroup = LayersTree.SelectedNode.Tag as WMS_Tile_ServiceTiledPatternsTiledGroup; if (tileGroup != null) { AddTiledLayer(tileGroup); return; } WMS.Layer wmsLayer = LayersTree.SelectedNode.Tag as WMS.Layer; WMS.Style style = LayersTree.SelectedNode.Tag as WMS.Style; if (style != null && LayersTree.SelectedNode.Parent != null) { wmsLayer = LayersTree.SelectedNode.Parent.Tag as WMS.Layer; } if (wmsLayer != null) { if (TiledWMS.Checked) { AddTiledLayer(wmsLayer, style); return; } double west = -180; double east = 180; double north = 90; double south = -90; int width = 2048; int height = 2048; if (wmsLayer.EX_GeographicBoundingBox != null) { west = wmsLayer.EX_GeographicBoundingBox.westBoundLongitude; north = wmsLayer.EX_GeographicBoundingBox.northBoundLatitude; east = wmsLayer.EX_GeographicBoundingBox.eastBoundLongitude; south = wmsLayer.EX_GeographicBoundingBox.southBoundLatitude; } if (wmsLayer.LatLonBoundingBox != null) { west = wmsLayer.LatLonBoundingBox.minx; north = wmsLayer.LatLonBoundingBox.maxy; east = wmsLayer.LatLonBoundingBox.maxx; south = wmsLayer.LatLonBoundingBox.miny; } if (wmsLayer.fixedHeight != null) { int h = int.Parse(wmsLayer.fixedHeight); if (h > 0) { height = h; } } if (wmsLayer.fixedWidth != null) { int w = int.Parse(wmsLayer.fixedWidth); if (w > 0) { width = w; } } WmsLayer layer = new WmsLayer(); //string path = MakeWmsGetMapUrl(wmsLayer.Name, style != null ? style.Name : "", // west,north, east, south, // width, height, // "", // ""); layer.ServiceUrl = serviceUrl; layer.WmsVersion = wmsVersion; layer.Layers = wmsLayer.Name; layer.Styles = style != null ? style.Name : ""; layer.Overlay.north = north; layer.Overlay.south = south; layer.Overlay.west = west; layer.Overlay.east = east; layer.Height = height; layer.Width = width; if (wmsLayer.Dimension != null) { foreach (Dimension dim in wmsLayer.Dimension) { if (dim.name == "time") { string[] dates = wmsLayer.Dimension[0].Value.Split(new char[] { ',' }); foreach (string date in dates) { layer.TimeRanges.Add(new TimeRange(date)); } layer.UpdateTimeRange(); } } } layer.Enabled = true; layer.Name = wmsLayer.Title; layer.ReferenceFrame = LayerManager.CurrentMap; LayerManager.Add(layer, true); } }
public void MergeTourStopsFromXml(string filename) { XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode root = doc["Tour"]; bool timeLineTour = false; if (root.Attributes["TimeLineTour"] != null) { timeLineTour = bool.Parse(root.Attributes["TimeLineTour"].Value); } XmlNode TourStops = null; if (timeLineTour) { TourStops = root["TimeLineTourStops"]; } else { TourStops = root["TourStops"]; } foreach (XmlNode tourStop in TourStops) { currentTourstopIndex++; InsertTourStop(TourStop.FromXml(this, tourStop)); } XmlNode Frames = root["ReferenceFrames"]; if (Frames != null) { foreach (XmlNode frame in Frames) { ReferenceFrame newFrame = new ReferenceFrame(); newFrame.InitializeFromXml(frame); if (!LayerManager.AllMaps.ContainsKey(newFrame.Name)) { LayerMap map = new LayerMap(newFrame.Name, ReferenceFrames.Custom); map.Frame = newFrame; LayerManager.AllMaps.Add(newFrame.Name, map); } } LayerManager.ConnectAllChildren(); LayerManager.LoadTree(); } XmlNode Layers = root["Layers"]; if (Layers != null) { foreach (XmlNode layer in Layers) { Layer newLayer = Layer.FromXml(layer, true); string fileName = WorkingDirectory + string.Format("{0}.txt", newLayer.ID.ToString()); newLayer.LoadData(fileName); LayerManager.Add(newLayer, false); } LayerManager.LoadTree(); } }
public static TourDocument FromXml(string filename) { TourDocument newTour = new TourDocument(); newTour.filename = filename; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode root = doc["Tour"]; newTour.id = root.Attributes["ID"].Value.ToString(); newTour.Title = root.Attributes["Title"].Value.ToString(); newTour.Author = root.Attributes["Author"].Value.ToString(); if (root.Attributes["Descirption"] != null) { newTour.Description = root.Attributes["Descirption"].Value; } if (root.Attributes["Description"] != null) { newTour.Description = root.Attributes["Description"].Value; } if (root.Attributes["AuthorEmail"] != null) { newTour.authorEmail = root.Attributes["AuthorEmail"].Value; } if (root.Attributes["Keywords"] != null) { newTour.Keywords = root.Attributes["Keywords"].Value; } if (root.Attributes["OrganizationName"] != null) { newTour.OrgName = root.Attributes["OrganizationName"].Value; } if (root.Attributes["DomeMode"] != null) { newTour.DomeMode = bool.Parse(root.Attributes["DomeMode"].Value); } newTour.organizationUrl = root.Attributes["OrganizationUrl"].Value.ToString(); newTour.level = (UserLevel)Enum.Parse(typeof(UserLevel), root.Attributes["UserLevel"].Value.ToString()); newTour.type = (Classification)Enum.Parse(typeof(Classification), root.Attributes["Classification"].Value.ToString()); newTour.taxonomy = root.Attributes["Taxonomy"].Value.ToString(); bool timeLineTour = false; if (root.Attributes["TimeLineTour"] != null) { timeLineTour = bool.Parse(root.Attributes["TimeLineTour"].Value); } XmlNode TourStops = null; if (timeLineTour) { TourStops = root["TimeLineTourStops"]; } else { TourStops = root["TourStops"]; } foreach (XmlNode tourStop in TourStops) { newTour.AddTourStop(TourStop.FromXml(newTour, tourStop)); } XmlNode Frames = root["ReferenceFrames"]; if (Frames != null) { foreach (XmlNode frame in Frames) { ReferenceFrame newFrame = new ReferenceFrame(); newFrame.InitializeFromXml(frame); if (!LayerManager.AllMaps.ContainsKey(newFrame.Name)) { LayerMap map = new LayerMap(newFrame.Name, ReferenceFrames.Custom); map.Frame = newFrame; map.LoadedFromTour = true; LayerManager.AllMaps.Add(newFrame.Name, map); } } LayerManager.ConnectAllChildren(); LayerManager.LoadTree(); } XmlNode Layers = root["Layers"]; if (Layers != null) { foreach (XmlNode layer in Layers) { Layer newLayer = Layer.FromXml(layer, true); string fileName = newTour.WorkingDirectory + string.Format("{0}.txt", newLayer.ID.ToString()); // Overwite ISS layer if in a tour using the authored ISS details if (LayerManager.LayerList.ContainsKey(newLayer.ID) && newLayer.ID == ISSLayer.ISSGuid) { LayerManager.DeleteLayerByID(newLayer.ID, true, false); } // Ask about merging other layers. if (LayerManager.LayerList.ContainsKey(newLayer.ID) && newLayer.ID != ISSLayer.ISSGuid) { if (!newTour.CollisionChecked) { if (UiTools.ShowMessageBox(Language.GetLocalizedText(958, "There are layers with the same name. Overwrite existing layers?"), Language.GetLocalizedText(3, "Microsoft WorldWide Telescope"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { newTour.OverWrite = true; } else { newTour.OverWrite = false; } newTour.CollisionChecked = true; } if (newTour.OverWrite) { LayerManager.DeleteLayerByID(newLayer.ID, true, false); } } try { newLayer.LoadedFromTour = true; newLayer.LoadData(fileName); LayerManager.Add(newLayer, false); } catch { } } LayerManager.LoadTree(); } if (File.Exists(newTour.WorkingDirectory + "Author.png")) { newTour.authorImage = UiTools.LoadBitmap(newTour.WorkingDirectory + "Author.png"); } newTour.tourDirty = 0; return(newTour); }
public static LayerContainer FromXml(string filename, string parentFrame, bool referenceFrameRightClick) { LayerContainer newDoc = new LayerContainer(); newDoc.filename = filename; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNode root = doc["LayerContainer"]; newDoc.id = root.Attributes["ID"].Value.ToString(); XmlNode Layers = root["Layers"]; bool loadAtNewParent = false; if (!referenceFrameRightClick || Layers.ChildNodes.Count != 1) { XmlNode Frames = root["ReferenceFrames"]; if (Frames != null) { foreach (XmlNode frame in Frames) { ReferenceFrame newFrame = new ReferenceFrame(); newFrame.InitializeFromXml(frame); if (!LayerManager.AllMaps.ContainsKey(newFrame.Name)) { LayerMap map = new LayerMap(newFrame.Name, ReferenceFrames.Custom); map.Frame = newFrame; LayerManager.AllMaps.Add(newFrame.Name, map); } } LayerManager.ConnectAllChildren(); LayerManager.LoadTree(); } } else { loadAtNewParent = true; } if (Layers != null) { foreach (XmlNode layer in Layers) { Layer newLayer = Layer.FromXml(layer, true); string fileName = newDoc.WorkingDirectory + string.Format("{0}.txt", newLayer.ID.ToString()); if (LayerManager.LayerList.ContainsKey(newLayer.ID) && newLayer.ID != ISSLayer.ISSGuid) { if (!newDoc.CollisionChecked) { if (UiTools.ShowMessageBox(Language.GetLocalizedText(958, "There are layers with the same name. Overwrite existing layers?"), Language.GetLocalizedText(3, "Microsoft WorldWide Telescope"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { newDoc.OverWrite = true; } else { newDoc.OverWrite = false; } newDoc.CollisionChecked = true; } if (newDoc.OverWrite) { LayerManager.DeleteLayerByID(newLayer.ID, true, false); } } newLayer.LoadData(fileName); if (loadAtNewParent) { newLayer.ReferenceFrame = parentFrame; } LayerManager.Add(newLayer, false); newDoc.LastLoadedLayer = newLayer; } LayerManager.LoadTree(); } newDoc.tourDirty = 0; return(newDoc); }