internal BlueMarbleBuilder() : base("Blue Marble", MainForm.WorldWindowSingleton, null) { ImageLayer oBaseLayer = new WorldWind.Renderable.ImageLayer( "Blue Marble ImageLayer", MainForm.WorldWindowSingleton.CurrentWorld, 0, String.Format(CultureInfo.InvariantCulture, "{0}\\Data\\Earth\\BmngBathy\\world.topo.bathy.2004{1:D2}.jpg", Path.GetDirectoryName(Application.ExecutablePath), 7), -90, 90, -180, 180, 1.0f, null); WorldWind.NltImageStore imageStore = new WorldWind.NltImageStore(String.Format(CultureInfo.InvariantCulture, "bmng.topo.bathy.2004{0:D2}", 7), "http://worldwind25.arc.nasa.gov/tile/tile.aspx"); imageStore.DataDirectory = null; imageStore.LevelZeroTileSizeDegrees = 36.0; imageStore.LevelCount = 5; imageStore.ImageExtension = "jpg"; imageStore.CacheDirectory = MainForm.WorldWindowSingleton.Cache.CacheDirectory + "\\Earth\\BMNG\\"; WorldWind.ImageStore[] ias = new WorldWind.ImageStore[1]; ias[0] = imageStore; QuadTileSet oTiledBaseLayer = new WorldWind.Renderable.QuadTileSet( "Blue Marble QuadTileSet", MainForm.WorldWindowSingleton.CurrentWorld, 0, 90, -90, -180, 180, true, ias); RenderableObjectList oRenderableList = new RenderableObjectList("This name doesn't matter, it gets rewritten"); oRenderableList.Add(oBaseLayer); oRenderableList.Add(oTiledBaseLayer); oRenderableList.RenderPriority = RenderPriority.TerrainMappedImages; m_hObject = oRenderableList; }
public void Dispose() { m_Initialized = false; m_Disposing = true; if(m_NorthWestChild != null) { m_NorthWestChild.Dispose(); } if(m_NorthEastChild != null) { m_NorthEastChild.Dispose(); } if(m_SouthWestChild != null) { m_SouthWestChild.Dispose(); } if(m_SouthEastChild != null) { m_SouthEastChild.Dispose(); } if(m_NwImageLayer != null) { m_NwImageLayer.Dispose(); m_NwImageLayer = null; } if(m_NeImageLayer != null) { m_NeImageLayer.Dispose(); m_NeImageLayer = null; } if(m_SwImageLayer != null) { m_SwImageLayer.Dispose(); m_SwImageLayer = null; } if(m_SeImageLayer != null) { m_SeImageLayer.Dispose(); m_SeImageLayer = null; } if(m_ImageStream != null) { m_ImageStream.Close(); } if(!m_Initializing) { m_Disposing = false; } }
public void Dispose() { m_Initialized = false; m_Disposing = true; if (m_NorthWestChild != null) { m_NorthWestChild.Dispose(); } if (m_NorthEastChild != null) { m_NorthEastChild.Dispose(); } if (m_SouthWestChild != null) { m_SouthWestChild.Dispose(); } if (m_SouthEastChild != null) { m_SouthEastChild.Dispose(); } if (m_NwImageLayer != null) { m_NwImageLayer.Dispose(); m_NwImageLayer = null; } if (m_NeImageLayer != null) { m_NeImageLayer.Dispose(); m_NeImageLayer = null; } if (m_SwImageLayer != null) { m_SwImageLayer.Dispose(); m_SwImageLayer = null; } if (m_SeImageLayer != null) { m_SeImageLayer.Dispose(); m_SeImageLayer = null; } if (m_ImageStream != null) { m_ImageStream.Close(); } if (!m_Initializing) { m_Disposing = false; } }
public void DownloadImage() { try { this.downloadState = DownloadState.Downloading; this.downloadProgress = 0.0f; if (File.Exists(this.saveTexturePath)) { File.Delete(this.saveTexturePath); } if (!Directory.Exists(Path.GetDirectoryName(this.saveTexturePath))) { Directory.CreateDirectory(Path.GetDirectoryName(this.saveTexturePath)); } using (WebDownload dl = new WebDownload(imageUrl)) { dl.ProgressCallback += new DownloadProgressHandler(UpdateProgress); dl.DownloadMemory(); this.downloadState = DownloadState.Converting; ImageHelper.ConvertToDxt1(dl.ContentStream, saveTexturePath); } if (this.downloadState == DownloadState.Cancelled) { return; } this.IsTextureAvailable = true; if (this.LoadImage) { this.imageLayer = new ImageLayer(this.Name, m_ParentWorld, this.layerRadius - (float)m_ParentWorld.EquatorialRadius, this.saveTexturePath, this.south, this.north, this.west, this.east, 255, /*this.terrainInfo*/ null); } this.downloadState = DownloadState.Pending; } catch (Exception caught) { Log.Write(caught); } }
public bool DownLoadImage(DrawArgs drawArgs) { if (this.imageLayer != null || (this.downloadThread != null && this.downloadThread.IsAlive)) { return(false); } this.LoadImage = true; this.drawArgs = drawArgs; //download the thing... if (!this.IsTextureAvailable) { this.downloadThread = new Thread(new ThreadStart(this.DownloadImage)); this.downloadThread.Name = "DownloadableImageFromIconSet.DownloadImage"; this.downloadThread.IsBackground = true; this.downloadThread.Start(); } else { this.imageLayer = new ImageLayer(this.Name, this.m_ParentWorld, this.layerRadius - (float)m_ParentWorld.EquatorialRadius, this.saveTexturePath, this.south, this.north, this.west, this.east, 255, this._terrainAccessor); } return(true); }
public void Initialize(DrawArgs drawArgs) { try { m_Initializing = true; double centerLatitude = 0.5 * (m_GeoBB.North + m_GeoBB.South); double centerLongitude = 0.5 * (m_GeoBB.West + m_GeoBB.East); m_NwImageLayer = CreateImageLayer(m_GeoBB.North, centerLatitude, m_GeoBB.West, centerLongitude, drawArgs); m_NeImageLayer = CreateImageLayer(m_GeoBB.North, centerLatitude, centerLongitude, m_GeoBB.East, drawArgs); m_SwImageLayer = CreateImageLayer(centerLatitude, m_GeoBB.South, m_GeoBB.West, centerLongitude, drawArgs); m_SeImageLayer = CreateImageLayer(centerLatitude, m_GeoBB.South, centerLongitude, m_GeoBB.East, drawArgs); if(m_NwImageLayer != null) { m_NwImageLayer.Initialize(drawArgs); } if(m_NeImageLayer != null) { m_NeImageLayer.Initialize(drawArgs); } if(m_SwImageLayer != null) { m_SwImageLayer.Initialize(drawArgs); } if(m_SeImageLayer != null) { m_SeImageLayer.Initialize(drawArgs); } } catch(Exception ex) { Log.Write(ex); } finally { m_Initializing = false; if(m_Disposing) { Dispose(); m_Initialized = false; } else { m_Initialized = true; } } }
public void Initialize(DrawArgs drawArgs) { try { m_Initializing = true; double centerLatitude = 0.5 * (m_GeoBB.North + m_GeoBB.South); double centerLongitude = 0.5 * (m_GeoBB.West + m_GeoBB.East); m_NwImageLayer = CreateImageLayer(m_GeoBB.North, centerLatitude, m_GeoBB.West, centerLongitude, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", ShapeTile.CachePath, ConfigurationLoader.GetRenderablePathString(m_ShapeTileArgs.ParentShapeFileLayer), Level + 1, 2 * Row + 1, 2 * Col)); m_NeImageLayer = CreateImageLayer(m_GeoBB.North, centerLatitude, centerLongitude, m_GeoBB.East, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", ShapeTile.CachePath, ConfigurationLoader.GetRenderablePathString(m_ShapeTileArgs.ParentShapeFileLayer), Level + 1, 2 * Row + 1, 2 * Col + 1)); m_SwImageLayer = CreateImageLayer(centerLatitude, m_GeoBB.South, m_GeoBB.West, centerLongitude, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", ShapeTile.CachePath, ConfigurationLoader.GetRenderablePathString(m_ShapeTileArgs.ParentShapeFileLayer), Level + 1, 2 * Row, 2 * Col)); m_SeImageLayer = CreateImageLayer(centerLatitude, m_GeoBB.South, centerLongitude, m_GeoBB.East, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", ShapeTile.CachePath, ConfigurationLoader.GetRenderablePathString(m_ShapeTileArgs.ParentShapeFileLayer), Level + 1, 2 * Row, 2 * Col + 1)); if (m_NwImageLayer != null) { m_NwImageLayer.Initialize(drawArgs); } if (m_NeImageLayer != null) { m_NeImageLayer.Initialize(drawArgs); } if (m_SwImageLayer != null) { m_SwImageLayer.Initialize(drawArgs); } if (m_SeImageLayer != null) { m_SeImageLayer.Initialize(drawArgs); } } catch (Exception ex) { Utility.Log.Write(ex); } finally { m_Initializing = false; if (m_Disposing) { Dispose(); m_Initialized = false; } else { m_Initialized = true; } } }
private void animationTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if(this.isUpdating) return; this.isUpdating = true; if(this.currentAnimatingImages.Count > 0) { if(this.imageLayer == null) { byte opacity = (byte)(255 * ((float)this.trackBar2.Value / this.trackBar2.Maximum)); this.imageLayer = new ImageLayer("NRL, Monterey -- \"Real-Time\" Weather", m_WorldWindow.CurrentWorld, 30000.0f, Path.Combine( this.m_CacheDirectory, ((string)this.currentAnimatingImages[0]) ), (float)this.currentAnimatingDataSet.South, (float)this.currentAnimatingDataSet.North, (float)this.currentAnimatingDataSet.West, (float)this.currentAnimatingDataSet.East, opacity, null); this.imageLayer.IsOn = true; m_WorldWindow.CurrentWorld.RenderableObjects.Add(this.imageLayer); } else if(this.currentAnimatingImages.Count != 1) { this.imageLayer.UpdateTexture( Path.Combine( this.m_CacheDirectory, ((string)this.currentAnimatingImages[currentFrame]))); this.currentFrame++; if(this.currentFrame >= this.currentAnimatingImages.Count) { System.Threading.Thread.Sleep(1000); this.currentFrame = 0; } } } this.isUpdating = false; }
public override void Initialize(WorldWind.DrawArgs drawArgs) { lock (this) { m_oLastAoI = drawArgs.CurrentRoI; m_oLastAoIChangeTime = DateTime.Now; if (m_oGroundOverlay.Icon.ViewRefreshMode == KMLViewRefreshMode.onStop) { GeographicBoundingBox oRenderBox = GetNewBox(drawArgs.CurrentRoI, m_oGroundOverlay.Icon.ViewBoundScale); m_oLayer = new ImageLayer( m_oGroundOverlay.Name, drawArgs.CurrentWorld, m_oGroundOverlay.Altitude, m_strImageFilename, oRenderBox.South, oRenderBox.North, oRenderBox.West, oRenderBox.East, (byte)(m_oGroundOverlay.Color.A * ((double)m_opacity / (double)(byte.MaxValue))), drawArgs.CurrentWorld.TerrainAccessor); if (m_oGroundOverlay.Icon.IsLocalFile) { m_oLayer.ImagePath = Path.Combine(m_strKMLDirectory, m_oGroundOverlay.Icon.HRef); } else { m_oLayer.ImageUrl = m_oGroundOverlay.Icon.GetUri(oRenderBox.West, oRenderBox.South, oRenderBox.East, oRenderBox.North); } m_oLayerAoI = drawArgs.CurrentRoI.Clone() as GeographicBoundingBox; } else { m_oLayer = new ImageLayer( m_oGroundOverlay.Name, drawArgs.CurrentWorld, m_oGroundOverlay.Altitude, m_strImageFilename, m_oGroundOverlay.LatLonBox.South, m_oGroundOverlay.LatLonBox.North, m_oGroundOverlay.LatLonBox.West, m_oGroundOverlay.LatLonBox.East, (byte)(m_oGroundOverlay.Color.A * ((double)m_opacity / (double)(byte.MaxValue))), drawArgs.CurrentWorld.TerrainAccessor); if (m_oGroundOverlay.Icon.IsLocalFile) { m_oLayer.ImagePath = Path.Combine(m_strKMLDirectory, m_oGroundOverlay.Icon.HRef); } else { m_oLayer.ImageUrl = m_oGroundOverlay.GetUri(); } } m_oLayer.Initialize(drawArgs); } }
private void ProcessWmsEncodedUri() { //first parse the rawUri string looking for "functions" string uri = worldWindUri.RawUrl.Substring(12, worldWindUri.RawUrl.Length - 12); uri = uri.Replace("wmsimage=", "wmsimage|"); uri = uri.Replace("&wmsimage", "#wmsimage"); string[] uriFunctions = uri.Split('#'); foreach(string uriFunction in uriFunctions) { string[] paramValuePair = uriFunction.Split('|'); if(String.Compare(paramValuePair[0], "wmsimage", true, CultureInfo.InvariantCulture) == 0) { string displayName = null; int transparencyPercent = 0; double heightAboveSurface = 0.0; string wmslink = ""; string[] wmsImageParams = new string[0]; if(paramValuePair[1].IndexOf("://") > 0) { wmsImageParams = paramValuePair[1].Replace("%26", "|").Split('|'); } else { wmsImageParams = System.Web.HttpUtility.UrlDecode(paramValuePair[1]).Replace("%26", "|").Split('|'); } foreach(string p in wmsImageParams) { string new_p = p.Replace("%3d", "|"); char[] deliminator = new char[1] {'|'}; string[] functionParam = new_p.Split(deliminator, 2); if(String.Compare(functionParam[0], "displayname", true, CultureInfo.InvariantCulture) == 0) { displayName = functionParam[1]; } else if(String.Compare(functionParam[0], "transparency", true, CultureInfo.InvariantCulture) == 0) { transparencyPercent = Int32.Parse(functionParam[1], CultureInfo.InvariantCulture); } else if(String.Compare(functionParam[0], "altitude", true, CultureInfo.InvariantCulture) == 0) { heightAboveSurface = Double.Parse(functionParam[1], CultureInfo.InvariantCulture); } else if(String.Compare(functionParam[0], "link", true, CultureInfo.InvariantCulture) == 0) { wmslink = functionParam[1]; if(wmslink.EndsWith("/")) wmslink = wmslink.Substring(0, wmslink.Length - 1); } } try { string[] wmslinkParams = wmslink.Split('?')[1].Split('&'); string wmsLayerName = null; LayerSet.Type_LatitudeCoordinate2 bb_north = new LayerSet.Type_LatitudeCoordinate2(); LayerSet.Type_LatitudeCoordinate2 bb_south = new LayerSet.Type_LatitudeCoordinate2(); LayerSet.Type_LongitudeCoordinate2 bb_west = new LayerSet.Type_LongitudeCoordinate2(); LayerSet.Type_LongitudeCoordinate2 bb_east = new LayerSet.Type_LongitudeCoordinate2(); foreach(string wmslinkParam in wmslinkParams) { string linkParamUpper = wmslinkParam.ToUpper(CultureInfo.InvariantCulture); if(linkParamUpper.IndexOf("BBOX") >= 0) { string[] bb_parts = wmslinkParam.Split('=')[1].Split(','); bb_west.AddValue2(new LayerSet.ValueType4(bb_parts[0])); bb_south.AddValue2(new LayerSet.ValueType3(bb_parts[1])); bb_east.AddValue2(new LayerSet.ValueType4(bb_parts[2])); bb_north.AddValue2(new LayerSet.ValueType3(bb_parts[3])); } else if(linkParamUpper.IndexOf("LAYERS") >= 0) { wmsLayerName = wmslinkParam.Split('=')[1]; } } string path = String.Format(CultureInfo.InvariantCulture, @"{0}\{1}\___DownloadedWMSImages.xml", Settings.ConfigPath, "");//this.currentWorld.LayerDirectory.Value); string texturePath = string.Format(CultureInfo.InvariantCulture, @"{0}\Data\DownloadedWMSImages\{1}", DirectoryPath, System.DateTime.Now.ToFileTimeUtc()); if(!File.Exists(path)) { LayerSet.LayerSetDoc newDoc = new LayerSet.LayerSetDoc(); LayerSet.Type_LayerSet root = new LayerSet.Type_LayerSet(); root.AddName(new LayerSet.NameType2("Downloaded WMS Images")); root.AddShowAtStartup(new Altova.Types.SchemaBoolean(true)); root.AddShowOnlyOneLayer(new Altova.Types.SchemaBoolean(false)); newDoc.SetRootElementName("", "LayerSet"); newDoc.Save(path, root); } LayerSet.LayerSetDoc doc = new LayerSet.LayerSetDoc(); LayerSet.Type_LayerSet curRoot = new LayerSet.Type_LayerSet(doc.Load(path)); if(displayName == null) { displayName = wmslink.Split('?')[0] + " - " + wmsLayerName + " : " + System.DateTime.Now.ToShortDateString() + " " + System.DateTime.Now.ToLongTimeString(); } for(int i = 0; i < curRoot.ImageLayerCount; i++) { LayerSet.Type_ImageLayer curImageLayerType = (LayerSet.Type_ImageLayer)curRoot.GetImageLayerAt(i); if(curImageLayerType.Name.Value.Equals(displayName)) { displayName += String.Format(CultureInfo.CurrentCulture, " : {0} {1}", System.DateTime.Now.ToShortDateString(), System.DateTime.Now.ToLongTimeString()); } } LayerSet.Type_ImageLayer newImageLayer = new LayerSet.Type_ImageLayer(); newImageLayer.AddShowAtStartup(new Altova.Types.SchemaBoolean(false)); if(bb_north.Value2.DoubleValue() - bb_south.Value2.DoubleValue() > 90 || bb_east.Value2.DoubleValue() - bb_west.Value2.DoubleValue() > 90) heightAboveSurface = 10000.0; newImageLayer.AddName(new LayerSet.NameType( displayName)); newImageLayer.AddDistanceAboveSurface( new Altova.Types.SchemaDecimal(heightAboveSurface)); LayerSet.Type_LatLonBoundingBox2 bb = new LayerSet.Type_LatLonBoundingBox2(); bb.AddNorth(bb_north); bb.AddSouth(bb_south); bb.AddWest(bb_west); bb.AddEast(bb_east); newImageLayer.AddBoundingBox(bb); newImageLayer.AddTexturePath(new Altova.Types.SchemaString( texturePath)); byte opacityValue = (byte)((100.0 - transparencyPercent) * 0.01 * 255); newImageLayer.AddOpacity(new LayerSet.OpacityType( opacityValue.ToString(CultureInfo.InvariantCulture))); newImageLayer.AddTerrainMapped(new Altova.Types.SchemaBoolean(false)); curRoot.AddImageLayer(newImageLayer); doc.Save(path, curRoot); ImageLayer newLayer = new ImageLayer( displayName, this.worldWindow.CurrentWorld, (float)heightAboveSurface, texturePath, (float)bb_south.Value2.DoubleValue(), (float)bb_north.Value2.DoubleValue(), (float)bb_west.Value2.DoubleValue(), (float)bb_east.Value2.DoubleValue(), 0.01f * (100.0f - transparencyPercent), this.worldWindow.CurrentWorld.TerrainAccessor); newLayer.ImageUrl = wmslink; RenderableObjectList downloadedImagesRol = (RenderableObjectList)this.worldWindow.CurrentWorld.RenderableObjects.GetObject("Downloaded WMS Images"); if(downloadedImagesRol == null) downloadedImagesRol = new RenderableObjectList("Downloaded WMS Images"); this.worldWindow.CurrentWorld.RenderableObjects.Add(newLayer); worldWindUri.Latitude = Angle.FromDegrees(0.5 * (bb_north.Value2.DoubleValue() + bb_south.Value2.DoubleValue())); worldWindUri.Longitude = Angle.FromDegrees(0.5 * (bb_west.Value2.DoubleValue() + bb_east.Value2.DoubleValue())); if(bb_north.Value2.DoubleValue() - bb_south.Value2.DoubleValue() > bb_east.Value2.DoubleValue() - bb_west.Value2.DoubleValue()) worldWindUri.ViewRange = Angle.FromDegrees(bb_north.Value2.DoubleValue() - bb_south.Value2.DoubleValue()); else worldWindUri.ViewRange = Angle.FromDegrees(bb_east.Value2.DoubleValue() - bb_west.Value2.DoubleValue()); if(worldWindUri.ViewRange.Degrees > 180) worldWindUri.ViewRange = Angle.FromDegrees(180); System.Threading.Thread.Sleep(10); } catch {} } } }
private void displayFrame(int frameNumber) { WMSDownload curFrame = null; lock(this.animationFrames.SyncRoot) { if (this.animationFrames.Count<=0) return; if (frameNumber>=this.animationFrames.Count) frameNumber = 0; if (frameNumber<0) frameNumber = this.animationFrames.Count-1; this.currentAnimationFrame = frameNumber; curFrame = (WMSDownload)this.animationFrames[frameNumber]; } if(curFrame != null && File.Exists(curFrame.SavedFilePath)) { if(this.imageLayer == null) { byte opacity = (byte)(255 * ((float)this.trackBarOpacity.Value / this.trackBarOpacity.Maximum)); this.imageLayer = new ImageLayer("NASA SVS", this.worldWindow.CurrentWorld, 10000.0f, curFrame.SavedFilePath, (float)curFrame.South, (float)curFrame.North, (float)curFrame.West, (float)curFrame.East, opacity, null); this.imageLayer.IsOn = true; //this.imageLayer.DisableZBuffer = true; this.imageLayer.Initialize(this.worldWindow.DrawArgs); this.worldWindow.CurrentWorld.RenderableObjects.Add(this.imageLayer); } else { this.imageLayer.UpdateTexture(curFrame.SavedFilePath); } this.worldWindow.Caption = curFrame.Title + "\n" + curFrame.Date; this.worldWindow.Invalidate(); UpdateProgressBarFrame( this.animationFrames.Count == 1 ? 1 : frameNumber, progressBarFrame.Maximum); } }
public void DownloadImage() { try { this.downloadState = DownloadState.Downloading; this.downloadProgress = 0.0f; if(File.Exists(this.saveTexturePath)) File.Delete(this.saveTexturePath); if(!Directory.Exists(Path.GetDirectoryName(this.saveTexturePath))) Directory.CreateDirectory(Path.GetDirectoryName(this.saveTexturePath)); using( WebDownload dl = new WebDownload(imageUrl)) { dl.ProgressCallback += new DownloadProgressHandler(UpdateProgress); dl.DownloadMemory(); this.downloadState = DownloadState.Converting; ImageHelper.ConvertToDxt1(dl.ContentStream, saveTexturePath); } if(this.downloadState == DownloadState.Cancelled) return; this.IsTextureAvailable = true; if(this.LoadImage) { this.imageLayer = new ImageLayer(this.Name, m_ParentWorld, this.layerRadius - (float)m_ParentWorld.EquatorialRadius, this.saveTexturePath, this.south, this.north, this.west, this.east, 255, /*this.terrainInfo*/null); } this.downloadState = DownloadState.Pending; } catch(Exception caught) { Log.Write( caught ); } }
public bool DownLoadImage(DrawArgs drawArgs) { if(this.imageLayer != null || (this.downloadThread != null && this.downloadThread.IsAlive)) return false; this.LoadImage = true; this.drawArgs = drawArgs; //download the thing... if(!this.IsTextureAvailable) { this.downloadThread = new Thread(new ThreadStart(this.DownloadImage)); this.downloadThread.Name = "DownloadableImageFromIconSet.DownloadImage"; this.downloadThread.IsBackground = true; this.downloadThread.Start(); } else { this.imageLayer = new ImageLayer(this.Name, this.m_ParentWorld, this.layerRadius - (float)m_ParentWorld.EquatorialRadius, this.saveTexturePath, this.south, this.north, this.west, this.east, 255, this._terrainAccessor); } return true; }
protected override void CleanUpLayer(bool bFinal) { if (m_Layer != null) m_Layer.Dispose(); if (File.Exists(m_strCacheFileName)) File.Delete(m_strCacheFileName); if (bFinal && m_bIsTmp && File.Exists(m_strFileName)) File.Delete(m_strFileName); m_Layer = null; m_blnIsChanged = true; }
internal override RenderableObject GetLayer() { if (m_blnIsChanged) { try { GeographicBoundingBox extents = GeorefImageLayerBuilder.GetExtentsFromGeotif(m_strFileName); if (extents != null) { // Convert Geotif right here to save lockup in update thread due to slow GDI+ to DirectX texture stream if (!File.Exists(m_strCacheFileName) || File.GetLastWriteTime(m_strCacheFileName) < File.GetLastWriteTime(m_strFileName)) { using (Image img = Image.FromFile(m_strFileName)) { Directory.CreateDirectory(Path.GetDirectoryName(m_strCacheFileName)); img.Save(m_strCacheFileName, System.Drawing.Imaging.ImageFormat.Png); } } m_Layer = new ImageLayer(m_szTreeNodeText, m_oWorldWindow.CurrentWorld, 0.0, m_strCacheFileName, extents.South, extents.North, extents.West, extents.East, m_bOpacity, m_oWorldWindow.CurrentWorld.TerrainAccessor); m_Layer.IsOn = m_IsOn; m_Layer.Opacity = m_bOpacity; m_Layer.RenderPriority = RenderPriority.TerrainMappedImages; } } catch { if (File.Exists(m_strCacheFileName)) File.Delete(m_strCacheFileName); m_Layer = null; } m_blnIsChanged = false; } return m_Layer; }
private void displayFrame(int frameNumber) { ImageLayerInfo imageLayerInfo = null; lock(this.animationFrames.SyncRoot) { if(this.animationFrames.Count<=0) return; if(frameNumber<0) frameNumber = this.animationFrames.Count+frameNumber; if(frameNumber>=this.animationFrames.Count) frameNumber = frameNumber % this.animationFrames.Count; imageLayerInfo = this.animationFrames[frameNumber] as ImageLayerInfo; if(imageLayerInfo == null) return; if(this.imageLayer == null) { this.imageLayer = new ImageLayer(this.Text, this.worldWindow.CurrentWorld, 1000.0f * (float)this.numericUpDownHeight.Value, imageLayerInfo.ImageFilePath, imageLayerInfo.South, imageLayerInfo.North, imageLayerInfo.West, imageLayerInfo.East, (float)this.numericUpDownTransparency.Value * 0.01f, null); this.imageLayer.RenderPriority = RenderPriority.AtmosphericImages; this.imageLayer.IsOn = true; this.worldWindow.CurrentWorld.RenderableObjects.Add(this.imageLayer); } else { this.imageLayer.UpdateTexture(imageLayerInfo.ImageFilePath); } } this.worldWindow.Caption = imageLayerInfo.Description; }
public void Reset() { lock(this.downloadQueue.SyncRoot) this.downloadQueue.Clear(); StopDownloadThread(); this.animationTimer.Stop(); lock(this.animationFrames.SyncRoot) { this.animationFrames.Clear(); } if(this.imageLayer != null) { this.worldWindow.CurrentWorld.RenderableObjects.Remove(this.imageLayer.Name); this.worldWindow.Invalidate(); this.imageLayer.Dispose(); this.imageLayer = null; } UpdateStatusBar( "" ); if(this.colorbar != null) { this.colorbar.Visible = false; this.colorbar.Dispose(); this.colorbar = null; } bool isAnim = false; MyWMSLayer curLayer = this.getCurrentlySelectedWMSLayer(); if(curLayer != null) { if(curLayer.Width != 0 || curLayer.Height != 0) this.groupBoxExtents.Enabled = false; else this.groupBoxExtents.Enabled = true; isAnim = curLayer.Dates != null; } foreach(Control cntrl in this.tabPageAnimation.Controls) cntrl.Enabled = isAnim; this.animationState = AnimationState.Stop; this.buttonPlay.ImageIndex = 4; this.worldWindow.Caption = ""; }
/// <summary> /// Stops the animation playback. /// </summary> public void StopAnimation() { if(this.animationState==AnimationState.Pending) return; if(this.currentlyAnimatingNode != null) this.currentlyAnimatingNode.ForeColor = this.treeViewLayers.ForeColor; this.currentlyAnimatingNode = null; this.animationState = AnimationState.Pending; this.animationTimer.Enabled = false; StopDownloadThread(); updateCurrentProgressBar(0,1); lock(this.downloadQueue.SyncRoot) this.downloadQueue.Clear(); this.downloadState = DownloadState.Pending; lock(this.animationFrames.SyncRoot) this.animationFrames.Clear(); this.currentAnimationFrame = 0; if(this.imageLayer != null) { this.worldWindow.CurrentWorld.RenderableObjects.Remove(this.imageLayer.Name); this.imageLayer.Dispose(); this.imageLayer = null; } this.worldWindow.Caption = ""; UpdateProgressBarFrame(0,1); this.buttonPlay.ImageIndex = 4; this.CurrentFrameInterval = startFrameInterval; this.buttonColorBar.Enabled = false; if(this.colorbar != null) { this.colorbar.Visible = false; this.colorbar.Dispose(); this.colorbar = null; } SetCaption( "" ); updateStatusBar("Stopped."); }
private void animationTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { if(this.animationState != AnimationState.Pending && this.animationState != AnimationState.Paused && !this.isRendering) { this.isRendering = true; lock(this.animationFrames.SyncRoot) { if(this.animationState == AnimationState.PlayingForward) this.currentAnimationFrame++; else this.currentAnimationFrame--; this.displayFrame(this.currentAnimationFrame); } } } catch(Exception caught) { Log.Write(caught); if(this.imageLayer != null) { this.worldWindow.CurrentWorld.RenderableObjects.Remove(this.imageLayer.Name); this.imageLayer = null; } } this.isRendering = false; }
private static void addImageLayersFromXPathNodeIterator(XPathNodeIterator iter, World parentWorld, RenderableObjectList parentRenderable) { if(iter.Count > 0) { while(iter.MoveNext()) { string name = getInnerTextFromFirstChild(iter.Current.Select("Name")); double distanceAboveSurface = ParseDouble(getInnerTextFromFirstChild(iter.Current.Select("DistanceAboveSurface"))); string texturePath = getInnerTextFromFirstChild(iter.Current.Select("TexturePath")); byte opacity = byte.Parse(getInnerTextFromFirstChild(iter.Current.Select("Opacity"))); TimeSpan dataExpiration = getCacheExpiration(iter.Current.Select("CacheExpirationTime")); string imageUrl = null; if(texturePath.StartsWith("http://")) { imageUrl = texturePath; texturePath = null; } XPathNodeIterator boundingBoxIter = iter.Current.Select("BoundingBox"); if(boundingBoxIter.Count > 0) { boundingBoxIter.MoveNext(); double north = ParseDouble(getInnerTextFromFirstChild(boundingBoxIter.Current.Select("North"))); double south = ParseDouble(getInnerTextFromFirstChild(boundingBoxIter.Current.Select("South"))); double west = ParseDouble(getInnerTextFromFirstChild(boundingBoxIter.Current.Select("West"))); double east = ParseDouble(getInnerTextFromFirstChild(boundingBoxIter.Current.Select("East"))); ImageLayer im = new ImageLayer( name, parentWorld, distanceAboveSurface, texturePath, south, north, west, east, opacity, parentWorld.TerrainAccessor); im.ImageUrl = imageUrl; im.CacheExpiration = dataExpiration; string description = getInnerTextFromFirstChild(iter.Current.Select("Description")); if(description != null && description.Length > 0) im.Description = description; addExtendedInformation(iter.Current.Select("ExtendedInformation"), im); string infoUri = iter.Current.GetAttribute("InfoUri", ""); if(infoUri != null && infoUri.Length > 0) { if(im.MetaData.Contains("InfoUri")) { im.MetaData["InfoUri"] = infoUri; } else { im.MetaData.Add("InfoUri", infoUri); } } im.MetaData.Add("XmlSource", (string)parentRenderable.MetaData["XmlSource"]); im.ParentList = parentRenderable; if(World.Settings.useDefaultLayerStates) { im.IsOn = ParseBool(iter.Current.GetAttribute("ShowAtStartup", "")); } else { im.IsOn = IsLayerOn(im); } parentRenderable.ChildObjects.Add( im ); } } } }
protected override void OnClosing(CancelEventArgs e) { e.Cancel = true; this.Visible = false; if(this.curSelectedDataSet == null) return; this.currentImageList.Clear(); this.currentAnimatingImages.Clear(); if(this.imageLayer != null) { m_WorldWindow.CurrentWorld.RenderableObjects.Remove(this.imageLayer.Name); this.imageLayer.Dispose(); this.imageLayer = null; } if(this.buttonLoad.Text == "Cancel") { this.buttonLoad.Text = "Load"; } m_WorldWindow.Focus(); base.OnClosing (e); }
/*public byte Opacity * { * get * { * return m_parentProjectedLayer.Opacity; * } * set * { * if(m_NwImageLayer != null) * { * m_NwImageLayer.Opacity = value; * } * if(m_NeImageLayer != null) * { * m_NeImageLayer.Opacity = value; * } * if(m_SwImageLayer != null) * { * m_SwImageLayer.Opacity = value; * } * if(m_SeImageLayer != null) * { * m_SeImageLayer.Opacity = value; * } * * if(m_NorthWestChild != null) * { * m_NorthWestChild.Opacity = value; * } * if(m_NorthEastChild != null) * { * m_NorthEastChild.Opacity = value; * } * if(m_SouthWestChild != null) * { * m_SouthWestChild.Opacity = value; * } * if(m_SouthEastChild != null) * { * m_SouthEastChild.Opacity = value; * } * } * }*/ private Renderable.ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs, string imagePath) { Bitmap b = null; Graphics g = null; Renderable.ImageLayer imageLayer = null; GeographicBoundingBox geoBB = new GeographicBoundingBox(north, south, west, east); int numberPolygonsInTile = 0; FileInfo imageFile = new FileInfo(imagePath); if (!m_parentProjectedLayer.EnableCaching || !imageFile.Exists ) { if (m_parentProjectedLayer.LineStrings != null) { for (int i = 0; i < m_parentProjectedLayer.LineStrings.Length; i++) { if (!m_parentProjectedLayer.LineStrings[i].Visible) { continue; } GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.LineStrings[i].GetGeographicBoundingBox(); if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB)) { continue; } else { if (b == null) { b = new Bitmap( m_parentProjectedLayer.TileSize.Width, m_parentProjectedLayer.TileSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } if (g == null) { g = Graphics.FromImage(b); } drawLineString( m_parentProjectedLayer.LineStrings[i], g, geoBB, b.Size ); numberPolygonsInTile++; } } } if (m_parentProjectedLayer.Polygons != null) { for (int i = 0; i < m_parentProjectedLayer.Polygons.Length; i++) { if (!m_parentProjectedLayer.Polygons[i].Visible) { continue; } GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.Polygons[i].GetGeographicBoundingBox(); if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB)) { continue; } else { if (b == null) { b = new Bitmap( m_parentProjectedLayer.TileSize.Width, m_parentProjectedLayer.TileSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } if (g == null) { g = Graphics.FromImage(b); } drawPolygon( m_parentProjectedLayer.Polygons[i], g, geoBB, b.Size); numberPolygonsInTile++; } } } } if (b != null) { System.Drawing.Imaging.BitmapData srcInfo = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); bool isBlank = true; unsafe { int *srcPointer = (int *)srcInfo.Scan0; for (int i = 0; i < b.Height; i++) { for (int j = 0; j < b.Width; j++) { int color = *srcPointer++; if (((color >> 24) & 0xff) > 0) { isBlank = false; break; } } srcPointer += (srcInfo.Stride >> 2) - b.Width; } } b.UnlockBits(srcInfo); if (isBlank) { numberPolygonsInTile = 0; } } // if(!m_parentProjectedLayer.EnableCaching) // { string id = System.DateTime.Now.Ticks.ToString(); if (b != null && numberPolygonsInTile > 0) { MemoryStream ms = new MemoryStream(); b.Save(ms, System.Drawing.Imaging.ImageFormat.Png); //must copy original stream into new stream, if not, error occurs, not sure why m_ImageStream = new MemoryStream(ms.GetBuffer()); imageLayer = new WorldWind.Renderable.ImageLayer( id, m_parentProjectedLayer.World, 0, m_ImageStream, System.Drawing.Color.Black.ToArgb(), (float)south, (float)north, (float)west, (float)east, 1.0f //(float)m_parentProjectedLayer.Opacity / 255.0f , m_parentProjectedLayer.World.TerrainAccessor); ms.Close(); } /* } * else if(imageFile.Exists || numberPolygonsInTile > 0) * { * string id = System.DateTime.Now.Ticks.ToString(); * * if(b != null) * { * MemoryStream ms = new MemoryStream(); * b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); * if(!imageFile.Directory.Exists) * imageFile.Directory.Create(); * * //must copy original stream into new stream, if not, error occurs, not sure why * m_ImageStream = new MemoryStream(ms.GetBuffer()); * ImageHelper.ConvertToDxt3(m_ImageStream, imageFile.FullName); * * ms.Close(); * } * * imageLayer = new WorldWind.Renderable.ImageLayer( * id, * m_parentProjectedLayer.World, * 0, * imageFile.FullName, * //System.Drawing.Color.Black.ToArgb(), * (float)south, * (float)north, * (float)west, * (float)east, * 1.0f,//(float)m_parentProjectedLayer.Opacity / 255.0f, * m_parentProjectedLayer.World.TerrainAccessor); * * imageLayer.TransparentColor = System.Drawing.Color.Black.ToArgb(); * } */ if (b != null) { b.Dispose(); } if (g != null) { g.Dispose(); } b = null; g = null; //might not be necessary //GC.Collect(); return(imageLayer); }
private void UpdateImageLayers(DrawArgs drawArgs) { try { m_LastUpdate = System.DateTime.Now; if(m_NwImageLayer != null) m_NwImageLayer.Dispose(); if(m_NeImageLayer != null) m_NeImageLayer.Dispose(); if(m_SwImageLayer != null) m_SwImageLayer.Dispose(); if(m_SeImageLayer != null) m_SeImageLayer.Dispose(); double centerLatitude = 0.5 * (m_geographicBoundingBox.North + m_geographicBoundingBox.South); double centerLongitude = 0.5 * (m_geographicBoundingBox.West + m_geographicBoundingBox.East); m_NwImageLayer = CreateImageLayer(m_geographicBoundingBox.North, centerLatitude, m_geographicBoundingBox.West, centerLongitude, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", null,//ShapeTile.CachePath, "R",//ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer), Level + 1, 2 * Row + 1, 2 * Col)); m_NeImageLayer = CreateImageLayer(m_geographicBoundingBox.North, centerLatitude, centerLongitude, m_geographicBoundingBox.East, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", null,//ShapeTile.CachePath, "R",//ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer), Level + 1, 2 * Row + 1, 2 * Col + 1)); m_SwImageLayer = CreateImageLayer(centerLatitude, m_geographicBoundingBox.South, m_geographicBoundingBox.West, centerLongitude, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", null,//ShapeTile.CachePath, "R",//ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer), Level + 1, 2 * Row, 2 * Col)); m_SeImageLayer = CreateImageLayer(centerLatitude, m_geographicBoundingBox.South, centerLongitude, m_geographicBoundingBox.East, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", null,//ShapeTile.CachePath, "R",//ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer), Level + 1, 2 * Row, 2 * Col + 1)); if(m_NwImageLayer != null) { m_NwImageLayer.Initialize(drawArgs); } if(m_NeImageLayer != null) { m_NeImageLayer.Initialize(drawArgs); } if(m_SwImageLayer != null) { m_SwImageLayer.Initialize(drawArgs); } if(m_SeImageLayer != null) { m_SeImageLayer.Initialize(drawArgs); } } catch(Exception ex) { Log.Write(ex); } }
public void Initialize(DrawArgs drawArgs) { try { m_Initializing = true; double centerLatitude = 0.5*(m_GeoBB.North + m_GeoBB.South); double centerLongitude = 0.5*(m_GeoBB.West + m_GeoBB.East); m_NwImageLayer = CreateImageLayer(m_GeoBB.North, centerLatitude, m_GeoBB.West, centerLongitude, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", CachePath, ConfigurationLoader.GetRenderablePathString(m_ShapeTileArgs.ParentShapeFileLayer), Level + 1, 2*Row + 1, 2*Col)); m_NeImageLayer = CreateImageLayer(m_GeoBB.North, centerLatitude, centerLongitude, m_GeoBB.East, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", CachePath, ConfigurationLoader.GetRenderablePathString(m_ShapeTileArgs.ParentShapeFileLayer), Level + 1, 2*Row + 1, 2*Col + 1)); m_SwImageLayer = CreateImageLayer(centerLatitude, m_GeoBB.South, m_GeoBB.West, centerLongitude, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", CachePath, ConfigurationLoader.GetRenderablePathString(m_ShapeTileArgs.ParentShapeFileLayer), Level + 1, 2*Row, 2*Col)); m_SeImageLayer = CreateImageLayer(centerLatitude, m_GeoBB.South, centerLongitude, m_GeoBB.East, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", CachePath, ConfigurationLoader.GetRenderablePathString(m_ShapeTileArgs.ParentShapeFileLayer), Level + 1, 2*Row, 2*Col + 1)); if (m_NwImageLayer != null) { m_NwImageLayer.Initialize(drawArgs); } if (m_NeImageLayer != null) { m_NeImageLayer.Initialize(drawArgs); } if (m_SwImageLayer != null) { m_SwImageLayer.Initialize(drawArgs); } if (m_SeImageLayer != null) { m_SeImageLayer.Initialize(drawArgs); } } catch (Exception ex) { Log.Write(ex); } finally { m_Initializing = false; if (m_Disposing) { Dispose(); m_Initialized = false; } else { m_Initialized = true; } } }
private RenderableObject getRenderableObjectListFromLayerSet(World curWorld, LayerSet.Type_LayerSet curLayerSet, string layerSetFile)//ref TreeNode treeNode) { RenderableObjectList rol = null; // If the layer set has icons, use the icon list layer as parent if(curLayerSet.HasIcon()) { rol = new Icons(curLayerSet.Name.Value); rol.RenderPriority = RenderPriority.Icons; } else rol = new RenderableObjectList(curLayerSet.Name.Value); if(curLayerSet.HasShowOnlyOneLayer()) rol.ShowOnlyOneLayer = curLayerSet.ShowOnlyOneLayer.Value; // HACK: This should be part of the settings if(curLayerSet.Name.ToString().ToUpper(System.Globalization.CultureInfo.InvariantCulture)=="PLACENAMES") rol.RenderPriority = RenderPriority.Placenames; if(curLayerSet.HasExtendedInformation()) { if(curLayerSet.ExtendedInformation.HasToolBarImage()) rol.MetaData.Add("ToolBarImagePath", curLayerSet.ExtendedInformation.ToolBarImage.Value); } if(curLayerSet.HasImageLayer()) { for(int i = 0; i < curLayerSet.ImageLayerCount; i++) { LayerSet.Type_ImageLayer curImageLayerType = curLayerSet.GetImageLayerAt(i); // <TexturePath> could contain Url, relative path, or absolute path string imagePath = null; string imageUrl = null; if (curImageLayerType.TexturePath.Value.ToLower(System.Globalization.CultureInfo.InvariantCulture).StartsWith(("http://"))) { imageUrl = curImageLayerType.TexturePath.Value; } else { imagePath = curImageLayerType.TexturePath.Value; if(!Path.IsPathRooted(imagePath)) imagePath = Path.Combine(DirectoryPath, imagePath); } int transparentColor = 0; if(curImageLayerType.HasTransparentColor()) { transparentColor = System.Drawing.Color.FromArgb( curImageLayerType.TransparentColor.Red.Value, curImageLayerType.TransparentColor.Green.Value, curImageLayerType.TransparentColor.Blue.Value).ToArgb(); } ImageLayer newImageLayer = new ImageLayer( curImageLayerType.Name.Value, curWorld, (float)curImageLayerType.DistanceAboveSurface.Value, imagePath, (float)curImageLayerType.BoundingBox.South.Value2.DoubleValue(), (float)curImageLayerType.BoundingBox.North.Value2.DoubleValue(), (float)curImageLayerType.BoundingBox.West.Value2.DoubleValue(), (float)curImageLayerType.BoundingBox.East.Value2.DoubleValue(), (byte)curImageLayerType.Opacity.Value, (curImageLayerType.TerrainMapped.Value ? curWorld.TerrainAccessor : null)); newImageLayer.ImageUrl = imageUrl; newImageLayer.TransparentColor = transparentColor; newImageLayer.IsOn = curImageLayerType.ShowAtStartup.Value; if(curImageLayerType.HasLegendImagePath()) newImageLayer.LegendImagePath = curImageLayerType.LegendImagePath.Value; if(curImageLayerType.HasExtendedInformation() && curImageLayerType.ExtendedInformation.HasToolBarImage()) newImageLayer.MetaData.Add("ToolBarImagePath", Path.Combine(DirectoryPath, curImageLayerType.ExtendedInformation.ToolBarImage.Value)); rol.Add(newImageLayer); } } if(curLayerSet.HasQuadTileSet()) { for(int i = 0; i < curLayerSet.QuadTileSetCount; i++) { LayerSet.Type_QuadTileSet2 curQtsType = curLayerSet.GetQuadTileSetAt(i); /*ImageAccessor imageAccessor = null; string permDirPath = null; if(curQtsType.ImageAccessor.HasPermanantDirectory()) { permDirPath = curQtsType.ImageAccessor.PermanantDirectory.Value; if(!Path.IsPathRooted(permDirPath)) permDirPath = Path.Combine( DirectoryPath, permDirPath ); } string cacheDirPath = Path.Combine(worldWindow.Cache.CacheDirectory, Path.Combine(curWorld.Name, Path.Combine(rol.Name, curQtsType.Name.Value ))); int transparentColor = 0; if(curQtsType.HasTransparentColor()) { transparentColor = System.Drawing.Color.FromArgb( curQtsType.TransparentColor.Red.Value, curQtsType.TransparentColor.Green.Value, curQtsType.TransparentColor.Blue.Value).ToArgb(); } if(curQtsType.ImageAccessor.HasWMSAccessor()) { WMSLayerAccessor wmsLayerAccessor = null; wmsLayerAccessor = new WMSLayerAccessor(); wmsLayerAccessor.ImageFormat = curQtsType.ImageAccessor.WMSAccessor.ImageFormat.Value; wmsLayerAccessor.IsTransparent = curQtsType.ImageAccessor.WMSAccessor.UseTransparency.Value; wmsLayerAccessor.ServerGetMapUrl = curQtsType.ImageAccessor.WMSAccessor.ServerGetMapUrl.Value; wmsLayerAccessor.Version = curQtsType.ImageAccessor.WMSAccessor.Version.Value; wmsLayerAccessor.WMSLayerName = curQtsType.ImageAccessor.WMSAccessor.WMSLayerName.Value; if(curQtsType.ImageAccessor.WMSAccessor.HasUsername()) wmsLayerAccessor.Username = curQtsType.ImageAccessor.WMSAccessor.Username.Value; if(curQtsType.ImageAccessor.WMSAccessor.HasPassword()) wmsLayerAccessor.Password = curQtsType.ImageAccessor.WMSAccessor.Password.Value; if(curQtsType.ImageAccessor.WMSAccessor.HasWMSLayerStyle()) wmsLayerAccessor.WMSLayerStyle = curQtsType.ImageAccessor.WMSAccessor.WMSLayerStyle.Value; else wmsLayerAccessor.WMSLayerStyle = ""; if(curQtsType.ImageAccessor.WMSAccessor.HasServerLogoFilePath()) { string logoPath = Path.Combine(DirectoryPath, curQtsType.ImageAccessor.WMSAccessor.ServerLogoFilePath.Value); if(File.Exists(logoPath)) wmsLayerAccessor.LogoFilePath = logoPath; } imageAccessor = new ImageAccessor( permDirPath, curQtsType.ImageAccessor.TextureSizePixels.Value, curQtsType.ImageAccessor.LevelZeroTileSizeDegrees.DoubleValue(), curQtsType.ImageAccessor.NumberLevels.Value, curQtsType.ImageAccessor.ImageFileExtension.Value, cacheDirPath, wmsLayerAccessor); } else if(curQtsType.ImageAccessor.HasImageTileService()) { string logoPath = null; if(curQtsType.ImageAccessor.ImageTileService.HasServerLogoFilePath()) logoPath = Path.Combine( DirectoryPath, curQtsType.ImageAccessor.ImageTileService.ServerLogoFilePath.Value); ImageTileService imageTileService = new ImageTileService( curQtsType.ImageAccessor.ImageTileService.DataSetName.Value, curQtsType.ImageAccessor.ImageTileService.ServerUrl.Value, logoPath ); imageAccessor = new ImageAccessor( permDirPath, curQtsType.ImageAccessor.TextureSizePixels.Value, curQtsType.ImageAccessor.LevelZeroTileSizeDegrees.DoubleValue(), curQtsType.ImageAccessor.NumberLevels.Value, curQtsType.ImageAccessor.ImageFileExtension.Value, cacheDirPath, imageTileService); } else if(curQtsType.ImageAccessor.HasDuplicateTilePath()) { string dupePath = curQtsType.ImageAccessor.DuplicateTilePath.Value; if(!Path.IsPathRooted(dupePath)) dupePath = Path.Combine(DirectoryPath, dupePath); imageAccessor = new ImageAccessor( permDirPath, curQtsType.ImageAccessor.TextureSizePixels.Value, curQtsType.ImageAccessor.LevelZeroTileSizeDegrees.DoubleValue(), curQtsType.ImageAccessor.NumberLevels.Value, curQtsType.ImageAccessor.ImageFileExtension.Value, cacheDirPath, dupePath); } else { imageAccessor = new ImageAccessor( permDirPath, curQtsType.ImageAccessor.TextureSizePixels.Value, curQtsType.ImageAccessor.LevelZeroTileSizeDegrees.DoubleValue(), curQtsType.ImageAccessor.NumberLevels.Value, curQtsType.ImageAccessor.ImageFileExtension.Value, cacheDirPath); } QuadTileSet qts = new QuadTileSet( curQtsType.Name.Value, curWorld, curQtsType.DistanceAboveSurface.DoubleValue(), curQtsType.BoundingBox.North.Value2.DoubleValue(), curQtsType.BoundingBox.South.Value2.DoubleValue(), curQtsType.BoundingBox.West.Value2.DoubleValue(), curQtsType.BoundingBox.East.Value2.DoubleValue(), (curQtsType.TerrainMapped.Value ? curWorld.TerrainAccessor : null), imageAccessor); qts.TransparentColor = transparentColor; if(curQtsType.ShowAtStartup.Value) qts.IsOn = true; else qts.IsOn = false; if(curQtsType.HasExtendedInformation() && curQtsType.ExtendedInformation.HasToolBarImage()) { try { string fileName = Path.Combine(DirectoryPath, curQtsType.ExtendedInformation.ToolBarImage.Value); if (File.Exists(fileName)) qts.MetaData.Add("ToolBarImagePath", fileName); } catch { // TODO: Log or display warning } } rol.Add(qts);*/ } } if(curLayerSet.HasPathList()) { for(int i = 0; i < curLayerSet.PathListCount; i++) { LayerSet.Type_PathList2 newPathList = curLayerSet.GetPathListAt(i); PathList pl = new PathList( newPathList.Name.Value, curWorld, newPathList.MinDisplayAltitude.DoubleValue(), newPathList.MaxDisplayAltitude.DoubleValue(), DirectoryPath + "//" + newPathList.PathsDirectory.Value, newPathList.DistanceAboveSurface.DoubleValue(), (newPathList.HasWinColorName() ? System.Drawing.Color.FromName(newPathList.WinColorName.Value) : System.Drawing.Color.FromArgb(newPathList.RGBColor.Red.Value, newPathList.RGBColor.Green.Value, newPathList.RGBColor.Blue.Value)), curWorld.TerrainAccessor); pl.IsOn = newPathList.ShowAtStartup.Value; if(newPathList.HasExtendedInformation() && newPathList.ExtendedInformation.HasToolBarImage()) pl.MetaData.Add("ToolBarImagePath", Path.Combine(DirectoryPath, newPathList.ExtendedInformation.ToolBarImage.Value)); rol.Add(pl); } } if(curLayerSet.HasShapeFileLayer()) { for(int i = 0; i < curLayerSet.ShapeFileLayerCount; i++) { LayerSet.Type_ShapeFileLayer2 newShapefileLayer = curLayerSet.GetShapeFileLayerAt(i); Microsoft.DirectX.Direct3D.FontDescription fd = GetLayerFontDescription(newShapefileLayer.DisplayFont); Microsoft.DirectX.Direct3D.Font font = worldWindow.DrawArgs.CreateFont( fd ); ShapeLayer sp = new ShapeLayer( newShapefileLayer.Name.Value, curWorld, newShapefileLayer.DistanceAboveSurface.DoubleValue(), newShapefileLayer.MasterFilePath.Value, newShapefileLayer.MinimumViewAltitude.DoubleValue(), newShapefileLayer.MaximumViewAltitude.DoubleValue(), font, (newShapefileLayer.HasWinColorName() ? System.Drawing.Color.FromName(newShapefileLayer.WinColorName.Value) : System.Drawing.Color.FromArgb(newShapefileLayer.RGBColor.Red.Value, newShapefileLayer.RGBColor.Green.Value, newShapefileLayer.RGBColor.Blue.Value)), (newShapefileLayer.HasScalarKey() ? newShapefileLayer.ScalarKey.Value : null), (newShapefileLayer.HasShowBoundaries() ? newShapefileLayer.ShowBoundaries.Value : false), (newShapefileLayer.HasShowFilledRegions() ? newShapefileLayer.ShowFilledRegions.Value : false)); sp.IsOn = newShapefileLayer.ShowAtStartup.BoolValue(); if(newShapefileLayer.HasExtendedInformation() && newShapefileLayer.ExtendedInformation.HasToolBarImage()) sp.MetaData.Add("ToolBarImagePath", Path.Combine(DirectoryPath, newShapefileLayer.ExtendedInformation.ToolBarImage.Value)); rol.Add(sp); } } if(curLayerSet.HasIcon()) { Icons icons = (Icons)rol; for(int i = 0; i < curLayerSet.IconCount; i++) { LayerSet.Type_Icon newIcon = curLayerSet.GetIconAt(i); string textureFullPath = newIcon.TextureFilePath.Value; if (textureFullPath.Length > 0 && !Path.IsPathRooted(textureFullPath)) // Use absolute path to icon image textureFullPath = Path.Combine( DirectoryPath, newIcon.TextureFilePath.Value ); WorldWind.Renderable.Icon ic = new WorldWind.Renderable.Icon( newIcon.Name.Value, (float)newIcon.Latitude.Value2.DoubleValue(), (float)newIcon.Longitude.Value2.DoubleValue(), (float)newIcon.DistanceAboveSurface.DoubleValue() ); ic.TextureFileName = textureFullPath; ic.Width = newIcon.IconWidthPixels.Value; ic.Height = newIcon.IconHeightPixels.Value; ic.IsOn = newIcon.ShowAtStartup.Value; if(newIcon.HasDescription()) ic.Description = newIcon.Description.Value; if(newIcon.HasClickableUrl()) ic.ClickableActionURL = newIcon.ClickableUrl.Value; if(newIcon.HasMaximumDisplayAltitude()) ic.MaximumDisplayDistance = (float)newIcon.MaximumDisplayAltitude.Value; if(newIcon.HasMinimumDisplayAltitude()) ic.MinimumDisplayDistance = (float)newIcon.MinimumDisplayAltitude.Value; icons.Add(ic); } } if(curLayerSet.HasTiledPlacenameSet()) { for(int i = 0; i < curLayerSet.TiledPlacenameSetCount; i++) { LayerSet.Type_TiledPlacenameSet2 newPlacenames = curLayerSet.GetTiledPlacenameSetAt(i); string filePath = newPlacenames.PlacenameListFilePath.Value; if(!Path.IsPathRooted(filePath)) filePath = Path.Combine(DirectoryPath, filePath); Microsoft.DirectX.Direct3D.FontDescription fd = GetLayerFontDescription(newPlacenames.DisplayFont); TiledPlacenameSet tps = new TiledPlacenameSet( newPlacenames.Name.Value, curWorld, newPlacenames.DistanceAboveSurface.DoubleValue(), newPlacenames.MaximumDisplayAltitude.DoubleValue(), newPlacenames.MinimumDisplayAltitude.DoubleValue(), filePath, fd, (newPlacenames.HasWinColorName() ? System.Drawing.Color.FromName(newPlacenames.WinColorName.Value) : System.Drawing.Color.FromArgb(newPlacenames.RGBColor.Red.Value, newPlacenames.RGBColor.Green.Value, newPlacenames.RGBColor.Blue.Value)), (newPlacenames.HasIconFilePath() ? newPlacenames.IconFilePath.Value : null)); if(newPlacenames.HasExtendedInformation() && newPlacenames.ExtendedInformation.HasToolBarImage()) tps.MetaData.Add("ToolBarImagePath", Path.Combine(DirectoryPath, newPlacenames.ExtendedInformation.ToolBarImage.Value)); tps.IsOn = newPlacenames.ShowAtStartup.Value; rol.Add(tps); } } if(curLayerSet.HasChildLayerSet()) { for(int i = 0; i < curLayerSet.ChildLayerSetCount; i++) { LayerSet.Type_LayerSet ls = curLayerSet.GetChildLayerSetAt(i); rol.Add( getRenderableObjectListFromLayerSet( curWorld, ls, layerSetFile)); } } rol.IsOn = curLayerSet.ShowAtStartup.Value; return rol; }
public override void Update(WorldWind.DrawArgs drawArgs) { lock (this) { if (m_oLayer != null) { if (m_oGroundOverlay.Icon.ViewRefreshMode == KMLViewRefreshMode.onStop) { double dTimeStopped; if (drawArgs.CurrentRoI.Equals(m_oLastAoI)) { dTimeStopped = (DateTime.Now - m_oLastAoIChangeTime).Seconds; } else { dTimeStopped = 0.0; m_oLastAoI = drawArgs.CurrentRoI; m_oLastAoIChangeTime = DateTime.Now; } if (dTimeStopped > m_oGroundOverlay.Icon.ViewRefreshTime && !m_oLayerAoI.Equivalent(drawArgs.CurrentRoI, 1e-6)) { try { File.Delete(m_strImageFilename); } catch (IOException) { return; } GeographicBoundingBox oRenderBox = GetNewBox(drawArgs.CurrentRoI, m_oGroundOverlay.Icon.ViewBoundScale); m_oLayer = new ImageLayer( m_oGroundOverlay.Name, drawArgs.CurrentWorld, m_oGroundOverlay.Altitude, m_strImageFilename, oRenderBox.South, oRenderBox.North, oRenderBox.West, oRenderBox.East, (byte)(m_oGroundOverlay.Color.A * ((double)m_opacity / (double)(byte.MaxValue))), drawArgs.CurrentWorld.TerrainAccessor); if (m_oGroundOverlay.Icon.IsLocalFile) { m_oLayer.ImagePath = Path.Combine(m_strKMLDirectory, m_oGroundOverlay.Icon.HRef); } else { m_oLayer.ImageUrl = m_oGroundOverlay.Icon.GetUri(oRenderBox.West, oRenderBox.South, oRenderBox.East, oRenderBox.North); } m_oLayer.Initialize(drawArgs); m_oLayerAoI = drawArgs.CurrentRoI.Clone() as GeographicBoundingBox; } } m_oLayer.Update(drawArgs); } } }
private void UpdateImageLayers(DrawArgs drawArgs) { try { m_LastUpdate = System.DateTime.Now; if (m_NwImageLayer != null) { m_NwImageLayer.Dispose(); } if (m_NeImageLayer != null) { m_NeImageLayer.Dispose(); } if (m_SwImageLayer != null) { m_SwImageLayer.Dispose(); } if (m_SeImageLayer != null) { m_SeImageLayer.Dispose(); } double centerLatitude = 0.5 * (m_geographicBoundingBox.North + m_geographicBoundingBox.South); double centerLongitude = 0.5 * (m_geographicBoundingBox.West + m_geographicBoundingBox.East); m_NwImageLayer = CreateImageLayer(m_geographicBoundingBox.North, centerLatitude, m_geographicBoundingBox.West, centerLongitude, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", null, //ShapeTile.CachePath, "R", //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer), Level + 1, 2 * Row + 1, 2 * Col)); m_NeImageLayer = CreateImageLayer(m_geographicBoundingBox.North, centerLatitude, centerLongitude, m_geographicBoundingBox.East, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", null, //ShapeTile.CachePath, "R", //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer), Level + 1, 2 * Row + 1, 2 * Col + 1)); m_SwImageLayer = CreateImageLayer(centerLatitude, m_geographicBoundingBox.South, m_geographicBoundingBox.West, centerLongitude, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", null, //ShapeTile.CachePath, "R", //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer), Level + 1, 2 * Row, 2 * Col)); m_SeImageLayer = CreateImageLayer(centerLatitude, m_geographicBoundingBox.South, centerLongitude, m_geographicBoundingBox.East, drawArgs, String.Format("{0}\\{1}\\{2}\\{3:D4}\\{3:D4}_{4:D4}.dds", null, //ShapeTile.CachePath, "R", //ConfigurationLoader.GetRenderablePathString(m_parentProjectedLayer), Level + 1, 2 * Row, 2 * Col + 1)); if (m_NwImageLayer != null) { m_NwImageLayer.Initialize(drawArgs); } if (m_NeImageLayer != null) { m_NeImageLayer.Initialize(drawArgs); } if (m_SwImageLayer != null) { m_SwImageLayer.Initialize(drawArgs); } if (m_SeImageLayer != null) { m_SeImageLayer.Initialize(drawArgs); } } catch (Exception ex) { Log.Write(ex); } }
private void button1_Click(object sender, System.EventArgs e) { try { if(this.curSelectedDataSet == null) return; this.currentImageList.Clear(); this.currentAnimatingImages.Clear(); if(this.imageLayer != null) { m_WorldWindow.CurrentWorld.RenderableObjects.Remove(this.imageLayer.Name); this.imageLayer.Dispose(); this.imageLayer = null; } if(this.buttonLoad.Text == "Cancel") { this.buttonLoad.Text = "Load"; } else { this.currentAnimatingDataSet = this.curSelectedDataSet; if(this.listBox1.SelectedItems.Count > 0) { this.animationTimer.Start(); foreach(string item in this.listBox1.SelectedItems) { this.currentImageList.Add(item); } this.buttonLoad.Text = "Cancel"; this.downloaderThread = new System.Threading.Thread(new System.Threading.ThreadStart(this.downloadThreadFunc)); this.downloaderThread.IsBackground = true; this.downloaderThread.Start(); } } } catch(Exception ex) { this.statusBar1.Text = "Error"; Log.Write(ex); } }
private void UpdateImageLayers(DrawArgs drawArgs) { try { m_LastUpdate = System.DateTime.Now; if(m_NwImageLayer != null) m_NwImageLayer.Dispose(); if(m_NeImageLayer != null) m_NeImageLayer.Dispose(); if(m_SwImageLayer != null) m_SwImageLayer.Dispose(); if(m_SeImageLayer != null) m_SeImageLayer.Dispose(); double centerLatitude = 0.5 * (m_geographicBoundingBox.North + m_geographicBoundingBox.South); double centerLongitude = 0.5 * (m_geographicBoundingBox.West + m_geographicBoundingBox.East); m_NwImageLayer = CreateImageLayer(m_geographicBoundingBox.North, centerLatitude, m_geographicBoundingBox.West, centerLongitude); m_NeImageLayer = CreateImageLayer(m_geographicBoundingBox.North, centerLatitude, centerLongitude, m_geographicBoundingBox.East); m_SwImageLayer = CreateImageLayer(centerLatitude, m_geographicBoundingBox.South, m_geographicBoundingBox.West, centerLongitude); m_SeImageLayer = CreateImageLayer(centerLatitude, m_geographicBoundingBox.South, centerLongitude, m_geographicBoundingBox.East); if(m_NwImageLayer != null) { m_NwImageLayer.Initialize(drawArgs); } if(m_NeImageLayer != null) { m_NeImageLayer.Initialize(drawArgs); } if(m_SwImageLayer != null) { m_SwImageLayer.Initialize(drawArgs); } if(m_SeImageLayer != null) { m_SeImageLayer.Initialize(drawArgs); } } catch(Exception ex) { Log.Write(ex); } }
private Renderable.ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs, string imagePath) { Bitmap b = null; Graphics g = null; Renderable.ImageLayer imageLayer = null; GeographicBoundingBox geoBB = new GeographicBoundingBox(north, south, west, east); int numberPolygonsInTile = 0; FileInfo imageFile = new FileInfo(imagePath); FileInfo shapeFile = new FileInfo(m_ShapeTileArgs.ParentShapeFileLayer.ShapeFilePath); FileInfo shapeXmlFile = null; if (m_ShapeTileArgs.ParentShapeFileLayer.MetaData.Contains("SourceXml")) { string sourceXml = (string)m_ShapeTileArgs.ParentShapeFileLayer.MetaData["SourceXml"]; if (!sourceXml.ToLower().StartsWith("http://")) { shapeXmlFile = new FileInfo(sourceXml); } } if (!m_ShapeTileArgs.ParentShapeFileLayer.EnableCaching || !imageFile.Exists || shapeXmlFile == null || shapeXmlFile.LastWriteTimeUtc > imageFile.LastWriteTimeUtc || shapeFile.LastWriteTimeUtc > imageFile.LastWriteTimeUtc ) { for (int i = 0; i < m_ShapeTileArgs.ShapeRecords.Count; i++) { ShapeRecord currentRecord = (ShapeRecord)m_ShapeTileArgs.ShapeRecords[i]; if (currentRecord.Null != null || currentRecord.Point != null || currentRecord.MultiPoint != null || !isShapeRecordInBounds(geoBB, currentRecord)) { continue; } else { if (b == null) { b = new Bitmap(m_ShapeTileArgs.TilePixelSize.Width, m_ShapeTileArgs.TilePixelSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } if (g == null) { g = Graphics.FromImage(b); } System.Drawing.Color color = m_ShapeTileArgs.PolygonColor; //Fix Black Tiles g.DrawLine(new Pen(color), 0, 0, 1, 1); if (m_ShapeTileArgs.UseScalar && m_ShapeTileArgs.ScaleColors) { double red = 1.0; double green = 1.0; double blue = 1.0; try { //TODO: make this a function and abstract to allow multiple gradient mappings double dv; double curScalar = double.Parse(currentRecord.Value.ToString()); if (curScalar < m_ShapeTileArgs.ScaleMin) { curScalar = m_ShapeTileArgs.ScaleMin; } if (curScalar > m_ShapeTileArgs.ScaleMax) { curScalar = m_ShapeTileArgs.ScaleMax; } dv = m_ShapeTileArgs.ScaleMax - m_ShapeTileArgs.ScaleMin; if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.25 * dv)) { red = 0; green = 4 * (curScalar - m_ShapeTileArgs.ScaleMin) / dv; } else if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.5 * dv)) { red = 0; blue = 1 + 4 * (m_ShapeTileArgs.ScaleMin + 0.25 * dv - curScalar) / dv; } else if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.75 * dv)) { red = 4 * (curScalar - m_ShapeTileArgs.ScaleMin - 0.5 * dv) / dv; blue = 0; } else { green = 1 + 4 * (m_ShapeTileArgs.ScaleMin + 0.75 * dv - curScalar) / dv; blue = 0; } color = System.Drawing.Color.FromArgb((int)(255 * red), (int)(255 * green), (int)(255 * blue)); } catch (Exception) { // Utility.Log.Write((string)currentPoly.ScalarHash[m_ShapeTileArgs.ColorKey]); // Utility.Log.Write(String.Format("Min: {0}, Max: {1}", m_ShapeTileArgs.ScaleMin, m_ShapeTileArgs.ScaleMax)); // Utility.Log.Write(String.Format("{0},{1},{2}", red, green, blue)); // Utility.Log.Write(ex); } } else { if (m_ShapeTileArgs.ColorAssignments.Count > 0 && m_ShapeTileArgs.ScaleColors) { try { string colorAssignmentKey = (string)currentRecord.Value; foreach (string cak in m_ShapeTileArgs.ColorAssignments.Keys) { if (String.Compare(cak, colorAssignmentKey, true) == 0) { color = (System.Drawing.Color)m_ShapeTileArgs.ColorAssignments[cak]; break; } } } catch (Exception) { } } } if (currentRecord.Polygon != null) { drawPolygon(currentRecord.Polygon, g, color, geoBB, b.Size); } if (m_ShapeTileArgs.ColorAssignments.Count == 0 || !m_ShapeTileArgs.ScaleColors) { color = m_ShapeTileArgs.LineColor; } if (currentRecord.PolyLine != null) { drawPolyLine(currentRecord.PolyLine, g, color, geoBB, b.Size); } numberPolygonsInTile++; } } } if (!m_ShapeTileArgs.ParentShapeFileLayer.EnableCaching) { string id = System.DateTime.Now.Ticks.ToString(); if (b != null) { MemoryStream ms = new MemoryStream(); //must copy original stream into new stream, if not, error occurs, not sure why m_ImageStream = new MemoryStream(ms.GetBuffer()); imageLayer = new WorldWind.Renderable.ImageLayer( id, m_ShapeTileArgs.ParentWorld, 0, m_ImageStream, System.Drawing.Color.Black.ToArgb(), (float)south, (float)north, (float)west, (float)east, (float)m_ShapeTileArgs.ParentShapeFileLayer.Opacity / 255.0f, m_ShapeTileArgs.ParentWorld.TerrainAccessor); ms.Close(); } } else if (imageFile.Exists || numberPolygonsInTile > 0) { string id = System.DateTime.Now.Ticks.ToString(); if (b != null) { MemoryStream ms = new MemoryStream(); b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); if (!imageFile.Directory.Exists) { imageFile.Directory.Create(); } //must copy original stream into new stream, if not, error occurs, not sure why m_ImageStream = new MemoryStream(ms.GetBuffer()); ImageHelper.ConvertToDxt3(m_ImageStream, imageFile.FullName); ms.Close(); } imageLayer = new WorldWind.Renderable.ImageLayer( id, m_ShapeTileArgs.ParentWorld, 0, // should be distance above surface imageFile.FullName, //m_ImageStream, //0,//System.Drawing.Color.Black.ToArgb(), (float)south, (float)north, (float)west, (float)east, (float)m_ShapeTileArgs.ParentShapeFileLayer.Opacity / 255.0f, m_ShapeTileArgs.ParentWorld.TerrainAccessor); } if (b != null) { b.Dispose(); } if (g != null) { g.Dispose(); } b = null; g = null; //might not be necessary //GC.Collect(); return(imageLayer); }
private ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs, string imagePath) { Bitmap b = null; Graphics g = null; ImageLayer imageLayer = null; GeographicBoundingBox geoBB = new GeographicBoundingBox(north, south, west, east); int numberPolygonsInTile = 0; FileInfo imageFile = new FileInfo(imagePath); FileInfo shapeFile = new FileInfo(m_ShapeTileArgs.ParentShapeFileLayer.ShapeFilePath); FileInfo shapeXmlFile = null; if (m_ShapeTileArgs.ParentShapeFileLayer.MetaData.Contains("SourceXml")) { string sourceXml = (string) m_ShapeTileArgs.ParentShapeFileLayer.MetaData["SourceXml"]; if (!sourceXml.ToLower().StartsWith("http://")) { shapeXmlFile = new FileInfo(sourceXml); } } if (!m_ShapeTileArgs.ParentShapeFileLayer.EnableCaching || !imageFile.Exists || shapeXmlFile == null || shapeXmlFile.LastWriteTimeUtc > imageFile.LastWriteTimeUtc || shapeFile.LastWriteTimeUtc > imageFile.LastWriteTimeUtc) { for (int i = 0; i < m_ShapeTileArgs.ShapeRecords.Count; i++) { ShapeFileRecord currentRecord = (ShapeFileRecord) m_ShapeTileArgs.ShapeRecords[i]; if (currentRecord.Null != null || currentRecord.Point != null || currentRecord.MultiPoint != null || !isShapeRecordInBounds(geoBB, currentRecord)) { continue; } else { if (b == null) { b = new Bitmap(m_ShapeTileArgs.TilePixelSize.Width, m_ShapeTileArgs.TilePixelSize.Height, PixelFormat.Format32bppArgb); } if (g == null) { g = Graphics.FromImage(b); } Color color = m_ShapeTileArgs.PolygonColor; //Fix Black Tiles g.DrawLine(new Pen(color), 0, 0, 1, 1); if (m_ShapeTileArgs.UseScalar && m_ShapeTileArgs.ScaleColors) { double red = 1.0; double green = 1.0; double blue = 1.0; try { //TODO: make this a function and abstract to allow multiple gradient mappings double dv; double curScalar = double.Parse(currentRecord.Value.ToString()); if (curScalar < m_ShapeTileArgs.ScaleMin) { curScalar = m_ShapeTileArgs.ScaleMin; } if (curScalar > m_ShapeTileArgs.ScaleMax) { curScalar = m_ShapeTileArgs.ScaleMax; } dv = m_ShapeTileArgs.ScaleMax - m_ShapeTileArgs.ScaleMin; if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.25*dv)) { red = 0; green = 4*(curScalar - m_ShapeTileArgs.ScaleMin)/dv; } else if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.5*dv)) { red = 0; blue = 1 + 4*(m_ShapeTileArgs.ScaleMin + 0.25*dv - curScalar)/dv; } else if (curScalar < (m_ShapeTileArgs.ScaleMin + 0.75*dv)) { red = 4*(curScalar - m_ShapeTileArgs.ScaleMin - 0.5*dv)/dv; blue = 0; } else { green = 1 + 4*(m_ShapeTileArgs.ScaleMin + 0.75*dv - curScalar)/dv; blue = 0; } color = Color.FromArgb((int) (255*red), (int) (255*green), (int) (255*blue)); } catch (Exception) { // Utility.Log.Write((string)currentPoly.ScalarHash[m_ShapeTileArgs.ColorKey]); // Utility.Log.Write(String.Format("Min: {0}, Max: {1}", m_ShapeTileArgs.ScaleMin, m_ShapeTileArgs.ScaleMax)); // Utility.Log.Write(String.Format("{0},{1},{2}", red, green, blue)); // Utility.Log.Write(ex); } } else { if (m_ShapeTileArgs.ColorAssignments.Count > 0 && m_ShapeTileArgs.ScaleColors) { try { string colorAssignmentKey = (string) currentRecord.Value; foreach (string cak in m_ShapeTileArgs.ColorAssignments.Keys) { if (String.Compare(cak, colorAssignmentKey, true) == 0) { color = (Color) m_ShapeTileArgs.ColorAssignments[cak]; break; } } } catch (Exception) {} } } if (currentRecord.Polygon != null) { drawPolygon(currentRecord.Polygon, g, color, geoBB, b.Size); } if (m_ShapeTileArgs.ColorAssignments.Count == 0 || !m_ShapeTileArgs.ScaleColors) { color = m_ShapeTileArgs.LineColor; } if (currentRecord.PolyLine != null) { drawPolyLine(currentRecord.PolyLine, g, color, geoBB, b.Size); } numberPolygonsInTile++; } } } if (!m_ShapeTileArgs.ParentShapeFileLayer.EnableCaching) { string id = DateTime.Now.Ticks.ToString(); if (b != null) { MemoryStream ms = new MemoryStream(); //must copy original stream into new stream, if not, error occurs, not sure why m_ImageStream = new MemoryStream(ms.GetBuffer()); imageLayer = new ImageLayer(id, m_ShapeTileArgs.ParentWorld, 0, m_ImageStream, Color.Black.ToArgb(), (float) south, (float) north, (float) west, (float) east, (float) m_ShapeTileArgs.ParentShapeFileLayer.Opacity/255.0f, m_ShapeTileArgs.ParentWorld.TerrainAccessor); ms.Close(); } } else if (imageFile.Exists || numberPolygonsInTile > 0) { string id = DateTime.Now.Ticks.ToString(); if (b != null) { MemoryStream ms = new MemoryStream(); b.Save(ms, ImageFormat.Bmp); if (!imageFile.Directory.Exists) { imageFile.Directory.Create(); } //must copy original stream into new stream, if not, error occurs, not sure why m_ImageStream = new MemoryStream(ms.GetBuffer()); ImageHelper.ConvertToDxt3(m_ImageStream, imageFile.FullName); ms.Close(); } imageLayer = new ImageLayer(id, m_ShapeTileArgs.ParentWorld, 0, // should be distance above surface imageFile.FullName, //m_ImageStream, //0,//System.Drawing.Color.Black.ToArgb(), (float) south, (float) north, (float) west, (float) east, (float) m_ShapeTileArgs.ParentShapeFileLayer.Opacity/255.0f, m_ShapeTileArgs.ParentWorld.TerrainAccessor); } if (b != null) { b.Dispose(); } if (g != null) { g.Dispose(); } b = null; g = null; //might not be necessary //GC.Collect(); return imageLayer; }
/// <summary> /// Parse Ground Overlays /// </summary> /// <param name="inNode">The node containing Ground Overlays</param> /// <param name="layer">The layer to add the resulting Ground Overlays to</param> private void ParseGroundOverlays(XmlNode inNode, RIcons layer) { // Parse all Placemarks that have a name and LineString XmlNodeList groundOverlays = inNode.SelectNodes("GroundOverlay[name and LatLonBox]"); foreach (XmlNode node in groundOverlays) { // Extract the name from this node XmlNode nameNode = node.SelectSingleNode("name"); string name = nameNode.InnerText; XmlNode latLonBoxNode = node.SelectSingleNode("LatLonBox"); //Parse Coordinates if(latLonBoxNode != null) { XmlNode northNode = latLonBoxNode.SelectSingleNode("north"); XmlNode southNode = latLonBoxNode.SelectSingleNode("south"); XmlNode westNode = latLonBoxNode.SelectSingleNode("west"); XmlNode eastNode = latLonBoxNode.SelectSingleNode("east"); double north = ConfigurationLoader.ParseDouble(northNode.InnerText); double south = ConfigurationLoader.ParseDouble(southNode.InnerText); double west = ConfigurationLoader.ParseDouble(westNode.InnerText); double east = ConfigurationLoader.ParseDouble(eastNode.InnerText); // Create GroundOverlay WorldWind.Renderable.ImageLayer imageLayer = new ImageLayer( name, ParentApplication.WorldWindow.CurrentWorld, 0, null, south, north, west, east, 1.0, ParentApplication.WorldWindow.CurrentWorld.TerrainAccessor ); imageLayer.DisableZBuffer = true; imageLayer.ImageUrl = node.SelectSingleNode("Icon/href").InnerText; XmlNode visibilityNode = node.SelectSingleNode("visibility"); if(visibilityNode != null) imageLayer.IsOn = (visibilityNode.InnerText == "1" ? true : false); layer.Add(imageLayer); } } }