public void AddPlacename(string name, float lat, float lon, Hashtable metaData) { WorldWindPlacenameFile p = null; foreach (WorldWindPlacenameFile tempFile in m_placenameFiles) { if (lat < tempFile.north && lat >= tempFile.south && lon >= tempFile.west && lon < tempFile.east) { p = tempFile; break; } } if (p == null) { return; } if (p.m_placeNames.Count == 50000) { //split WorldWindPlacenameFile[] splitFiles = p.SplitPlacenameFiles(); m_placenameFiles.Remove(p); foreach (WorldWindPlacenameFile newFile in splitFiles) { m_placenameFiles.Add(newFile); } this.AddPlacename(name, lat, lon, metaData); } else { p.AddPlacename(name, lat, lon, metaData); } }
public WorldWindPlacenameList() { WorldWindPlacenameFile rootPlacenameFile = new WorldWindPlacenameFile(); rootPlacenameFile.dataFilename = "0000_0000.wwp"; rootPlacenameFile.north = 90.0f; rootPlacenameFile.south = -90.0f; rootPlacenameFile.west = -180.0f; rootPlacenameFile.east = 180.0f; m_placenameFiles.Add(rootPlacenameFile); }
public override void Initialize(DrawArgs drawArgs) { this.isInitialized = true; m_drawingFont = drawArgs.CreateFont(m_fontDescription); if (!File.Exists(m_placenameListFilePath)) { this.isInitialized = true; Log.Write(Log.Levels.Error, "PLACE", m_placenameListFilePath + " not found."); return; } if (m_iconFilePath != null) { m_iconTexture = ImageHelper.LoadIconTexture(m_iconFilePath); using (Surface s = m_iconTexture.GetSurfaceLevel(0)) { SurfaceDescription desc = s.Description; m_spriteSize = new System.Drawing.Rectangle(0, 0, desc.Width, desc.Height); } m_sprite = new Sprite(drawArgs.device); } using (BufferedStream placenameFileListStream = new BufferedStream(File.Open(m_placenameListFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))) using (BinaryReader placenameFileListReader = new BinaryReader(placenameFileListStream, System.Text.Encoding.ASCII)) { int count = placenameFileListReader.ReadInt32(); for (int i = 0; i < count; i++) { WorldWindPlacenameFile wwpf = new WorldWindPlacenameFile(); wwpf.dataFilename = placenameFileListReader.ReadString(); wwpf.west = placenameFileListReader.ReadSingle(); wwpf.south = placenameFileListReader.ReadSingle(); wwpf.east = placenameFileListReader.ReadSingle(); wwpf.north = placenameFileListReader.ReadSingle(); m_placenameFileList.Add(wwpf); } } }
public WorldWindPlacenameFile[] SplitPlacenameFiles() { //split WorldWindPlacenameFile northWest = new WorldWindPlacenameFile(); northWest.north = this.north; northWest.south = 0.5f * (this.north + this.south); northWest.west = this.west; northWest.east = 0.5f * (this.west + this.east); northWest.dataFilename = GetRowFromLatitude(northWest.south, northWest.north - northWest.south).ToString().PadLeft(4, '0') + "_" + GetColFromLongitude(northWest.west, northWest.east - northWest.west).ToString().PadLeft(4, '0') + ".wwp"; WorldWindPlacenameFile northEast = new WorldWindPlacenameFile(); northEast.north = this.north; northEast.south = 0.5f * (this.north + this.south); northEast.west = 0.5f * (this.west + this.east); northEast.east = this.east; northEast.dataFilename = GetRowFromLatitude(northEast.south, northEast.north - northEast.south).ToString().PadLeft(4, '0') + "_" + GetColFromLongitude(northEast.west, northEast.east - northEast.west).ToString().PadLeft(4, '0') + ".wwp"; WorldWindPlacenameFile southWest = new WorldWindPlacenameFile(); southWest.north = 0.5f * (this.north + this.south); southWest.south = this.south; southWest.west = this.west; southWest.east = 0.5f * (this.west + this.east); southWest.dataFilename = GetRowFromLatitude(southWest.south, southWest.north - southWest.south).ToString().PadLeft(4, '0') + "_" + GetColFromLongitude(southWest.west, southWest.east - southWest.west).ToString().PadLeft(4, '0') + ".wwp"; WorldWindPlacenameFile southEast = new WorldWindPlacenameFile(); southEast.north = 0.5f * (this.north + this.south); southEast.south = this.south; southEast.west = 0.5f * (this.west + this.east); southEast.east = this.east; southEast.dataFilename = GetRowFromLatitude(southEast.south, southEast.north - southEast.south).ToString().PadLeft(4, '0') + "_" + GetColFromLongitude(southEast.west, southEast.east - southEast.west).ToString().PadLeft(4, '0') + ".wwp"; foreach (WorldWindPlacename p in m_placeNames) { if (p.Lat >= 0.5f * (this.north + this.south)) { if (p.Lon >= 0.5 * (this.west + this.east)) { northEast.AddPlacename(p.Name, p.Lat, p.Lon, p.metaData); } else { northWest.AddPlacename(p.Name, p.Lat, p.Lon, p.metaData); } } else { if (p.Lon >= 0.5 * (this.west + this.east)) { southEast.AddPlacename(p.Name, p.Lat, p.Lon, p.metaData); } else { southWest.AddPlacename(p.Name, p.Lat, p.Lon, p.metaData); } } } WorldWindPlacenameFile[] returnArray = new WorldWindPlacenameFile[] { northWest, northEast, southWest, southEast }; return(returnArray); }
/// <summary> /// Loads visible place names from one file. /// </summary> void UpdateNames(WorldWindPlacenameFile placenameFileDescriptor, ArrayList tempPlacenames, DrawArgs drawArgs) { // TODO: Replace with bounding box frustum intersection test double viewRange = drawArgs.WorldCamera.TrueViewRange.Degrees; double north = drawArgs.WorldCamera.Latitude.Degrees + viewRange; double south = drawArgs.WorldCamera.Latitude.Degrees - viewRange; double west = drawArgs.WorldCamera.Longitude.Degrees - viewRange; double east = drawArgs.WorldCamera.Longitude.Degrees + viewRange; if (placenameFileDescriptor.north < south) { return; } if (placenameFileDescriptor.south > north) { return; } if (placenameFileDescriptor.east < west) { return; } if (placenameFileDescriptor.west > east) { return; } string dataFilePath = Path.Combine(Path.GetDirectoryName(m_placenameListFilePath), placenameFileDescriptor.dataFilename); using (BufferedStream dataFileStream = new BufferedStream(File.Open(dataFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))) using (BinaryReader dataFileReader = new BinaryReader(dataFileStream, System.Text.Encoding.ASCII)) { WorldWindPlacenameFile dataFile = new WorldWindPlacenameFile(); dataFile.dataFilename = placenameFileDescriptor.dataFilename; dataFile.north = placenameFileDescriptor.north; dataFile.south = placenameFileDescriptor.south; dataFile.west = placenameFileDescriptor.west; dataFile.east = placenameFileDescriptor.east; int numberPlacenames = dataFileReader.ReadInt32(); tempPlacenames.Capacity = tempPlacenames.Count + numberPlacenames; WorldWindPlacename curPlace = new WorldWindPlacename(); for (int i = 0; i < numberPlacenames; i++) { if (m_placeNames != null && curPlaceNameIndex < m_placeNames.Length) { curPlace = m_placeNames[curPlaceNameIndex]; } string name = dataFileReader.ReadString(); float lat = dataFileReader.ReadSingle(); float lon = dataFileReader.ReadSingle(); int c = dataFileReader.ReadInt32(); // Not in use, removed for speed // Hashtable metaData = new Hashtable(c); for (int n = 0; n < c; n++) { string key = dataFileReader.ReadString(); string keyData = dataFileReader.ReadString(); // Not in use, removed for speed //metaData.Add(key, keyData); } // for easier hit testing float lonRanged = lon; if (lonRanged < west) { lonRanged += 360; // add a revolution } if (lat > north || lat < south || lonRanged > east || lonRanged < west) { continue; } WorldWindPlacename pn = new WorldWindPlacename(); pn.Lat = lat; pn.Lon = lon; pn.Name = name; // Not in use, removed for speed //pn.metaData = metaData; float elevation = 0; if (m_parentWorld.TerrainAccessor != null && drawArgs.WorldCamera.Altitude < 300000) { elevation = (float)m_parentWorld.TerrainAccessor.GetElevationAt(lat, lon); } float altitude = (float)(m_parentWorld.EquatorialRadius + World.Settings.VerticalExaggeration * m_altitude + World.Settings.VerticalExaggeration * elevation); pn.cartesianPoint = MathEngine.SphericalToCartesian(lat, lon, altitude); float distanceSq = Vector3.LengthSq(pn.cartesianPoint - drawArgs.WorldCamera.Position); if (distanceSq > m_maximumDistanceSq) { continue; } if (distanceSq < m_minimumDistanceSq) { continue; } if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(pn.cartesianPoint)) { continue; } tempPlacenames.Add(pn); } } }
public WorldWindPlacenameList() { WorldWindPlacenameFile rootPlacenameFile = new WorldWindPlacenameFile(); rootPlacenameFile.dataFilename = "0000_0000.wwp"; rootPlacenameFile.north = 90.0f; rootPlacenameFile.south = -90.0f; rootPlacenameFile.west = -180.0f; rootPlacenameFile.east = 180.0f; m_placenameFiles.Add(rootPlacenameFile); }
public WorldWindPlacenameFile[] SplitPlacenameFiles() { //split WorldWindPlacenameFile northWest = new WorldWindPlacenameFile(); northWest.north = this.north; northWest.south = 0.5f*(this.north + this.south); northWest.west = this.west; northWest.east = 0.5f*(this.west + this.east); northWest.dataFilename = GetRowFromLatitude(northWest.south, northWest.north - northWest.south).ToString().PadLeft(4, '0') + "_" + GetColFromLongitude(northWest.west, northWest.east - northWest.west).ToString().PadLeft(4, '0') + ".wwp"; WorldWindPlacenameFile northEast = new WorldWindPlacenameFile(); northEast.north = this.north; northEast.south = 0.5f*(this.north + this.south); northEast.west = 0.5f*(this.west + this.east); northEast.east = this.east; northEast.dataFilename = GetRowFromLatitude(northEast.south, northEast.north - northEast.south).ToString().PadLeft(4, '0') + "_" + GetColFromLongitude(northEast.west, northEast.east - northEast.west).ToString().PadLeft(4, '0') + ".wwp"; WorldWindPlacenameFile southWest = new WorldWindPlacenameFile(); southWest.north = 0.5f*(this.north + this.south); southWest.south = this.south; southWest.west = this.west; southWest.east = 0.5f*(this.west + this.east); southWest.dataFilename = GetRowFromLatitude(southWest.south, southWest.north - southWest.south).ToString().PadLeft(4, '0') + "_" + GetColFromLongitude(southWest.west, southWest.east - southWest.west).ToString().PadLeft(4, '0') + ".wwp"; WorldWindPlacenameFile southEast = new WorldWindPlacenameFile(); southEast.north = 0.5f*(this.north + this.south); southEast.south = this.south; southEast.west = 0.5f*(this.west + this.east); southEast.east = this.east; southEast.dataFilename = GetRowFromLatitude(southEast.south, southEast.north - southEast.south).ToString().PadLeft(4, '0') + "_" + GetColFromLongitude(southEast.west, southEast.east - southEast.west).ToString().PadLeft(4, '0') + ".wwp"; foreach (WorldWindPlacename p in m_placeNames) { if (p.Lat >= 0.5f*(this.north + this.south)) { if (p.Lon >= 0.5*(this.west + this.east)) { northEast.AddPlacename(p.Name, p.Lat, p.Lon, p.metaData); } else { northWest.AddPlacename(p.Name, p.Lat, p.Lon, p.metaData); } } else { if (p.Lon >= 0.5*(this.west + this.east)) { southEast.AddPlacename(p.Name, p.Lat, p.Lon, p.metaData); } else { southWest.AddPlacename(p.Name, p.Lat, p.Lon, p.metaData); } } } WorldWindPlacenameFile[] returnArray = new WorldWindPlacenameFile[] {northWest, northEast, southWest, southEast}; return returnArray; }
/// <summary> /// Loads visible place names from one file. /// </summary> private void UpdateNames(WorldWindPlacenameFile placenameFileDescriptor, ArrayList tempPlacenames, DrawArgs drawArgs) { // TODO: Replace with bounding box frustum intersection test double viewRange = drawArgs.WorldCamera.TrueViewRange.Degrees; double north = drawArgs.WorldCamera.Latitude.Degrees + viewRange; double south = drawArgs.WorldCamera.Latitude.Degrees - viewRange; double west = drawArgs.WorldCamera.Longitude.Degrees - viewRange; double east = drawArgs.WorldCamera.Longitude.Degrees + viewRange; if (placenameFileDescriptor.north < south) { return; } if (placenameFileDescriptor.south > north) { return; } if (placenameFileDescriptor.east < west) { return; } if (placenameFileDescriptor.west > east) { return; } string dataFilePath = Path.Combine(Path.GetDirectoryName(m_placenameListFilePath), placenameFileDescriptor.dataFilename); using (BufferedStream dataFileStream = new BufferedStream(File.Open(dataFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))) { using (BinaryReader dataFileReader = new BinaryReader(dataFileStream, Encoding.UTF8)) { WorldWindPlacenameFile dataFile = new WorldWindPlacenameFile(); dataFile.dataFilename = placenameFileDescriptor.dataFilename; dataFile.north = placenameFileDescriptor.north; dataFile.south = placenameFileDescriptor.south; dataFile.west = placenameFileDescriptor.west; dataFile.east = placenameFileDescriptor.east; int numberPlacenames = dataFileReader.ReadInt32(); tempPlacenames.Capacity = tempPlacenames.Count + numberPlacenames; WorldWindPlacename curPlace = new WorldWindPlacename(); for (int i = 0; i < numberPlacenames; i++) { if (m_placeNames != null && curPlaceNameIndex < m_placeNames.Length) { curPlace = m_placeNames[curPlaceNameIndex]; } string name = dataFileReader.ReadString(); float lat = dataFileReader.ReadSingle(); float lon = dataFileReader.ReadSingle(); int c = dataFileReader.ReadInt32(); // Not in use, removed for speed // Hashtable metaData = new Hashtable(c); for (int n = 0; n < c; n++) { string key = dataFileReader.ReadString(); string keyData = dataFileReader.ReadString(); // Not in use, removed for speed //metaData.Add(key, keyData); } // for easier hit testing float lonRanged = lon; if (lonRanged < west) { lonRanged += 360; // add a revolution } if (lat > north || lat < south || lonRanged > east || lonRanged < west) { continue; } WorldWindPlacename pn = new WorldWindPlacename(); pn.Lat = lat; pn.Lon = lon; pn.Name = name; // Not in use, removed for speed //pn.metaData = metaData; float elevation = 0; if (m_parentWorld.TerrainAccessor != null && drawArgs.WorldCamera.Altitude < 300000) { elevation = (float) m_parentWorld.TerrainAccessor.GetElevationAt(lat, lon); } float altitude = (float) (m_parentWorld.EquatorialRadius + World.Settings.VerticalExaggeration*m_altitude + World.Settings.VerticalExaggeration*elevation); pn.cartesianPoint = MathEngine.SphericalToCartesian(lat, lon, altitude); float distanceSq = Vector3.LengthSq(pn.cartesianPoint - drawArgs.WorldCamera.Position); if (distanceSq > m_maximumDistanceSq) { continue; } if (distanceSq < m_minimumDistanceSq) { continue; } if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(pn.cartesianPoint)) { continue; } tempPlacenames.Add(pn); } } } }
public override void Initialize(DrawArgs drawArgs) { this.Inited = true; m_drawingFont = drawArgs.CreateFont(m_fontDescription); if (!File.Exists(m_placenameListFilePath)) { this.Inited = true; Log.Write("PLACE", m_placenameListFilePath + " not found."); return; } if (m_iconFilePath != null) { m_iconTexture = ImageHelper.LoadIconTexture(m_iconFilePath); using (Surface s = m_iconTexture.GetSurfaceLevel(0)) { SurfaceDescription desc = s.Description; m_spriteSize = new Rectangle(0, 0, desc.Width, desc.Height); } m_sprite = new Sprite(drawArgs.Device); } using (BufferedStream placenameFileListStream = new BufferedStream(File.Open(m_placenameListFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))) { using (BinaryReader placenameFileListReader = new BinaryReader(placenameFileListStream, Encoding.UTF8)) { int count = placenameFileListReader.ReadInt32(); for (int i = 0; i < count; i++) { WorldWindPlacenameFile wwpf = new WorldWindPlacenameFile(); wwpf.dataFilename = placenameFileListReader.ReadString(); wwpf.west = placenameFileListReader.ReadSingle(); wwpf.south = placenameFileListReader.ReadSingle(); wwpf.east = placenameFileListReader.ReadSingle(); wwpf.north = placenameFileListReader.ReadSingle(); m_placenameFileList.Add(wwpf); } } } }