public void UpdateTexture(Device device, string textureFileName) { if ((textureFileName != null) && textureFileName.Length > 0) { if (textureFileName.ToLower().StartsWith("http://") && BaseSavePath != null) { // download it try { Uri uri = new Uri(textureFileName); // Set the subdirectory path to the hostname and replace . with _ string savePath = uri.Host; savePath = savePath.Replace('.', '_'); // build the save file name from the component pieces savePath = BaseSavePath + @"\" + savePath + uri.AbsolutePath; savePath = savePath.Replace('/', '\\'); // Offline check if (!World.Settings.WorkOffline) { WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(textureFileName); webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified; webDownload.DownloadFile(savePath); } // reset the texture file name for later use. textureFileName = savePath; } catch { } } } // Clear old texture - don't know if this is necessary so commented out for the moment //if (Texture != null) //{ // Texture.Dispose(); //} if (ImageHelper.IsGdiSupportedImageFormat(textureFileName)) { // Load without rescaling source bitmap using (Image image = ImageHelper.LoadImage(textureFileName)) LoadImage(device, image); } else { // Only DirectX can read this file, might get upscaled depending on input dimensions. Texture = ImageHelper.LoadIconTexture(textureFileName); // Read texture level 0 size using (Surface s = Texture.GetSurfaceLevel(0)) { SurfaceDescription desc = s.Description; Width = desc.Width; Height = desc.Height; } } }
public override void Initialize(DrawArgs drawArgs) { if (m_points == null) { isInitialized = true; return; } if (m_imageUri != null) { //load image if (m_imageUri.ToLower().StartsWith("http://")) { string savePath = string.Format("{0}\\image", ConfigurationLoader.GetRenderablePathString(this)); System.IO.FileInfo file = new System.IO.FileInfo(savePath); if (!file.Exists) { //Offline check if (!World.Settings.WorkOffline) { WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri); if (!file.Directory.Exists) { file.Directory.Create(); } download.DownloadFile(file.FullName, WorldWind.Net.DownloadType.Unspecified); } } //file might not have downloaded. Especially if we are offline if (!file.Exists) { m_texture = ImageHelper.LoadTexture(file.FullName); } else { m_texture = null; } } else { m_texture = ImageHelper.LoadTexture(m_imageUri); } } UpdateVertices(); isInitialized = true; }
/// <summary> /// Initializes a new instance of the <see cref= "T:WorldWind.Renderable.IconTexture"/> class /// from a texture file on disk. /// </summary> public IconTexture(Device device, string textureFileName) { if ((textureFileName != null) && textureFileName.Length > 0) { if (textureFileName.ToLower().StartsWith("http://") && BaseSavePath != null) { // download it try { Uri uri = new Uri(textureFileName); // Set the subdirectory path to the hostname and replace . with _ string savePath = uri.Host; savePath = savePath.Replace('.', '_'); // build the save file name from the component pieces savePath = BaseSavePath + @"\" + savePath + uri.AbsolutePath; savePath = savePath.Replace('/', '\\'); WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(textureFileName); webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified; webDownload.DownloadFile(savePath); // reset the texture file name for later use. textureFileName = savePath; } catch { } } } if(ImageHelper.IsGdiSupportedImageFormat(textureFileName)) { // Load without rescaling source bitmap using(Image image = ImageHelper.LoadImage(textureFileName)) LoadImage(device, image); } else { // Only DirectX can read this file, might get upscaled depending on input dimensions. Texture = ImageHelper.LoadIconTexture( textureFileName ); // Read texture level 0 size using(Surface s = Texture.GetSurfaceLevel(0)) { SurfaceDescription desc = s.Description; Width = desc.Width; Height = desc.Height; } } }
private void GetFeatureDlComplete(WorldWind.Net.WebDownload dl) { if (World.Settings.UseInternalBrowser) { SplitContainer sc = (SplitContainer)drawArgs.parentControl.Parent.Parent; InternalWebBrowserPanel browser = (InternalWebBrowserPanel)sc.Panel1.Controls[0]; browser.NavigateTo(dl.SavedFilePath); } else { System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); psi.FileName = dl.SavedFilePath; psi.Verb = "open"; psi.UseShellExecute = true; psi.CreateNoWindow = true; System.Diagnostics.Process.Start(psi); } }
void WorldWindow_MouseUp(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Right) { return; } if (m_Form == null) { return; } if (!m_Form.Visible) { return; } if (m_Form.KeyLayer == null) { return; } QuadTileSet qts = m_Form.KeyLayer; WorldWind.Net.Wms.WmsImageStore wms = (WorldWind.Net.Wms.WmsImageStore)qts.ImageStores[0]; string requestUrl = wms.ServerGetMapUrl; string[] layerNameParts = wms.WMSLayerName.Split('&'); string layerName = layerNameParts[0]; string getMapParts = requestUrl += "?QUERY_LAYERS=" + layerName + "&SERVICE=WMS&VERSION=" + wms.Version + "&REQUEST=GetFeatureInfo&SRS=EPSG:4326&FEATURE_COUNT=10&INFO_FORMAT=text/plain&EXCEPTIONS=text/plain"; // From Servir-Viz... Angle LowerLeftX; Angle LowerLeftY; Angle UpperRightX; Angle UpperRightY; string minx, miny, maxx, maxy; char[] degreeChar = { '°' }; int mouseX = e.X; int mouseY = e.Y; int queryBoxWidth = 2 * queryBoxOffset + 1; int queryBoxHeight = 2 * queryBoxOffset + 1; int queryX = queryBoxOffset + 1; int queryY = queryBoxOffset + 1; drawArgs.WorldCamera.PickingRayIntersectionWithTerrain(mouseX - queryBoxOffset, mouseY + queryBoxOffset, out LowerLeftY, out LowerLeftX, drawArgs.CurrentWorld); drawArgs.WorldCamera.PickingRayIntersectionWithTerrain(mouseX + queryBoxOffset, mouseY - queryBoxOffset, out UpperRightY, out UpperRightX, drawArgs.CurrentWorld); //drawArgs.WorldCamera.PickingRayIntersectionWithTerrain(0, 0 + drawArgs.screenHeight, out LowerLeftY, out LowerLeftX, drawArgs.CurrentWorld); //drawArgs.WorldCamera.PickingRayIntersectionWithTerrain(drawArgs.screenWidth, 0, out UpperRightY, out UpperRightX, drawArgs.CurrentWorld); minx = LowerLeftX.ToString().Contains("NaN") ? "-180.0" : LowerLeftX.ToString().TrimEnd(degreeChar); miny = LowerLeftY.ToString().Contains("NaN") ? "-90.0" : LowerLeftY.ToString().TrimEnd(degreeChar); maxx = UpperRightX.ToString().Contains("NaN") ? "180.0" : UpperRightX.ToString().TrimEnd(degreeChar); maxy = UpperRightY.ToString().Contains("NaN") ? "90.0" : UpperRightY.ToString().TrimEnd(degreeChar); // request has to include a bbox and the requested pixel coords relative to that box... requestUrl += "&layers=" + wms.WMSLayerName; requestUrl += "&WIDTH=" + queryBoxWidth.ToString() + "&HEIGHT=" + queryBoxHeight.ToString(); requestUrl += "&BBOX=" + minx + "," + miny + "," + maxx + "," + maxy; requestUrl += "&X=" + queryX.ToString() + "&Y=" + queryY.ToString(); if (!World.Settings.WorkOffline) { WorldWind.Net.WebDownload dl = new WorldWind.Net.WebDownload(requestUrl); System.IO.FileInfo fi = new System.IO.FileInfo("GetFeatureInfo_response.txt"); dl.DownloadFile(fi.FullName); //dl.SavedFilePath = fi.FullName; //dl.BackgroundDownloadFile(GetFeatureDlComplete); if (World.Settings.UseInternalBrowser) { SplitContainer sc = (SplitContainer)drawArgs.parentControl.Parent.Parent; InternalWebBrowserPanel browser = (InternalWebBrowserPanel)sc.Panel1.Controls[0]; browser.NavigateTo(fi.FullName); } else { System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); psi.FileName = fi.FullName; psi.Verb = "open"; psi.UseShellExecute = true; psi.CreateNoWindow = true; System.Diagnostics.Process.Start(psi); } } }
private void m_RefreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { if (isUpdating) { return; } isUpdating = true; if (m_ImageUri == null) { return; } if (m_ImageUri.ToLower().StartsWith("http://")) { bool forceDownload = false; if (m_SaveFilePath == null) { // TODO: hack, need to get the correct cache directory m_SaveFilePath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Cache\\PictureBoxImages\\temp"; forceDownload = true; } System.IO.FileInfo saveFile = new System.IO.FileInfo(m_SaveFilePath); if (forceDownload || !saveFile.Exists || (m_RefreshTime > 0 && saveFile.LastWriteTime.Subtract(System.DateTime.Now) > TimeSpan.FromSeconds(m_RefreshTime))) { //download it try { WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(m_ImageUri); webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified; if (!saveFile.Directory.Exists) { saveFile.Directory.Create(); } webDownload.DownloadFile(m_SaveFilePath); } catch { } } } else { m_SaveFilePath = m_ImageUri; } if (m_ImageTexture != null && !m_ImageTexture.Disposed) { m_ImageTexture.Dispose(); m_ImageTexture = null; } if (!System.IO.File.Exists(m_SaveFilePath)) { displayText = "Image Not Found"; return; } if (LoadAsUncompressed) { m_ImageTexture = TextureLoader.FromFile(DrawArgs.Device, m_SaveFilePath, 0, 0, 1, 0, Format.Unknown, Pool.Managed, Filter.None, Filter.None, 0); } else { m_ImageTexture = ImageHelper.LoadTexture(m_SaveFilePath); } m_surfaceDescription = m_ImageTexture.GetLevelDescription(0); int width = ClientSize.Width; int height = ClientSize.Height; if (ClientSize.Width == 0) { width = m_surfaceDescription.Width; } if (ClientSize.Height == 0) { height = m_surfaceDescription.Height; } if (ParentWidget is Widgets.Form && SizeParentToImage) { Widgets.Form parentForm = (Widgets.Form)ParentWidget; parentForm.ClientSize = new System.Drawing.Size(width, height + parentForm.HeaderHeight); } else if (SizeParentToImage) { ParentWidget.ClientSize = new System.Drawing.Size(width, height); } ClientSize = new System.Drawing.Size(width, height); m_currentImageUri = m_ImageUri; IsLoaded = true; isUpdating = false; displayText = null; if (m_RefreshTime == 0 && m_RefreshTimer.Enabled) { m_RefreshTimer.Stop(); } } catch (Exception ex) { Log.Write(ex); } }
private void refreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (isUpdating) { return; } isUpdating = true; try { for (int i = 0; i < this.ChildObjects.Count; i++) { RenderableObject ro = (RenderableObject)this.ChildObjects[i]; if (ro != null && ro.IsOn && ro is Icon) { Icon icon = (Icon)ro; if (icon.RefreshInterval == TimeSpan.MaxValue || icon.LastRefresh > System.DateTime.Now - icon.RefreshInterval) { continue; } object key = null; IconTexture iconTexture = null; if (icon.TextureFileName != null && icon.TextureFileName.Length > 0) { if (icon.TextureFileName.ToLower().StartsWith("http://") && icon.SaveFilePath != null) { //download it try { WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(icon.TextureFileName); webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified; System.IO.FileInfo saveFile = new System.IO.FileInfo(icon.SaveFilePath); if (!saveFile.Directory.Exists) { saveFile.Directory.Create(); } webDownload.DownloadFile(saveFile.FullName); } catch {} iconTexture = (IconTexture)m_textures[icon.SaveFilePath]; if (iconTexture != null) { IconTexture tempTexture = iconTexture; m_textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.SaveFilePath); tempTexture.Dispose(); } else { key = icon.SaveFilePath; iconTexture = new IconTexture(DrawArgs.Device, icon.SaveFilePath); // New texture, cache it m_textures.Add(key, iconTexture); // Use default dimensions if not set if (icon.Width == 0) { icon.Width = iconTexture.Width; } if (icon.Height == 0) { icon.Height = iconTexture.Height; } } } else { // Icon image from file iconTexture = (IconTexture)m_textures[icon.TextureFileName]; if (iconTexture != null) { IconTexture tempTexture = iconTexture; m_textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.TextureFileName); tempTexture.Dispose(); } else { key = icon.SaveFilePath; iconTexture = new IconTexture(DrawArgs.Device, icon.TextureFileName); // New texture, cache it m_textures.Add(key, iconTexture); // Use default dimensions if not set if (icon.Width == 0) { icon.Width = iconTexture.Width; } if (icon.Height == 0) { icon.Height = iconTexture.Height; } } } } else { // Icon image from bitmap if (icon.Image != null) { iconTexture = (IconTexture)m_textures[icon.Image]; if (iconTexture != null) { IconTexture tempTexture = iconTexture; m_textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.Image); tempTexture.Dispose(); } else { key = icon.SaveFilePath; iconTexture = new IconTexture(DrawArgs.Device, icon.Image); // New texture, cache it m_textures.Add(key, iconTexture); // Use default dimensions if not set if (icon.Width == 0) { icon.Width = iconTexture.Width; } if (icon.Height == 0) { icon.Height = iconTexture.Height; } } } } icon.LastRefresh = System.DateTime.Now; } } } catch {} finally { isUpdating = false; } }
public override void Initialize(DrawArgs drawArgs) { if (!isOn) { return; } if (m_sprite != null) { m_sprite.Dispose(); m_sprite = null; } m_sprite = new Sprite(drawArgs.device); System.TimeSpan smallestRefreshInterval = System.TimeSpan.MaxValue; // Load all textures foreach (RenderableObject ro in m_children) { Icon icon = ro as Icon; if (icon == null) { // Child is not an icon if (ro.IsOn) { ro.Initialize(drawArgs); } continue; } if (icon.RefreshInterval.TotalMilliseconds != 0 && icon.RefreshInterval != TimeSpan.MaxValue && icon.RefreshInterval < smallestRefreshInterval) { smallestRefreshInterval = icon.RefreshInterval; } // Child is an icon icon.Initialize(drawArgs); object key = null; IconTexture iconTexture = null; if (icon.TextureFileName != null && icon.TextureFileName.Length > 0) { if (icon.TextureFileName.ToLower().StartsWith("http://") && icon.SaveFilePath != null) { //download it try { WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(icon.TextureFileName); webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified; System.IO.FileInfo saveFile = new System.IO.FileInfo(icon.SaveFilePath); if (!saveFile.Directory.Exists) { saveFile.Directory.Create(); } webDownload.DownloadFile(saveFile.FullName); } catch {} iconTexture = (IconTexture)m_textures[icon.SaveFilePath]; if (iconTexture == null) { key = icon.SaveFilePath; iconTexture = new IconTexture(drawArgs.device, icon.SaveFilePath); } } else { // Icon image from file iconTexture = (IconTexture)m_textures[icon.TextureFileName]; if (iconTexture == null) { key = icon.TextureFileName; iconTexture = new IconTexture(drawArgs.device, icon.TextureFileName); } } } else { // Icon image from bitmap if (icon.Image != null) { iconTexture = (IconTexture)m_textures[icon.Image]; if (iconTexture == null) { // Create new texture from image key = icon.Image; iconTexture = new IconTexture(drawArgs.device, icon.Image); } } } if (iconTexture == null) { // No texture set continue; } if (key != null) { // New texture, cache it m_textures.Add(key, iconTexture); // Use default dimensions if not set if (icon.Width == 0) { icon.Width = iconTexture.Width; } if (icon.Height == 0) { icon.Height = iconTexture.Height; } } } // Compute mouse over bounding boxes foreach (RenderableObject ro in m_children) { Icon icon = ro as Icon; if (icon == null) { // Child is not an icon continue; } if (GetTexture(icon) == null) { // Label only icon.SelectionRectangle = drawArgs.defaultDrawingFont.MeasureString(null, icon.Name, DrawTextFormat.None, 0); } else { // Icon only icon.SelectionRectangle = new Rectangle(0, 0, icon.Width, icon.Height); } // Center the box at (0,0) icon.SelectionRectangle.Offset(-icon.SelectionRectangle.Width / 2, -icon.SelectionRectangle.Height / 2); } if (refreshTimer == null && smallestRefreshInterval != TimeSpan.MaxValue) { refreshTimer = new System.Timers.Timer(smallestRefreshInterval.TotalMilliseconds); refreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(refreshTimer_Elapsed); refreshTimer.Start(); } isInitialized = true; }
public static RenderableObjectList getRenderableFromLayerFile(string layerFile, World parentWorld, Cache cache, bool enableRefresh, string layerSetSchema) { Log.Write(Log.Levels.Debug + 1, "CONF", "Loading renderable from " + layerFile); try { XPathDocument docNav = null; XPathNavigator nav = null; XmlReaderSettings readerSettings = new XmlReaderSettings(); if (layerSetSchema != null && File.Exists(layerSetSchema)) { Log.Write(Log.Levels.Debug, "CONF", "validating " + layerFile + " against LayerSet.xsd"); readerSettings.ValidationType = ValidationType.Schema; XmlSchemaSet schemas = new XmlSchemaSet(); schemas.Add(null, layerSetSchema); readerSettings.Schemas = schemas; readerSettings.ValidationEventHandler += new ValidationEventHandler(XMLValidationCallback); readerSettings.ValidationFlags |= System.Xml.Schema.XmlSchemaValidationFlags.ReportValidationWarnings; } else { Log.Write(Log.Levels.Debug, "CONF", "loading " + layerFile + " without validation"); readerSettings.ValidationType = ValidationType.None; } try { if (layerFile.IndexOf(@"http://") < 0) { XmlReader docReader = XmlReader.Create(layerFile, readerSettings); docNav = new XPathDocument(docReader); docReader.Close(); } else { Angle[] bbox = CameraBase.getViewBoundingBox(); string viewBBox = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", bbox[0].ToString().TrimEnd('°'), bbox[1].ToString().TrimEnd('°'), bbox[2].ToString().TrimEnd('°'), bbox[3].ToString().TrimEnd('°')); //See if there is a ? already in the URL int flag = layerFile.IndexOf("?"); if (flag == -1) layerFile = layerFile + "?BBOX=" + viewBBox; else layerFile = layerFile + "&BBOX=" + viewBBox; WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(layerFile); download.DownloadMemory(); XmlReader docReader = XmlReader.Create(download.ContentStream, readerSettings); docNav = new XPathDocument(docReader); docReader.Close(); } nav = docNav.CreateNavigator(); } catch (Exception ex) { Log.Write(ex); return null; } XPathNodeIterator iter = nav.Select("/LayerSet"); if (iter.Count > 0) { iter.MoveNext(); string redirect = iter.Current.GetAttribute("redirect", ""); redirect = redirect.Replace("${WORLDWINDVERSION}", System.Windows.Forms.Application.ProductVersion); string redirectWithoutBBOX = redirect; if (redirect != null && redirect.Length > 0) { FileInfo layerFileInfo = new FileInfo(layerFile); try { Angle[] bbox = CameraBase.getViewBoundingBox(); string viewBBox = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", bbox[0].ToString().TrimEnd('°'), bbox[1].ToString().TrimEnd('°'), bbox[2].ToString().TrimEnd('°'), bbox[3].ToString().TrimEnd('°')); //See if there is a ? already in the URL int flag = redirect.IndexOf("?"); if (flag == -1) redirect = redirect + "?BBOX=" + viewBBox; else redirect = redirect + "&BBOX=" + viewBBox; WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(redirect); string username = iter.Current.GetAttribute("username", ""); if (username != null) { //// download.UserName = username; //// download.Password = password; } FileInfo tempDownloadFile = new FileInfo(layerFile.Replace(layerFileInfo.Extension, "_.tmp")); download.DownloadFile(tempDownloadFile.FullName, WorldWind.Net.DownloadType.Unspecified); tempDownloadFile.Refresh(); if (tempDownloadFile.Exists && tempDownloadFile.Length > 0) { FileInfo tempStoreFile = new FileInfo(tempDownloadFile.FullName.Replace("_.tmp", ".tmp")); if (tempStoreFile.Exists) tempStoreFile.Delete(); tempDownloadFile.MoveTo(tempStoreFile.FullName); } download.Dispose(); using (StreamWriter writer = new StreamWriter(layerFile.Replace(layerFileInfo.Extension, ".uri"), false)) { writer.WriteLine(redirectWithoutBBOX); } } catch (Exception ex) { Log.Write(ex); } return getRenderableFromLayerFile(layerFile.Replace(layerFileInfo.Extension, ".tmp"), parentWorld, cache); } else { RenderableObjectList parentRenderable = null; string sourceUri = null; if (layerFile.EndsWith(".tmp")) { //get source url using (StreamReader reader = new StreamReader(layerFile.Replace(".tmp", ".uri"))) { sourceUri = reader.ReadLine(); } } string refreshString = iter.Current.GetAttribute("Refresh", ""); if (refreshString != null && refreshString.Length > 0) { if (iter.Current.Select("Icon").Count > 0) { parentRenderable = new Icons(iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache); } else { parentRenderable = new RenderableObjectList( iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache); } } else { if (iter.Current.Select("Icon").Count > 0) { parentRenderable = new Icons(iter.Current.GetAttribute("Name", "")); } else { parentRenderable = new RenderableObjectList(iter.Current.GetAttribute("Name", "")); } } parentRenderable.ParentList = parentWorld.RenderableObjects; parentRenderable.IsOn = ParseBool(iter.Current.GetAttribute("ShowAtStartup", "")); string description = getInnerTextFromFirstChild(iter.Current.Select("Description")); if (description != null && description.Length > 0) parentRenderable.Description = description; parentRenderable.ShowOnlyOneLayer = ParseBool(iter.Current.GetAttribute("ShowOnlyOneLayer", "")); parentRenderable.MetaData.Add("XmlSource", (sourceUri != null ? sourceUri : layerFile)); parentRenderable.MetaData.Add("World", parentWorld); parentRenderable.MetaData.Add("Cache", cache); parentRenderable.ParentList = parentWorld.RenderableObjects; string renderPriorityString = iter.Current.GetAttribute("RenderPriority", ""); if (renderPriorityString != null) { if (String.Compare(renderPriorityString, "Icons", false, System.Globalization.CultureInfo.InvariantCulture) == 0) { parentRenderable.RenderPriority = RenderPriority.Icons; } else if (String.Compare(renderPriorityString, "LinePaths", false, System.Globalization.CultureInfo.InvariantCulture) == 0) { parentRenderable.RenderPriority = RenderPriority.LinePaths; } else if (String.Compare(renderPriorityString, "Placenames", false, System.Globalization.CultureInfo.InvariantCulture) == 0) { parentRenderable.RenderPriority = RenderPriority.Placenames; } else if (String.Compare(renderPriorityString, "AtmosphericImages", false, System.Globalization.CultureInfo.InvariantCulture) == 0) { parentRenderable.RenderPriority = RenderPriority.AtmosphericImages; } } string infoUri = iter.Current.GetAttribute("InfoUri", ""); if (infoUri != null && infoUri.Length > 0) { if (parentRenderable.MetaData.Contains("InfoUri")) { parentRenderable.MetaData["InfoUri"] = infoUri; } else { parentRenderable.MetaData.Add("InfoUri", infoUri); } } addTiledWFSPlacenameSet(iter.Current.Select("TiledWFSPlacenameSet"), parentWorld, parentRenderable, cache); addExtendedInformation(iter.Current.Select("ExtendedInformation"), parentRenderable); if (parentRenderable.RefreshTimer != null && enableRefresh) { parentRenderable.RefreshTimer.Start(); } return parentRenderable; } } } catch (Exception ex) { Log.Write(ex); //Log.Write(Log.Levels.Debug, layerFile); } Log.Write(Log.Levels.Warning, "CONF", "WARNING: no renderable created for " + layerFile); return null; }
private void refreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if(isUpdating) return; isUpdating = true; try { for(int i = 0; i < this.ChildObjects.Count; i++) { RenderableObject ro = (RenderableObject)this.ChildObjects[i]; if(ro != null && ro.IsOn && ro is Icon) { Icon icon = (Icon)ro; if(icon.RefreshInterval == TimeSpan.MaxValue || icon.LastRefresh > System.DateTime.Now - icon.RefreshInterval) continue; object key = null; IconTexture iconTexture = null; if(icon.TextureFileName != null && icon.TextureFileName.Length > 0) { if(icon.TextureFileName.ToLower().StartsWith("http://") && icon.SaveFilePath != null) { //download it try { WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(icon.TextureFileName); webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified; System.IO.FileInfo saveFile = new System.IO.FileInfo(icon.SaveFilePath); if(!saveFile.Directory.Exists) saveFile.Directory.Create(); webDownload.DownloadFile(saveFile.FullName); } catch{} iconTexture = (IconTexture)m_textures[icon.SaveFilePath]; if(iconTexture != null) { IconTexture tempTexture = iconTexture; m_textures[icon.SaveFilePath] = new IconTexture( DrawArgs.Device, icon.SaveFilePath ); tempTexture.Dispose(); } else { key = icon.SaveFilePath; iconTexture = new IconTexture( DrawArgs.Device, icon.SaveFilePath ); // New texture, cache it m_textures.Add(key, iconTexture); // Use default dimensions if not set if(icon.Width==0) icon.Width = iconTexture.Width; if(icon.Height==0) icon.Height = iconTexture.Height; } } else { // Icon image from file iconTexture = (IconTexture)m_textures[icon.TextureFileName]; if(iconTexture != null) { IconTexture tempTexture = iconTexture; m_textures[icon.SaveFilePath] = new IconTexture( DrawArgs.Device, icon.TextureFileName ); tempTexture.Dispose(); } else { key = icon.SaveFilePath; iconTexture = new IconTexture( DrawArgs.Device, icon.TextureFileName ); // New texture, cache it m_textures.Add(key, iconTexture); // Use default dimensions if not set if(icon.Width==0) icon.Width = iconTexture.Width; if(icon.Height==0) icon.Height = iconTexture.Height; } } } else { // Icon image from bitmap if(icon.Image != null) { iconTexture = (IconTexture)m_textures[icon.Image]; if(iconTexture != null) { IconTexture tempTexture = iconTexture; m_textures[icon.SaveFilePath] = new IconTexture( DrawArgs.Device, icon.Image ); tempTexture.Dispose(); } else { key = icon.SaveFilePath; iconTexture = new IconTexture( DrawArgs.Device, icon.Image ); // New texture, cache it m_textures.Add(key, iconTexture); // Use default dimensions if not set if(icon.Width==0) icon.Width = iconTexture.Width; if(icon.Height==0) icon.Height = iconTexture.Height; } } } icon.LastRefresh = System.DateTime.Now; } } } catch{} finally { isUpdating = false; } }
public override void Initialize(DrawArgs drawArgs) { if (m_polygonFeature == null) { double offset = 0.02; Point3d[] points = new Point3d[4]; points[0] = new Point3d( m_longitude - offset, m_latitude - offset, 200000); points[1] = new Point3d( m_longitude - offset, m_latitude + offset, 200000); points[2] = new Point3d( m_longitude + offset, m_latitude + offset, 200000); points[3] = new Point3d( m_longitude + offset, m_latitude - offset, 200000); LinearRing outerRing = new LinearRing(); outerRing.Points = points; m_polygonFeature = new PolygonFeature( name, World, outerRing, null, System.Drawing.Color.Chocolate); m_polygonFeature.AltitudeMode = AltitudeMode.Absolute; m_polygonFeature.Extrude = true; m_polygonFeature.Outline = true; m_polygonFeature.OutlineColor = System.Drawing.Color.Chocolate; } FileInfo savedFlagFile = new FileInfo(SavedImagePath); FileInfo placeHolderFile = new FileInfo(SavedImagePath + ".blk"); if (savedFlagFile.Exists) { try { m_texture = ImageHelper.LoadTexture( savedFlagFile.FullName, System.Drawing.Color.Black.ToArgb()); } catch { savedFlagFile.Delete(); savedFlagFile.Refresh(); } } if (!savedFlagFile.Exists && !placeHolderFile.Exists) { if (!savedFlagFile.Directory.Exists) { savedFlagFile.Directory.Create(); } try { // Offline check if (World.Settings.WorkOffline) { throw new Exception("Offline mode active."); } WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri); download.DownloadFile(savedFlagFile.FullName); download.Dispose(); savedFlagFile.Refresh(); } catch { FileStream fs = placeHolderFile.Create(); fs.Close(); fs = null; placeHolderFile.Refresh(); } if (savedFlagFile.Exists) { m_texture = ImageHelper.LoadTexture( savedFlagFile.FullName, System.Drawing.Color.Black.ToArgb()); } } if (m_vertexDeclaration == null) { VertexElement[] velements = new VertexElement[] { new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0), new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0), new VertexElement(0, 24, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), VertexElement.VertexDeclarationEnd }; m_vertexDeclaration = new VertexDeclaration(drawArgs.device, velements); } UpdateVertices(); isInitialized = true; }
public override void Initialize(DrawArgs drawArgs) { if(!isOn) return; if(m_sprite != null) { m_sprite.Dispose(); m_sprite = null; } m_sprite = new Sprite(drawArgs.device); System.TimeSpan smallestRefreshInterval = System.TimeSpan.MaxValue; // Load all textures foreach(RenderableObject ro in m_children) { Icon icon = ro as Icon; if(icon==null) { // Child is not an icon if(ro.IsOn) ro.Initialize(drawArgs); continue; } if(icon.RefreshInterval.TotalMilliseconds != 0 && icon.RefreshInterval != TimeSpan.MaxValue && icon.RefreshInterval < smallestRefreshInterval) smallestRefreshInterval = icon.RefreshInterval; // Child is an icon icon.Initialize(drawArgs); object key = null; IconTexture iconTexture = null; if(icon.TextureFileName != null && icon.TextureFileName.Length > 0) { if(icon.TextureFileName.ToLower().StartsWith("http://") && icon.SaveFilePath != null) { //download it try { WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(icon.TextureFileName); webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified; System.IO.FileInfo saveFile = new System.IO.FileInfo(icon.SaveFilePath); if(!saveFile.Directory.Exists) saveFile.Directory.Create(); webDownload.DownloadFile(saveFile.FullName); } catch{} iconTexture = (IconTexture)m_textures[icon.SaveFilePath]; if(iconTexture==null) { key = icon.SaveFilePath; iconTexture = new IconTexture( drawArgs.device, icon.SaveFilePath ); } } else { // Icon image from file iconTexture = (IconTexture)m_textures[icon.TextureFileName]; if(iconTexture==null) { key = icon.TextureFileName; iconTexture = new IconTexture( drawArgs.device, icon.TextureFileName ); } } } else { // Icon image from bitmap if(icon.Image != null) { iconTexture = (IconTexture)m_textures[icon.Image]; if(iconTexture==null) { // Create new texture from image key = icon.Image; iconTexture = new IconTexture( drawArgs.device, icon.Image); } } } if(iconTexture==null) // No texture set continue; if(key!=null) { // New texture, cache it m_textures.Add(key, iconTexture); // Use default dimensions if not set if(icon.Width==0) icon.Width = iconTexture.Width; if(icon.Height==0) icon.Height = iconTexture.Height; } } // Compute mouse over bounding boxes foreach(RenderableObject ro in m_children) { Icon icon = ro as Icon; if(icon==null) // Child is not an icon continue; if(GetTexture(icon)==null) { // Label only icon.SelectionRectangle = drawArgs.defaultDrawingFont.MeasureString(null, icon.Name, DrawTextFormat.None, 0); } else { // Icon only icon.SelectionRectangle = new Rectangle( 0,0,icon.Width, icon.Height ); } // Center the box at (0,0) icon.SelectionRectangle.Offset(-icon.SelectionRectangle.Width/2, -icon.SelectionRectangle.Height/2 ); } if(refreshTimer == null && smallestRefreshInterval != TimeSpan.MaxValue) { refreshTimer = new System.Timers.Timer(smallestRefreshInterval.TotalMilliseconds); refreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(refreshTimer_Elapsed); refreshTimer.Start(); } isInitialized = true; }
private void m_RefreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { if (isUpdating) return; isUpdating = true; if (m_ImageUri == null) return; if (m_ImageUri.ToLower().StartsWith("http://")) { bool forceDownload = false; if (m_SaveFilePath == null) { // TODO: hack, need to get the correct cache directory m_SaveFilePath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Cache\\PictureBoxImages\\temp"; forceDownload = true; } System.IO.FileInfo saveFile = new System.IO.FileInfo(m_SaveFilePath); if (forceDownload || !saveFile.Exists || (m_RefreshTime > 0 && saveFile.LastWriteTime.Subtract(System.DateTime.Now) > TimeSpan.FromSeconds(m_RefreshTime))) { //download it try { WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(m_ImageUri); webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified; if (!saveFile.Directory.Exists) saveFile.Directory.Create(); webDownload.DownloadFile(m_SaveFilePath); } catch { } } } else { m_SaveFilePath = m_ImageUri; } if (m_ImageTexture != null && !m_ImageTexture.Disposed) { m_ImageTexture.Dispose(); m_ImageTexture = null; } if (!System.IO.File.Exists(m_SaveFilePath)) { displayText = "Image Not Found"; return; } if (LoadAsUncompressed) { m_ImageTexture = TextureLoader.FromFile(DrawArgs.Device, m_SaveFilePath, 0, 0, 1, 0, Format.Unknown, Pool.Managed, Filter.None, Filter.None, 0); } else { m_ImageTexture = ImageHelper.LoadTexture(m_SaveFilePath); } m_surfaceDescription = m_ImageTexture.GetLevelDescription(0); int width = ClientSize.Width; int height = ClientSize.Height; if (ClientSize.Width == 0) { width = m_surfaceDescription.Width; } if (ClientSize.Height == 0) { height = m_surfaceDescription.Height; } if (ParentWidget is Widgets.Form && SizeParentToImage) { Widgets.Form parentForm = (Widgets.Form)ParentWidget; parentForm.ClientSize = new System.Drawing.Size(width, height + parentForm.HeaderHeight); } else if(SizeParentToImage) { ParentWidget.ClientSize = new System.Drawing.Size(width, height); } ClientSize = new System.Drawing.Size(width, height); m_currentImageUri = m_ImageUri; IsLoaded = true; isUpdating = false; displayText = null; if (m_RefreshTime == 0 && m_RefreshTimer.Enabled) m_RefreshTimer.Stop(); } catch (Exception ex) { Log.Write(ex); } }
public override void Initialize(DrawArgs drawArgs) { if (m_polygonFeature == null) { double offset = 0.02; Point3d[] points = new Point3d[4]; points[0] = new Point3d( m_longitude - offset, m_latitude - offset, 200000); points[1] = new Point3d( m_longitude - offset, m_latitude + offset, 200000); points[2] = new Point3d( m_longitude + offset, m_latitude + offset, 200000); points[3] = new Point3d( m_longitude + offset, m_latitude - offset, 200000); LinearRing outerRing = new LinearRing(); outerRing.Points = points; m_polygonFeature = new PolygonFeature( name, World, outerRing, null, System.Drawing.Color.Chocolate); m_polygonFeature.AltitudeMode = AltitudeMode.Absolute; m_polygonFeature.Extrude = true; m_polygonFeature.Outline = true; m_polygonFeature.OutlineColor = System.Drawing.Color.Chocolate; } FileInfo savedFlagFile = new FileInfo(SavedImagePath); FileInfo placeHolderFile = new FileInfo(SavedImagePath + ".blk"); if (savedFlagFile.Exists) { try { m_texture = ImageHelper.LoadTexture( savedFlagFile.FullName, System.Drawing.Color.Black.ToArgb()); } catch { savedFlagFile.Delete(); savedFlagFile.Refresh(); } } if (!savedFlagFile.Exists && !placeHolderFile.Exists) { if (!savedFlagFile.Directory.Exists) { savedFlagFile.Directory.Create(); } try { WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri); download.DownloadFile(savedFlagFile.FullName); download.Dispose(); savedFlagFile.Refresh(); } catch { FileStream fs = placeHolderFile.Create(); fs.Close(); fs = null; placeHolderFile.Refresh(); } if (savedFlagFile.Exists) { m_texture = ImageHelper.LoadTexture( savedFlagFile.FullName, System.Drawing.Color.Black.ToArgb()); } } UpdateVertices(); isInitialized = true; }
public override void Initialize(DrawArgs drawArgs) { if(m_points == null) { isInitialized = true; return; } if(m_imageUri != null) { //load image if(m_imageUri.ToLower().StartsWith("http://")) { string savePath = string.Format("{0}\\image", ConfigurationLoader.GetRenderablePathString(this)); System.IO.FileInfo file = new System.IO.FileInfo(savePath); if(!file.Exists) { WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri); if(!file.Directory.Exists) file.Directory.Create(); download.DownloadFile(file.FullName, WorldWind.Net.DownloadType.Unspecified); } m_texture = ImageHelper.LoadTexture(file.FullName); } else { m_texture = ImageHelper.LoadTexture(m_imageUri); } } UpdateVertices(); isInitialized = true; }
/// <summary> /// Plugin entry point - All plugins must implement this function /// </summary> public override void Load() { FileInfo savedFile = new FileInfo(SavedFilePath); if (!savedFile.Exists) { if (!savedFile.Directory.Exists) savedFile.Directory.Create(); try { WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(DataFileUri); download.DownloadFile(savedFile.FullName); download.Dispose(); } catch { } } m_wavingFlagsList = new RenderableObjectList("Waving Flags"); m_wavingFlagsList.IsOn = false; System.Collections.Hashtable countryHash = new System.Collections.Hashtable(); using (StreamReader reader = savedFile.OpenText()) { string header = reader.ReadLine(); string[] headers = header.Split('\t'); string line = reader.ReadLine(); while (line != null) { System.Collections.Hashtable fieldHash = new System.Collections.Hashtable(); string[] lineParts = line.Split('\t'); //Log.Write(string.Format("{0}\t{1}", lineParts[0], lineParts[1])); try { double latitude = double.Parse(lineParts[3], System.Globalization.CultureInfo.InvariantCulture); double longitude = double.Parse(lineParts[4], System.Globalization.CultureInfo.InvariantCulture); if (lineParts[1].Length == 2) { string flagFileUri = FlagTextureDirectoryUri + "/" + lineParts[1] + FlagSuffix; FileInfo savedFlagFile = new FileInfo(SavedFlagsDirectory + "\\" + lineParts[1] + ".dds"); WavingFlagLayer flag = new WavingFlagLayer( lineParts[0], ParentApplication.WorldWindow.CurrentWorld, latitude, longitude, flagFileUri); flag.SavedImagePath = savedFlagFile.FullName; flag.ScaleX = 100000; flag.ScaleY = 100000; flag.ScaleZ = 100000; flag.Bar3D = new Bar3D(flag.Name, flag.World, latitude, longitude, 0, flag.ScaleZ, System.Drawing.Color.Red); flag.Bar3D.ScaleX = 0.3f * flag.ScaleX; flag.Bar3D.ScaleY = 0.3f * flag.ScaleY; flag.Bar3D.IsOn = false; flag.RenderPriority = RenderPriority.Custom; flag.OnMouseEnterEvent += new EventHandler(flag_OnMouseEnterEvent); flag.OnMouseLeaveEvent += new EventHandler(flag_OnMouseLeaveEvent); flag.OnMouseUpEvent += new System.Windows.Forms.MouseEventHandler(flag_OnMouseUpEvent); m_wavingFlagsList.Add(flag); for (int i = 0; i < lineParts.Length; i++) { try { double value = double.Parse(lineParts[i], System.Globalization.CultureInfo.InvariantCulture); fieldHash.Add(headers[i], value); } catch { fieldHash.Add(headers[i], lineParts[i]); } } countryHash.Add(lineParts[0], fieldHash); } else { //Log.Write(Log.Levels.Debug, "blank: " + lineParts[0]); } } catch(Exception ex) { Log.Write(Log.Levels.Warning, string.Format("Exception: {0} - {1}", lineParts[0], ex.ToString())); } line = reader.ReadLine(); } Headers = headers; } CountryHash = countryHash; InitializeCiaForm(); ParentApplication.WorldWindow.CurrentWorld.RenderableObjects.Add(m_wavingFlagsList); }
/// <summary> /// Plugin entry point - All plugins must implement this function /// </summary> public override void Load() { FileInfo savedFile = new FileInfo(SavedFilePath); if (!savedFile.Exists) { if (!savedFile.Directory.Exists) { savedFile.Directory.Create(); } try { WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(DataFileUri); download.DownloadFile(savedFile.FullName); download.Dispose(); } catch { } } m_wavingFlagsList = new RenderableObjectList("Waving Flags"); m_wavingFlagsList.IsOn = false; System.Collections.Hashtable countryHash = new System.Collections.Hashtable(); using (StreamReader reader = savedFile.OpenText()) { string header = reader.ReadLine(); string[] headers = header.Split('\t'); string line = reader.ReadLine(); while (line != null) { System.Collections.Hashtable fieldHash = new System.Collections.Hashtable(); string[] lineParts = line.Split('\t'); //Log.Write(string.Format("{0}\t{1}", lineParts[0], lineParts[1])); try { double latitude = double.Parse(lineParts[3], System.Globalization.CultureInfo.InvariantCulture); double longitude = double.Parse(lineParts[4], System.Globalization.CultureInfo.InvariantCulture); if (lineParts[1].Length == 2) { string flagFileUri = FlagTextureDirectoryUri + "/" + lineParts[1] + FlagSuffix; FileInfo savedFlagFile = new FileInfo(SavedFlagsDirectory + "\\" + lineParts[1] + ".dds"); WavingFlagLayer flag = new WavingFlagLayer( lineParts[0], ParentApplication.WorldWindow.CurrentWorld, latitude, longitude, flagFileUri); flag.SavedImagePath = savedFlagFile.FullName; flag.ScaleX = 100000; flag.ScaleY = 100000; flag.ScaleZ = 100000; flag.Bar3D = new Bar3D(flag.Name, flag.World, latitude, longitude, 0, flag.ScaleZ, System.Drawing.Color.Red); flag.Bar3D.ScaleX = 0.3f * flag.ScaleX; flag.Bar3D.ScaleY = 0.3f * flag.ScaleY; flag.Bar3D.IsOn = false; flag.RenderPriority = RenderPriority.Custom; flag.OnMouseEnterEvent += new EventHandler(flag_OnMouseEnterEvent); flag.OnMouseLeaveEvent += new EventHandler(flag_OnMouseLeaveEvent); flag.OnMouseUpEvent += new System.Windows.Forms.MouseEventHandler(flag_OnMouseUpEvent); m_wavingFlagsList.Add(flag); for (int i = 0; i < lineParts.Length; i++) { try { double value = double.Parse(lineParts[i], System.Globalization.CultureInfo.InvariantCulture); fieldHash.Add(headers[i], value); } catch { fieldHash.Add(headers[i], lineParts[i]); } } countryHash.Add(lineParts[0], fieldHash); } else { //Log.Write(Log.Levels.Debug, "blank: " + lineParts[0]); } } catch (Exception ex) { Log.Write(Log.Levels.Warning, string.Format("Exception: {0} - {1}", lineParts[0], ex.ToString())); } line = reader.ReadLine(); } Headers = headers; } CountryHash = countryHash; InitializeCiaForm(); ParentApplication.WorldWindow.CurrentWorld.RenderableObjects.Add(m_wavingFlagsList); }
public override void Initialize(DrawArgs drawArgs) { if (m_polygonFeature == null) { double offset = 0.02; Point3d[] points = new Point3d[4]; points[0] = new Point3d( m_longitude - offset, m_latitude - offset, 200000); points[1] = new Point3d( m_longitude - offset, m_latitude + offset, 200000); points[2] = new Point3d( m_longitude + offset, m_latitude + offset, 200000); points[3] = new Point3d( m_longitude + offset, m_latitude - offset, 200000); LinearRing outerRing = new LinearRing(); outerRing.Points = points; m_polygonFeature = new PolygonFeature( name, World, outerRing, null, System.Drawing.Color.Chocolate); m_polygonFeature.AltitudeMode = AltitudeMode.Absolute; m_polygonFeature.Extrude = true; m_polygonFeature.Outline = true; m_polygonFeature.OutlineColor = System.Drawing.Color.Chocolate; } FileInfo savedFlagFile = new FileInfo(SavedImagePath); FileInfo placeHolderFile = new FileInfo(SavedImagePath + ".blk"); if (savedFlagFile.Exists) { try { m_texture = ImageHelper.LoadTexture( savedFlagFile.FullName, System.Drawing.Color.Black.ToArgb()); } catch { savedFlagFile.Delete(); savedFlagFile.Refresh(); } } if (!savedFlagFile.Exists && !placeHolderFile.Exists) { if (!savedFlagFile.Directory.Exists) savedFlagFile.Directory.Create(); try { WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri); download.DownloadFile(savedFlagFile.FullName); download.Dispose(); savedFlagFile.Refresh(); } catch { FileStream fs = placeHolderFile.Create(); fs.Close(); fs = null; placeHolderFile.Refresh(); } if (savedFlagFile.Exists) { m_texture = ImageHelper.LoadTexture( savedFlagFile.FullName, System.Drawing.Color.Black.ToArgb()); } } UpdateVertices(); isInitialized = true; }