From: <che...@us...> - 2010-02-01 21:55:51
|
Revision: 3407 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3407&view=rev Author: chemelli_sf Date: 2010-02-01 21:55:34 +0000 (Mon, 01 Feb 2010) Log Message: ----------- Code resharped Modified Paths: -------------- trunk/plugins/WorldMap/LocalizeStrings.cs trunk/plugins/WorldMap/MAPS/ImageFunctions.cs trunk/plugins/WorldMap/MAPS/MapFunctions.cs trunk/plugins/WorldMap/MAPS/MapTile.cs trunk/plugins/WorldMap/MAPS/MapTiles.cs trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs trunk/plugins/WorldMap/MAPS/ThreadedDownload.cs trunk/plugins/WorldMap/MAPS/TileCacheDatabase.cs trunk/plugins/WorldMap/PlugInBase.cs trunk/plugins/WorldMap/Settings.cs trunk/plugins/WorldMap/WorldMap.cs trunk/plugins/WorldMap/WorldMapSearchResults.cs trunk/plugins/WorldMap/WorldmapConfig.cs trunk/plugins/WorldMap/WorldmapMenu.cs trunk/plugins/WorldMap/WorldmapSearch.cs Modified: trunk/plugins/WorldMap/LocalizeStrings.cs =================================================================== --- trunk/plugins/WorldMap/LocalizeStrings.cs 2010-02-01 21:46:38 UTC (rev 3406) +++ trunk/plugins/WorldMap/LocalizeStrings.cs 2010-02-01 21:55:34 UTC (rev 3407) @@ -24,15 +24,11 @@ #endregion using System; -using System.IO; -using System.Globalization; using System.Collections; using System.Collections.Generic; -using System.Text; -using System.Xml; -using MediaPortal.Util; +using System.Globalization; +using MediaPortal.Configuration; using MediaPortal.GUI.Library; -using MediaPortal.Configuration; using MediaPortal.Localisation; namespace MyWorldmap @@ -45,25 +41,30 @@ public class GUILocalizeStrings { #region Variables - static LocalisationProvider _stringProvider; - static Dictionary<string, string> _cultures; - static string[] _languages; + + private static Dictionary<string, string> _cultures; + private static string[] _languages; + private static LocalisationProvider _stringProvider; + #endregion #region Constructors/Destructors + // singleton. Dont allow any instance of this class private GUILocalizeStrings() { } - static public void Dispose() + public static void Dispose() { if (_stringProvider != null) _stringProvider.Dispose(); } + #endregion #region Public Methods + /// <summary> /// Public method to load the text from a strings/xml file into memory /// </summary> @@ -73,11 +74,11 @@ /// false when it was unable to load the text /// </returns> //[Obsolete("This method has changed", true)] - static public bool Load(string language) + public static bool Load(string language) { bool isPrefixEnabled = true; - using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + using (var reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) { isPrefixEnabled = reader.GetValueAsBool("general", "myprefix", true); if (language == null) language = reader.GetValueAsString("skin", "language", "English"); @@ -87,7 +88,8 @@ string cultureName = null; if (language != null) cultureName = GetCultureName(language); - Log.Info("[Worldmap]: Loading localised Strings - Path: {0} Culture: {1} Language: {2} Prefix: {3}", directory, cultureName, language, isPrefixEnabled); + Log.Info("[Worldmap]: Loading localised Strings - Path: {0} Culture: {1} Language: {2} Prefix: {3}", directory, + cultureName, language, isPrefixEnabled); _stringProvider = new LocalisationProvider(directory, cultureName, isPrefixEnabled); @@ -96,7 +98,7 @@ return true; } - static public string CurrentLanguage() + public static string CurrentLanguage() { if (_stringProvider == null) Load(null); @@ -104,7 +106,7 @@ return _stringProvider.CurrentLanguage.EnglishName; } - static public void ChangeLanguage(string language) + public static void ChangeLanguage(string language) { if (_stringProvider == null) Load(language); @@ -121,7 +123,7 @@ /// <returns> /// string containing the translated text /// </returns> - static public string Get(int dwCode, object[] parameters) + public static string Get(int dwCode, object[] parameters) { if (_stringProvider == null) Load(null); @@ -138,7 +140,7 @@ { return String.Format(translation, parameters); } - catch (System.FormatException e) + catch (FormatException e) { Log.Error("[Worldmap]: Error formatting translation with id {0}", dwCode); Log.Error("[Worldmap]: Unformatted translation: {0}", translation); @@ -154,7 +156,7 @@ /// <returns> /// string containing the translated text /// </returns> - static public string Get(int dwCode) + public static string Get(int dwCode) { if (_stringProvider == null) Load(null); @@ -170,7 +172,7 @@ return translation; } - static public void LocalizeLabel(ref string strLabel) + public static void LocalizeLabel(ref string strLabel) { if (_stringProvider == null) Load(null); @@ -187,7 +189,7 @@ try { - dwLabelID = System.Int32.Parse(strLabel); + dwLabelID = Int32.Parse(strLabel); } catch (FormatException e) { @@ -223,7 +225,7 @@ CultureInfo[] cultures = _stringProvider.AvailableLanguages(); - SortedList sortedLanguages = new SortedList(); + var sortedLanguages = new SortedList(); foreach (CultureInfo culture in cultures) sortedLanguages.Add(culture.EnglishName, culture.EnglishName); @@ -231,14 +233,14 @@ for (int i = 0; i < sortedLanguages.Count; i++) { - _languages[i] = (string)sortedLanguages.GetByIndex(i); + _languages[i] = (string) sortedLanguages.GetByIndex(i); } } return _languages; } - static public string GetCultureName(string language) + public static string GetCultureName(string language) { if (_cultures == null) { @@ -257,6 +259,7 @@ return null; } + #endregion } } \ No newline at end of file Modified: trunk/plugins/WorldMap/MAPS/ImageFunctions.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/ImageFunctions.cs 2010-02-01 21:46:38 UTC (rev 3406) +++ trunk/plugins/WorldMap/MAPS/ImageFunctions.cs 2010-02-01 21:55:34 UTC (rev 3407) @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; using System.Drawing; -using System.Drawing.Drawing2D; namespace MAPS { - class ImageFunctions + internal class ImageFunctions { public static Bitmap MergeBitmaps(Bitmap Background, Bitmap Overlay) { @@ -18,39 +14,41 @@ public static Bitmap GetUpperLeftPart(Bitmap Tile) { - Bitmap tmpBitmap = new Bitmap(256,256); + var tmpBitmap = new Bitmap(256, 256); Graphics graphic = Graphics.FromImage(tmpBitmap); - Rectangle tmpDestRect = new Rectangle(0,0,Tile.Width,Tile.Height);; - Rectangle tmpSourceRect = new Rectangle(0, 0, 128, 128); + var tmpDestRect = new Rectangle(0, 0, Tile.Width, Tile.Height); + ; + var tmpSourceRect = new Rectangle(0, 0, 128, 128); - graphic.DrawImage(tmpBitmap,tmpDestRect,0,0,128,128,GraphicsUnit.Pixel); - //(Tile, 0, 0, tmpSourceRect, GraphicsUnit.Pixel) + graphic.DrawImage(tmpBitmap, tmpDestRect, 0, 0, 128, 128, GraphicsUnit.Pixel); + //(Tile, 0, 0, tmpSourceRect, GraphicsUnit.Pixel) return tmpBitmap; } public static Bitmap GetUpperRightPart(Bitmap Tile) { - Bitmap tmpBitmap = new Bitmap(256, 256); + var tmpBitmap = new Bitmap(256, 256); Graphics graphic = Graphics.FromImage(tmpBitmap); - Rectangle tmpDestRect = new Rectangle(0, 0, Tile.Width, Tile.Height); ; - Rectangle tmpSourceRect = new Rectangle(129, 0, 256, 128); + var tmpDestRect = new Rectangle(0, 0, Tile.Width, Tile.Height); + ; + var tmpSourceRect = new Rectangle(129, 0, 256, 128); graphic.DrawImage(tmpBitmap, tmpDestRect, 129, 0, 256, 128, GraphicsUnit.Pixel); return tmpBitmap; - } public static Bitmap GetLowerLeftPart(Bitmap Tile) { - Bitmap tmpBitmap = new Bitmap(256, 256); + var tmpBitmap = new Bitmap(256, 256); Graphics graphic = Graphics.FromImage(tmpBitmap); - Rectangle tmpDestRect = new Rectangle(0, 0, Tile.Width, Tile.Height); ; - Rectangle tmpSourceRect = new Rectangle(0, 129, 128, 256); + var tmpDestRect = new Rectangle(0, 0, Tile.Width, Tile.Height); + ; + var tmpSourceRect = new Rectangle(0, 129, 128, 256); graphic.DrawImage(tmpBitmap, tmpDestRect, 0, 129, 128, 256, GraphicsUnit.Pixel); @@ -59,19 +57,16 @@ public static Bitmap GetLowerRightPart(Bitmap Tile) { - Bitmap tmpBitmap = new Bitmap(256, 256); + var tmpBitmap = new Bitmap(256, 256); Graphics graphic = Graphics.FromImage(tmpBitmap); - Rectangle tmpDestRect = new Rectangle(0, 0, Tile.Width, Tile.Height); ; - Rectangle tmpSourceRect = new Rectangle(129, 129, 256, 256); + var tmpDestRect = new Rectangle(0, 0, Tile.Width, Tile.Height); + ; + var tmpSourceRect = new Rectangle(129, 129, 256, 256); graphic.DrawImage(tmpBitmap, tmpDestRect, 129, 129, 256, 256, GraphicsUnit.Pixel); return tmpBitmap; } - - } -} - - +} \ No newline at end of file Modified: trunk/plugins/WorldMap/MAPS/MapFunctions.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/MapFunctions.cs 2010-02-01 21:46:38 UTC (rev 3406) +++ trunk/plugins/WorldMap/MAPS/MapFunctions.cs 2010-02-01 21:55:34 UTC (rev 3407) @@ -1,11 +1,11 @@ using System; -using System.Collections.Generic; -using System.Text; namespace MAPS { public class MapFunctions { + #region MapType enum + public enum MapType { GMRoad, @@ -17,13 +17,15 @@ VEHybrid } + #endregion + public static MapType GetNextMapType(MapType currentMapType) { - Array tmpMapTypes = Enum.GetValues(typeof(MapFunctions.MapType)); + Array tmpMapTypes = Enum.GetValues(typeof (MapType)); int IntMapType = Convert.ToInt32(currentMapType); IntMapType++; if (IntMapType > tmpMapTypes.Length - 1) IntMapType = 0; - return (MapFunctions.MapType)(Enum.ToObject(typeof(MapFunctions.MapType), IntMapType)); + return (MapType) (Enum.ToObject(typeof (MapType), IntMapType)); } public static MapType GetNextRoadMap(MapType currentMapType) @@ -52,7 +54,7 @@ return MapType.GMHybrid; } - + /// <summary> /// Get the vertical tile number from a latitude using mercator ptrojection formula /// </summary> @@ -66,14 +68,14 @@ if (lat < -90) lat = lat + 180; // conversion degre=>radians - double phi = Math.PI * lat / 180; + double phi = Math.PI*lat/180; double res; //double temp = Math.Tan(Math.PI / 4 - phi / 2); //res = Math.Log(temp); - res = 0.5 * Math.Log((1 + Math.Sin(phi)) / (1 - Math.Sin(phi))); + res = 0.5*Math.Log((1 + Math.Sin(phi))/(1 - Math.Sin(phi))); double maxTileY = Math.Pow(2, zoomLevel); - int result = (int)(((1 - res / maxlat) / 2) * (maxTileY)); + var result = (int) (((1 - res/maxlat)/2)*(maxTileY)); return (result); } @@ -92,8 +94,8 @@ longitude = longitude + 360; } - double res = (longitude + 180) / 360; - return (int)(res * Math.Pow(2, zoomLevel)); + double res = (longitude + 180)/360; + return (int) (res*Math.Pow(2, zoomLevel)); } /// <summary> @@ -102,16 +104,13 @@ //private PointF getMinBounds(int numlat, int numlong, int zoom) //{ // PointF res = new PointF(); - // double maxlat = Math.PI; // double maxTile = Math.Pow(2, zoom); // double numlatrel = maxlat * (1 - 2 * ((numlat + 1) / maxTile)); - // res.Y = (float)((2 * Math.Atan(Math.Exp(numlatrel)) - Math.PI / 2) * 180 / Math.PI); // res.X = (float)(360 * (numlong / maxTile) - 180); // return res; //} - /** get latitude/longitude maxi of a tile*/ //private PointF getMaxBounds(int numlat, int numlong, int zoom) //{ @@ -119,26 +118,23 @@ // double maxlat = Math.PI; // double maxTile = Math.Pow(2, zoom); // double numlatrel = maxlat * (1 - 2 * (numlat / maxTile)); - // res.Y = (float)((2 * Math.Atan(Math.Exp(numlatrel)) - Math.PI / 2) * 180 / Math.PI); // res.X = (float)(360 * (numlong + 1) / maxTile - 180); // return res; //} - - public static double ConvertTileXToLongitude(int TileX, int ZoomLevel) { double maxTile = Math.Pow(2, ZoomLevel); - return (float)(360 * (TileX ) / maxTile - 180); + return (float) (360*(TileX)/maxTile - 180); } public static double ConvertTileYToLatitude(int TileY, int ZoomLevel) { double maxlat = Math.PI; double maxTile = Math.Pow(2, ZoomLevel); - double numlatrel = maxlat * (1 - 2 * (TileY / maxTile)); + double numlatrel = maxlat*(1 - 2*(TileY/maxTile)); - return (float)((2 * Math.Atan(Math.Exp(numlatrel)) - Math.PI / 2) * 180 / Math.PI); + return (float) ((2*Math.Atan(Math.Exp(numlatrel)) - Math.PI/2)*180/Math.PI); } public static double ConvertZoomLevelToTileSizeDegree(int zoomLevel) @@ -165,38 +161,44 @@ public static string GetGMapSatUrl(double Longitude, double Latitude, int zoomLevel, ref MapConfig curConfig) { - return GetGMapSatUrl(ConvertLongitudeToTileX(Longitude, zoomLevel), ConvertLatitudeToTileY(Latitude, zoomLevel), zoomLevel, ref curConfig); + return GetGMapSatUrl(ConvertLongitudeToTileX(Longitude, zoomLevel), ConvertLatitudeToTileY(Latitude, zoomLevel), + zoomLevel, ref curConfig); } public static string GetGMapSatUrl(int TileX, int TileY, int zoomLevel, ref MapConfig curConfig) { string tileCode = GetGMapSatUrlTileCode(TileX, TileY, zoomLevel); - if(tileCode=="") return ""; - + if (tileCode == "") return ""; + int servNum = -1; try { switch (tileCode[tileCode.Length - 1]) { - case 'q': servNum = 0; + case 'q': + servNum = 0; break; - case 'r': servNum = 1; + case 'r': + servNum = 1; break; - case 's': servNum = 2; + case 's': + servNum = 2; break; - case 't': servNum = 3; + case 't': + servNum = 3; break; } } catch (Exception err) - { } + { + } string StringServNum; if (servNum == -1) StringServNum = ""; else StringServNum = servNum.ToString(); - string fullurl = string.Format(curConfig.GMAUrl,StringServNum, tileCode); + string fullurl = string.Format(curConfig.GMAUrl, StringServNum, tileCode); if (tileCode == "transparent") { //fullurl = "http://www.google.com/intl/en_ALL/mapfiles/transparent.png"; @@ -211,13 +213,15 @@ double halflat = TileY; /**/ double locxmin, locxmax, locymin, locymax, locxmoy, locymoy; - locxmin = 0; locxmax = Math.Pow(2, zoomLevel); - locymin = 0; locymax = Math.Pow(2, zoomLevel); + locxmin = 0; + locxmax = Math.Pow(2, zoomLevel); + locymin = 0; + locymax = Math.Pow(2, zoomLevel); for (int i = 0; i < zoomLevel; i++) { - locxmoy = (locxmax + locxmin) / 2; - locymoy = (locymax + locymin) / 2; + locxmoy = (locxmax + locxmin)/2; + locymoy = (locymax + locymin)/2; if ((halflat < locymin) || (halflat > locymax) || (TileX < locxmin) || @@ -229,12 +233,14 @@ { locymax = locymoy; if (TileX < locxmoy) - { /*q quadrant (top left)*/ + { + /*q quadrant (top left)*/ tileid += "q"; locxmax = locxmoy; } else - {/*r quadrant (top right)*/ + { +/*r quadrant (top right)*/ tileid += "r"; locxmin = locxmoy; } @@ -243,21 +249,22 @@ { locymin = locymoy; if (TileX < locxmoy) - { /*t quadrant (bottom right)*/ + { + /*t quadrant (bottom right)*/ tileid += "t"; locxmax = locxmoy; } else - {/*s quadrant (bottom left)*/ + { +/*s quadrant (bottom left)*/ tileid += "s"; locxmin = locxmoy; } } } return tileid; + } - - } public static string GetGTerrainUrl(int TileX, int TileY, int zoomLevel, ref MapConfig curConfig) { string tileCode = GetGMapSatUrlTileCode(TileX, TileY, zoomLevel); @@ -269,18 +276,23 @@ { switch (tileCode[tileCode.Length - 1]) { - case 'q': servNum = 0; + case 'q': + servNum = 0; break; - case 'r': servNum = 1; + case 'r': + servNum = 1; break; - case 's': servNum = 2; + case 's': + servNum = 2; break; - case 't': servNum = 3; + case 't': + servNum = 3; break; } } catch (Exception err) - { } + { + } string StringServNum; if (servNum == -1) StringServNum = ""; @@ -290,7 +302,6 @@ string[] urltab = TileCode.Split('_'); string fullurl = string.Format(curConfig.GMTUrl, StringServNum, urltab[0], urltab[1], urltab[2]); return fullurl; - } public static string GetGMapUrl(int TileX, int TileY, int zoomLevel, ref MapConfig curConfig) @@ -304,18 +315,23 @@ { switch (tileCode[tileCode.Length - 1]) { - case 'q': servNum = 0; + case 'q': + servNum = 0; break; - case 'r': servNum = 1; + case 'r': + servNum = 1; break; - case 's': servNum = 2; + case 's': + servNum = 2; break; - case 't': servNum = 3; + case 't': + servNum = 3; break; } } catch (Exception err) - { } + { + } string StringServNum; if (servNum == -1) StringServNum = ""; @@ -323,9 +339,8 @@ string TileCode = GetGMapTileCode(TileX, TileY, zoomLevel); string[] urltab = TileCode.Split('_'); - string fullurl = string.Format(curConfig.GMRUrl, StringServNum, urltab[0],urltab[1],urltab[2]); + string fullurl = string.Format(curConfig.GMRUrl, StringServNum, urltab[0], urltab[1], urltab[2]); return fullurl; - } public static string GetGHybridOverlayUrl(int TileX, int TileY, int zoomLevel, ref MapConfig curConfig) @@ -339,18 +354,23 @@ { switch (tileCode[tileCode.Length - 1]) { - case 'q': servNum = 0; + case 'q': + servNum = 0; break; - case 'r': servNum = 1; + case 'r': + servNum = 1; break; - case 's': servNum = 2; + case 's': + servNum = 2; break; - case 't': servNum = 3; + case 't': + servNum = 3; break; } } catch (Exception err) - { } + { + } string StringServNum; if (servNum == -1) StringServNum = ""; @@ -358,7 +378,8 @@ string TileCode = GetGMapTileCode(TileX, TileY, zoomLevel); string[] urltab = TileCode.Split('_'); - string fullurl = string.Format(curConfig.GMHUrl, StringServNum, urltab[0], urltab[1], urltab[2]); // a small "t" make the big differens + string fullurl = string.Format(curConfig.GMHUrl, StringServNum, urltab[0], urltab[1], urltab[2]); + // a small "t" make the big differens return fullurl; } @@ -366,9 +387,9 @@ { int localzoom = (17 - zoomLevel); string tileid = ""; - double numLong = (int)TileX; - double numLat = (int)TileY; - tileid = numLong.ToString() + "_" + ((int)numLat).ToString() + "_" + localzoom.ToString(); + double numLong = TileX; + double numLat = TileY; + tileid = numLong + "_" + ((int) numLat) + "_" + localzoom; return tileid; } @@ -377,13 +398,17 @@ string url = null; switch (mapType) { - case MapType.GMTerrain: url = GetGTerrainUrl(TileX, TileY, zoomLevel, ref curConfig); + case MapType.GMTerrain: + url = GetGTerrainUrl(TileX, TileY, zoomLevel, ref curConfig); break; - case MapType.GMRoad: url = GetGMapUrl(TileX, TileY, zoomLevel, ref curConfig); + case MapType.GMRoad: + url = GetGMapUrl(TileX, TileY, zoomLevel, ref curConfig); break; - case MapType.GMAerial: url = GetGMapSatUrl(TileX, TileY, zoomLevel, ref curConfig); + case MapType.GMAerial: + url = GetGMapSatUrl(TileX, TileY, zoomLevel, ref curConfig); break; - case MapType.GMHybrid: url = GetGMapSatUrl(TileX, TileY, zoomLevel, ref curConfig); + case MapType.GMHybrid: + url = GetGMapSatUrl(TileX, TileY, zoomLevel, ref curConfig); break; } return url; @@ -421,8 +446,9 @@ { url = string.Format(curConfig.VEUrl, mapTypePreFix, quadKey[quadKey.Length - 1], quadKey, mapExtension); } - catch(Exception err) - { } + catch (Exception err) + { + } return url; } @@ -458,15 +484,17 @@ case MapType.GMAerial: case MapType.GMHybrid: case MapType.GMTerrain: - case MapType.GMRoad: url = GetGMTileUrl(mapType, TileX, TileY, zoomLevel, ref curConfig); + case MapType.GMRoad: + url = GetGMTileUrl(mapType, TileX, TileY, zoomLevel, ref curConfig); break; case MapType.VERoad: case MapType.VEAerial: - case MapType.VEHybrid: url = GetVETileUrl(mapType, TileX, TileY, zoomLevel, ref curConfig); + case MapType.VEHybrid: + url = GetVETileUrl(mapType, TileX, TileY, zoomLevel, ref curConfig); break; } return url; } } -} +} \ No newline at end of file Modified: trunk/plugins/WorldMap/MAPS/MapTile.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/MapTile.cs 2010-02-01 21:46:38 UTC (rev 3406) +++ trunk/plugins/WorldMap/MAPS/MapTile.cs 2010-02-01 21:55:34 UTC (rev 3407) @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Drawing; namespace MAPS @@ -10,79 +8,107 @@ public class ImageChangedEventArgs : EventArgs { private int TileX, TileY, ZoomMode; + public ImageChangedEventArgs(int tileX, int tileY, int zoomMode) { - this.TileX = tileX; - this.TileY = tileY; - this.ZoomMode = zoomMode; + TileX = tileX; + TileY = tileY; + ZoomMode = zoomMode; } } public class MapTile { - public event ImageChangedEventHandler ImageChangedEvent; - - protected virtual void OnImageChangedEvent(ImageChangedEventArgs e) - { - ImageChangedEvent(this, e); - } - - MapFunctions.MapType _mapType; + private double _BottomLatitude; + private Bitmap _Image; + private double _LeftLongitude; + private MapFunctions.MapType _mapType; private int _PosX; private int _PosY; - private int _ZoomLevel; - private double _LeftLongitude; private double _RightLongitude; + private double _TileHeightDegree; + private double _TileWidthDegree; private double _TopLatitude; - private double _BottomLatitude; - private double _TileWidthDegree; - private double _TileHeightDegree; + private int _ZoomLevel; - private Bitmap _Image; + public MapTile(MapFunctions.MapType mapType, int TileX, int TileY, int ZoomLevel) + { + _mapType = mapType; + _PosX = TileX; + _PosY = TileY; + + _ZoomLevel = ZoomLevel; + _TileWidthDegree = MapFunctions.ConvertZoomLevelToTileSizeDegree(_ZoomLevel); + + _LeftLongitude = MapFunctions.ConvertTileXToLongitude(_PosX, _ZoomLevel); + _RightLongitude = MapFunctions.ConvertTileXToLongitude(_PosX + 1, _ZoomLevel); + + _TopLatitude = MapFunctions.ConvertTileYToLatitude(_PosY, _ZoomLevel); + _BottomLatitude = MapFunctions.ConvertTileYToLatitude(_PosY + 1, _ZoomLevel); + + _TileWidthDegree = RigthLongitude - LeftLongitude; + if (_TileWidthDegree < 0) _TileWidthDegree *= -1; + + _TileHeightDegree = BottomLatitude - TopLatitude; + if (_TileHeightDegree < 0) _TileHeightDegree *= -1; + + _Image = new Bitmap(256, 256); + } + public MapFunctions.MapType MapType { get { return _mapType; } } + public int PosX { get { return _PosX; } } + public int PosY { get { return _PosY; } } + public int ZoomLevel { get { return _ZoomLevel; } } + public double LeftLongitude { get { return _LeftLongitude; } } + public double RigthLongitude { get { return _RightLongitude; } } + public double TopLatitude { get { return _TopLatitude; } } + public double BottomLatitude { get { return _BottomLatitude; } } + public double TileWidthDegree { get { return _TileWidthDegree; } } + public double TileHeightDegree { get { return _TileHeightDegree; } } + public Bitmap Image { - get { return _Image;} + get { return _Image; } set { _Image = value; @@ -90,31 +116,11 @@ } } - public MapTile(MapFunctions.MapType mapType, int TileX, int TileY, int ZoomLevel) + public event ImageChangedEventHandler ImageChangedEvent; + + protected virtual void OnImageChangedEvent(ImageChangedEventArgs e) { - _mapType = mapType; - - _PosX = TileX; - _PosY = TileY; - - _ZoomLevel = ZoomLevel; - _TileWidthDegree = MapFunctions.ConvertZoomLevelToTileSizeDegree(_ZoomLevel); - - _LeftLongitude = MapFunctions.ConvertTileXToLongitude(_PosX, _ZoomLevel); - _RightLongitude = MapFunctions.ConvertTileXToLongitude(_PosX+1, _ZoomLevel); - - _TopLatitude = MapFunctions.ConvertTileYToLatitude(_PosY, _ZoomLevel); - _BottomLatitude = MapFunctions.ConvertTileYToLatitude(_PosY+1, _ZoomLevel); - - _TileWidthDegree = RigthLongitude - LeftLongitude; - if (_TileWidthDegree < 0) _TileWidthDegree *= -1; - - _TileHeightDegree = BottomLatitude - TopLatitude; - if (_TileHeightDegree < 0) _TileHeightDegree *= -1; - - _Image = new Bitmap(256, 256); - + ImageChangedEvent(this, e); } - } -} +} \ No newline at end of file Modified: trunk/plugins/WorldMap/MAPS/MapTiles.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/MapTiles.cs 2010-02-01 21:46:38 UTC (rev 3406) +++ trunk/plugins/WorldMap/MAPS/MapTiles.cs 2010-02-01 21:55:34 UTC (rev 3407) @@ -1,31 +1,28 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Drawing; -using System.Threading; namespace MAPS { public class MapConfig { public string CacheFolder; - public int ThreadCountGMR; - public int ThreadCountGMA; - public int ThreadCountGMH; - public int ThreadCountGMT; - public int ThreadCountVER; - public int ThreadCountVEA; - public int ThreadCountVEH; public int DaysToKeepCachedDetailedTiles; public int DaysToKeepCachedOverviewTiles; + public Bitmap DownloadPlaceholder; public string GMAUrl; - public string GMRUrl; public string GMHUrl; + public string GMRUrl; public string GMTUrl; - public string VEUrl; - public Bitmap TileNotAvailable; public Bitmap IPBlocked; - public Bitmap DownloadPlaceholder; + public int ThreadCountGMA; + public int ThreadCountGMH; + public int ThreadCountGMR; + public int ThreadCountGMT; + public int ThreadCountVEA; + public int ThreadCountVEH; + public int ThreadCountVER; + public Bitmap TileNotAvailable; + public string VEUrl; public MapConfig() { @@ -41,43 +38,37 @@ DaysToKeepCachedDetailedTiles = 200; } } - + public delegate void CombinedImageChangedEventHandler(object sender, ImageChangedEventArgs e); public class MapTiles { - public event CombinedImageChangedEventHandler CombinedImageChangedEvent; - - public MapConfig mapConfig; - + public Bitmap combinedTiles; + public Bitmap croppedCombinedTiles; public ThreadedDownload ImageGrabber; - public MapTile[][] Tiles; public int ImageResolutionX; public int ImageResolutionY; - public int TileCountX; - public int TileCountY; - - public int StartTileX; - public int StartTileY; - - public double Longitude; public double Latitude; + public double Longitude; + public MapConfig mapConfig; + public MapFunctions.MapType mapType; public int OffsetX; public int OffsetY; + public int StartTileX; + public int StartTileY; + public int TileCountX; + public int TileCountY; + public MapTile[][] Tiles; public int ZoomLevel; - public MapFunctions.MapType mapType; - public Bitmap combinedTiles; - public Bitmap croppedCombinedTiles; - public MapTiles(int ImageResulotionX, int ImageResulotionY, MapConfig mapConfig) { - this.ImageResolutionX = ImageResulotionX; - this.ImageResolutionY = ImageResulotionY; + ImageResolutionX = ImageResulotionX; + ImageResolutionY = ImageResulotionY; this.mapConfig = mapConfig; @@ -86,9 +77,11 @@ TileCountX = CalcTileCount(ImageResulotionX + 256); TileCountY = CalcTileCount(ImageResulotionY + 256); - combinedTiles = new Bitmap(TileCountX * 256, TileCountY * 256); + combinedTiles = new Bitmap(TileCountX*256, TileCountY*256); } + public event CombinedImageChangedEventHandler CombinedImageChangedEvent; + protected virtual void OnCombinedImageChangedEvent(ImageChangedEventArgs e) { try @@ -97,31 +90,30 @@ } catch (NullReferenceException err) { - } } public void Refresh() { - int CenterTileX = MapFunctions.ConvertLongitudeToTileX(Longitude,ZoomLevel); - int CenterTileY = MapFunctions.ConvertLatitudeToTileY(Latitude,ZoomLevel); + int CenterTileX = MapFunctions.ConvertLongitudeToTileX(Longitude, ZoomLevel); + int CenterTileY = MapFunctions.ConvertLatitudeToTileY(Latitude, ZoomLevel); - StartTileX = CenterTileX - ((int)(TileCountX / 2)); - StartTileY = CenterTileY - ((int)(TileCountY / 2)); + StartTileX = CenterTileX - ((int) (TileCountX/2)); + StartTileY = CenterTileY - ((int) (TileCountY/2)); - MapTile tmpTile = new MapTile(mapType, CenterTileX, CenterTileY, ZoomLevel); + var tmpTile = new MapTile(mapType, CenterTileX, CenterTileY, ZoomLevel); double tmpLongitudeDelta; tmpLongitudeDelta = Longitude - tmpTile.LeftLongitude; if (tmpLongitudeDelta < 0) tmpLongitudeDelta *= -1; - OffsetX = (int)(256 * (((100 / tmpTile.TileWidthDegree) * tmpLongitudeDelta) / 100)); + OffsetX = (int) (256*(((100/tmpTile.TileWidthDegree)*tmpLongitudeDelta)/100)); double tmpLatitudeDelta; tmpLatitudeDelta = Latitude - tmpTile.TopLatitude; if (tmpLatitudeDelta < 0) tmpLatitudeDelta *= -1; - OffsetY = (int)(256 * (((100 / tmpTile.TileHeightDegree) * tmpLatitudeDelta) / 100)); + OffsetY = (int) (256*(((100/tmpTile.TileHeightDegree)*tmpLatitudeDelta)/100)); Tiles = new MapTile[TileCountX][]; @@ -141,43 +133,48 @@ } } - void tmpTile_ImageChangedEvent(object sender, ImageChangedEventArgs e) + private void tmpTile_ImageChangedEvent(object sender, ImageChangedEventArgs e) { lock (combinedTiles) { bool newTiles = false; - MapTile tmpTile = (MapTile)sender; + var tmpTile = (MapTile) sender; try { if (tmpTile == null) { return; } - int insertX = (tmpTile.PosX - StartTileX) * 256; - int insertY = (tmpTile.PosY - StartTileY) * 256; + int insertX = (tmpTile.PosX - StartTileX)*256; + int insertY = (tmpTile.PosY - StartTileY)*256; Graphics graphics = Graphics.FromImage(combinedTiles); graphics.DrawImage(tmpTile.Image, insertX, insertY, tmpTile.Image.Width, tmpTile.Image.Height); newTiles = true; } catch (NullReferenceException err) - { } + { + } catch (InvalidOperationException err) - { } + { + } catch (ArgumentOutOfRangeException err) - { } + { + } if (newTiles) { croppedCombinedTiles = new Bitmap(ImageResolutionX, ImageResolutionY); Graphics cropGraphics = Graphics.FromImage(croppedCombinedTiles); - int cropPosX = (((combinedTiles.Width / 2) - 128) + OffsetX) - (ImageResolutionX / 2); //(((combinedTiles.Width / 2) - (ImageResolutionX / 2)) + 128) - OffsetX; - int cropPosY = (((combinedTiles.Height / 2) - 128) + OffsetY) - (ImageResolutionY / 2); // (((combinedTiles.Height / 2) - (ImageResolutionY / 2)) + 128) - OffsetY; + int cropPosX = (((combinedTiles.Width/2) - 128) + OffsetX) - (ImageResolutionX/2); + //(((combinedTiles.Width / 2) - (ImageResolutionX / 2)) + 128) - OffsetX; + int cropPosY = (((combinedTiles.Height/2) - 128) + OffsetY) - (ImageResolutionY/2); + // (((combinedTiles.Height / 2) - (ImageResolutionY / 2)) + 128) - OffsetY; //System.Diagnostics.Debug.WriteLine(OffsetX + " : " + OffsetY + " :: " + cropPosX + " : " + cropPosY); - Rectangle tmpSource = new Rectangle(cropPosX, cropPosY, ImageResolutionX, ImageResolutionY); - Rectangle tmpDest = new Rectangle(0, 0, ImageResolutionX, ImageResolutionY); + var tmpSource = new Rectangle(cropPosX, cropPosY, ImageResolutionX, ImageResolutionY); + var tmpDest = new Rectangle(0, 0, ImageResolutionX, ImageResolutionY); cropGraphics.DrawImage(combinedTiles, tmpDest, tmpSource, GraphicsUnit.Pixel); OnCombinedImageChangedEvent(null); @@ -187,9 +184,9 @@ public int CalcTileCount(int Pixel) { - int ret = (int)(Pixel / 256); - if ((Pixel % 256) != 0) ret++; // if the division does not fit - if ((ret % 2) == 0) ret++; // if the the tile count is unpair + var ret = (int) (Pixel/256); + if ((Pixel%256) != 0) ret++; // if the division does not fit + if ((ret%2) == 0) ret++; // if the the tile count is unpair return ret; } @@ -198,4 +195,4 @@ ImageGrabber.ClearDownloadQueue(); } } -} +} \ No newline at end of file Modified: trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs 2010-02-01 21:46:38 UTC (rev 3406) +++ trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs 2010-02-01 21:55:34 UTC (rev 3407) @@ -1,15 +1,14 @@ using System; using System.Collections.Generic; -using System.Text; +using System.Diagnostics; +using System.Globalization; +using System.IO; using System.Net; -using System.Web; -using System.IO; using System.Xml; -using System.Diagnostics; namespace MAPS { - enum GeoCodeService + internal enum GeoCodeService { OpenGeoCoding, YahooGeoCoding, @@ -17,25 +16,25 @@ GeoNames } - class GeoCode + internal class GeoCode { - public string Name; - public string Street; public string City; - public string State; public string Country; + public double Latitude; public double Longitude; - public double Latitude; + public string Name; + public string State; + public string Street; } - class SearchGeoCodes + internal class SearchGeoCodes { - public string Street = ""; public string City = ""; public string Country = ""; public string Placename = ""; + public List<GeoCode> SearchResult; public GeoCodeService ServiceName = GeoCodeService.YahooGeoCoding; - public List<GeoCode> SearchResult = null; + public string Street = ""; public void SearchNow() { @@ -63,7 +62,7 @@ { string ret = null; - HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url); + var httpRequest = (HttpWebRequest) WebRequest.Create(url); httpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"; httpRequest.Timeout = 15000; httpRequest.ReadWriteTimeout = 15000; @@ -73,10 +72,10 @@ try { - httpResponse = (HttpWebResponse)httpRequest.GetResponse(); + httpResponse = (HttpWebResponse) httpRequest.GetResponse(); Stream tmpStream = httpResponse.GetResponseStream(); - using (StreamReader reader = new StreamReader(tmpStream)) + using (var reader = new StreamReader(tmpStream)) { ret = reader.ReadToEnd(); } @@ -94,24 +93,24 @@ SearchResult = new List<GeoCode>(); SearchResult.Clear(); if (XMLString == null) return; - - XmlDocument doc = new XmlDocument(); + + var doc = new XmlDocument(); doc.LoadXml(XMLString); - + //XmlNode root = doc.DocumentElement; //XmlNodeList nodes = doc.SelectNodes("//ResultSet/Result"); //nodes = doc.DocumentElement.SelectNodes("Result"); XmlNodeList nodes = doc.DocumentElement.ChildNodes; - System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InstalledUICulture; - System.Globalization.NumberFormatInfo ni = (System.Globalization.NumberFormatInfo)ci.NumberFormat.Clone(); + CultureInfo ci = CultureInfo.InstalledUICulture; + var ni = (NumberFormatInfo) ci.NumberFormat.Clone(); ni.NumberDecimalSeparator = "."; ni.NumberGroupSeparator = ","; foreach (XmlNode node in nodes) { - GeoCode tmpGeoCode = new GeoCode(); + var tmpGeoCode = new GeoCode(); tmpGeoCode.Name = ""; tmpGeoCode.Street = node["Address"].InnerText; tmpGeoCode.City = node["City"].InnerText; @@ -120,7 +119,7 @@ tmpGeoCode.Latitude = double.Parse(node["Latitude"].InnerText, ni); tmpGeoCode.Longitude = double.Parse(node["Longitude"].InnerText, ni); SearchResult.Add(tmpGeoCode); - } + } } public void PushGeoNamesResultToSearchResult(string XMLString) @@ -130,7 +129,7 @@ if (XMLString == null) return; - XmlDocument doc = new XmlDocument(); + var doc = new XmlDocument(); doc.LoadXml(XMLString); XmlNode root = doc.DocumentElement; @@ -139,8 +138,8 @@ XmlNodeList nodes = doc.DocumentElement.ChildNodes; - System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InstalledUICulture; - System.Globalization.NumberFormatInfo ni = (System.Globalization.NumberFormatInfo)ci.NumberFormat.Clone(); + CultureInfo ci = CultureInfo.InstalledUICulture; + var ni = (NumberFormatInfo) ci.NumberFormat.Clone(); ni.NumberDecimalSeparator = "."; ni.NumberGroupSeparator = ","; @@ -148,14 +147,15 @@ { if (node.Name == "geoname") { - GeoCode tmpGeoCode = new GeoCode(); + var tmpGeoCode = new GeoCode(); tmpGeoCode.Name = node["name"].InnerText; try { tmpGeoCode.Name += " (" + node["adminName1"].InnerText + ")"; } catch (Exception err) - { } + { + } tmpGeoCode.Country = node["countryName"].InnerText; tmpGeoCode.Latitude = double.Parse(node["lat"].InnerText, ni); tmpGeoCode.Longitude = double.Parse(node["lng"].InnerText, ni); @@ -171,7 +171,7 @@ if (XMLString == null) return; - XmlDocument doc = new XmlDocument(); + var doc = new XmlDocument(); doc.LoadXml(XMLString); XmlNode root = doc.DocumentElement; @@ -180,27 +180,28 @@ XmlNodeList nodes = root.ChildNodes; - System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InstalledUICulture; - System.Globalization.NumberFormatInfo ni = (System.Globalization.NumberFormatInfo)ci.NumberFormat.Clone(); + CultureInfo ci = CultureInfo.InstalledUICulture; + var ni = (NumberFormatInfo) ci.NumberFormat.Clone(); ni.NumberDecimalSeparator = "."; ni.NumberGroupSeparator = ","; foreach (XmlNode node in nodes) { - if(node.Name == "Status") + if (node.Name == "Status") { - Debug.WriteLine(String.Format("WorldMap Google GeoCodeSearch. Request:{0} ReturnCode: {1}", node["request"].InnerText, node["code"].InnerText)); + Debug.WriteLine(String.Format("WorldMap Google GeoCodeSearch. Request:{0} ReturnCode: {1}", + node["request"].InnerText, node["code"].InnerText)); } if (node.Name == "Placemark") { - GeoCode tmpGeoCode = new GeoCode(); + var tmpGeoCode = new GeoCode(); tmpGeoCode.Name = node["address"].InnerText; XmlNode PointNode = node["Point"]; string Coordinates = PointNode.FirstChild.InnerText; - string longitude = Coordinates.Split(new char[] { ',' })[0]; - string latitude = Coordinates.Split(new char[] { ',' })[1]; + string longitude = Coordinates.Split(new[] {','})[0]; + string latitude = Coordinates.Split(new[] {','})[1]; tmpGeoCode.Longitude = double.Parse(longitude, ni); tmpGeoCode.Latitude = double.Parse(latitude, ni); SearchResult.Add(tmpGeoCode); @@ -212,7 +213,7 @@ { string url = "http://local.yahooapis.com/MapsService/V1/geocode?appid=MediaPortalWorldmap&output=xml"; - if (Street != "") url += "&street=" + Street; + if (Street != "") url += "&street=" + Street; if (City != "") url += "&city=" + City; if (Country != "") url += "&state=" + Country; @@ -236,7 +237,8 @@ public Uri GetGoogleAdress() { // right now the key is found somewhere at the internet. Why have to get our own... - string url = "http://maps.google.com/maps/geo?output=xml&key=ABQIAAAA5rWB_5p0XK5Y2Qzsyd6HpxSPVks7h_CYIzXuM6UMzYp2f8KU7RQbRo0p7vACcXJ1w39qEH6JPQL_xg&q="; + string url = + "http://maps.google.com/maps/geo?output=xml&key=ABQIAAAA5rWB_5p0XK5Y2Qzsyd6HpxSPVks7h_CYIzXuM6UMzYp2f8KU7RQbRo0p7vACcXJ1w39qEH6JPQL_xg&q="; int valuesAdded = 0; @@ -269,19 +271,20 @@ public string ConvertStringToSafeUrl(string url) { string ret = string.Empty; - string safeChars = "0123456789" + // Numeric - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic + string safeChars = "0123456789" + // Numeric + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic "abcdefghijklmnopqrstuvwxyz" + - ":-_.!~*'()?\\/=&%"; // special + ":-_.!~*'()?\\/=&%"; // special foreach (char Char in url) { if (safeChars.Contains(Char.ToString())) ret += Char; - else { ret += String.Format("%{0:X2}", (int)Char); } // convert to % plus the "hex value" + else + { + ret += String.Format("%{0:X2}", (int) Char); + } // convert to % plus the "hex value" } return ret; } - } - -} +} \ No newline at end of file Modified: trunk/plugins/WorldMap/MAPS/ThreadedDownload.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/ThreadedDownload.cs 2010-02-01 21:46:38 UTC (rev 3406) +++ trunk/plugins/WorldMap/MAPS/ThreadedDownload.cs 2010-02-01 21:55:34 UTC (rev 3407) @@ -1,30 +1,30 @@ using System; using System.Collections.Generic; -using System.Text; -using System.Windows.Forms; +using System.Diagnostics; +using System.Drawing; using System.IO; using System.Net; -using System.Diagnostics; -using System.Drawing; using System.Threading; namespace MAPS { - delegate void ProcessDownloadQueue(); - delegate void ImageThread(Object stateInfo); + internal delegate void ProcessDownloadQueue(); + + internal delegate void ImageThread(Object stateInfo); + public class ThreadedDownload { - public List<MapTile> QueuedImageDownloads = new List<MapTile>(); + public TileCacheDatabase cacheDatabase; public List<Thread> ImageDownloadThreads = new List<Thread>(); public MapConfig mapConfig; - public TileCacheDatabase cacheDatabase; + public List<MapTile> QueuedImageDownloads = new List<MapTile>(); public ThreadedDownload(MapConfig mapConfig) { this.mapConfig = mapConfig; - DatabaseOptions databaseOptions = new DatabaseOptions(); + var databaseOptions = new DatabaseOptions(); databaseOptions.cacheFolder = mapConfig.CacheFolder; databaseOptions.DaysToKeepCachedDetailedTiles = mapConfig.DaysToKeepCachedDetailedTiles; databaseOptions.DaysToKeepCachedOverviewTiles = mapConfig.DaysToKeepCachedOverviewTiles; @@ -38,19 +38,26 @@ switch (mapTile.MapType) { - case MapFunctions.MapType.GMRoad: FilePreFix = "gmr"; + case MapFunctions.MapType.GMRoad: + FilePreFix = "gmr"; break; - case MapFunctions.MapType.GMAerial: FilePreFix = "gma"; + case MapFunctions.MapType.GMAerial: + FilePreFix = "gma"; break; - case MapFunctions.MapType.GMHybrid: FilePreFix = "gmh"; + case MapFunctions.MapType.GMHybrid: + FilePreFix = "gmh"; break; - case MapFunctions.MapType.GMTerrain: FilePreFix = "gmt"; + case MapFunctions.MapType.GMTerrain: + FilePreFix = "gmt"; break; - case MapFunctions.MapType.VERoad: FilePreFix = "ver"; + case MapFunctions.MapType.VERoad: + FilePreFix = "ver"; break; - case MapFunctions.MapType.VEAerial: FilePreFix = "vea"; + case MapFunctions.MapType.VEAerial: + FilePreFix = "vea"; break; - case MapFunctions.MapType.VEHybrid: FilePreFix = "veh"; + case MapFunctions.MapType.VEHybrid: + FilePreFix = "veh"; break; } @@ -66,12 +73,14 @@ } } catch (NullReferenceException err) - { } + { + } catch (Exception err) { Debug.WriteLine(err.ToString()); - }; - + } + ; + //tmpTileImage = GetParentTilePart(FilePreFix,mapTile.PosX, mapTile.PosY, mapTile.ZoomLevel); if (tmpTileImage == null) @@ -80,20 +89,20 @@ } mapTile.Image = tmpTileImage; - + //System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(ImageThread), tmpImage); QueuedImageDownloads.Add(mapTile); ProcessDownloadQueue(); } - Bitmap GetParentTilePart(string mapPreFix, int TileX, int TileY, int zoomLevel) + private Bitmap GetParentTilePart(string mapPreFix, int TileX, int TileY, int zoomLevel) { Bitmap ret = null; - - double curLongitude = MapFunctions.ConvertTileXToLongitude(TileX,zoomLevel); - double curLatitude = MapFunctions.ConvertTileYToLatitude(TileY,zoomLevel); + double curLongitude = MapFunctions.ConvertTileXToLongitude(TileX, zoomLevel); + double curLatitude = MapFunctions.ConvertTileYToLatitude(TileY, zoomLevel); + int parentX = MapFunctions.ConvertLongitudeToTileX(curLongitude, zoomLevel - 1); int parentY = MapFunctions.ConvertLatitudeToTileY(curLatitude, zoomLevel - 1); @@ -105,13 +114,17 @@ string tmpTileCode = MapFunctions.GetGMapSatUrlTileCode(TileX, TileY, zoomLevel); switch (tmpTileCode[tmpTileCode.Length - 1]) { - case 'q': ret = ImageFunctions.GetUpperLeftPart(parentTile); + case 'q': + ret = ImageFunctions.GetUpperLeftPart(parentTile); break; - case 'r': ret = ImageFunctions.GetUpperRightPart(parentTile); + case 'r': + ret = ImageFunctions.GetUpperRightPart(parentTile); break; - case 's': ret = ImageFunctions.GetLowerLeftPart(parentTile); + case 's': + ret = ImageFunctions.GetLowerLeftPart(parentTile); break; - case 't': ret = ImageFunctions.GetLowerRightPart(parentTile); + case 't': + ret = ImageFunctions.GetLowerRightPart(parentTile); break; } } @@ -119,7 +132,8 @@ catch (Exception err) { // Debug.WriteLine(err.ToString()); - }; + } + ; return ret; } @@ -131,24 +145,32 @@ { switch (QueuedImageDownloads[0].MapType) { - case MapFunctions.MapType.GMRoad: maxThreadCount = mapConfig.ThreadCountGMR; + case MapFunctions.MapType.GMRoad: + maxThreadCount = mapConfig.ThreadCountGMR; break; - case MapFunctions.MapType.GMAerial: maxThreadCount = mapConfig.ThreadCountGMA; + case MapFunctions.MapType.GMAerial: + maxThreadCount = mapConfig.ThreadCountGMA; break; - case MapFunctions.MapType.GMHybrid: maxThreadCount = mapConfig.ThreadCountGMH; + case MapFunctions.MapType.GMHybrid: + maxThreadCount = mapConfig.ThreadCountGMH; break; - case MapFunctions.MapType.GMTerrain: maxThreadCount = mapConfig.ThreadCountGMT; + case MapFunctions.MapType.GMTerrain: + maxThreadCount = mapConfig.ThreadCountGMT; break; - case MapFunctions.MapType.VERoad: maxThreadCount = mapConfig.ThreadCountVER; + case MapFunctions.MapType.VERoad: + maxThreadCount = mapConfig.ThreadCountVER; break; - case MapFunctions.MapType.VEAerial: maxThreadCount = mapConfig.ThreadCountVEA; + case MapFunctions.MapType.VEAerial: + maxThreadCount = mapConfig.ThreadCountVEA; break; - case MapFunctions.MapType.VEHybrid: maxThreadCount = mapConfig.ThreadCountVEH; + case MapFunctions.MapType.VEHybrid: + maxThreadCount = mapConfig.ThreadCountVEH; break; } } - catch(Exception err) - { } + catch (Exception err) + { + } if (ImageDownloadThreads.Count < maxThreadCount) { @@ -159,7 +181,7 @@ MapTile tmpTile = QueuedImageDownloads[0]; QueuedImageDownloads.RemoveAt(0); - Thread t = new Thread(new ParameterizedThreadStart(ImageThread)); + var t = new Thread(new ParameterizedThreadStart(ImageThread)); t.Priority = ThreadPriority.BelowNormal; t.Name = "MapTileDownloader"; t.IsBackground = true; @@ -168,7 +190,8 @@ t.Start(tmpTile); } catch (Exception err) - { } + { + } //if(QueuedImageDownloads.Count>0) QueuedImageDownloads.RemoveAt(0); } @@ -191,8 +214,9 @@ //ImageDownloadThreads.RemoveAt(0); } - catch(Exception err) - { } + catch (Exception err) + { + } } Thread.Sleep(250); } @@ -200,13 +224,13 @@ ImageDownloadThreads.Clear(); - System.GC.ReRegisterForFinalize(QueuedImageDownloads); - System.GC.ReRegisterForFinalize(ImageDownloadThreads); - System.GC.Collect(); + GC.ReRegisterForFinalize(QueuedImageDownloads); + GC.ReRegisterForFinalize(ImageDownloadThreads); + GC.Collect(); //currentlyRunningThreads = 0; } - bool ImageThreadIsRunning() + private bool ImageThreadIsRunning() { bool ret = false; for (int i = 0; i < ImageDownloadThreads.Count; i++) @@ -216,12 +240,13 @@ ret |= ImageDownloadThreads[i].IsAlive; } catch (Exception err) - { } + { + } } return ret; } - void RemoveCurrentThreadFromList() + private void RemoveCurrentThreadFromList() { for (int i = 0; i < ImageDownloadThreads.Count; i++) { @@ -234,17 +259,19 @@ ImageDownloadThreads.RemoveAt(i); } catch (Exception err) - { } + { + } } } catch (Exception err) - { } + { + } } } - void ImageThread(Object stateInfo) + private void ImageThread(Object stateInfo) { - MapTile tmpImage = (MapTile)stateInfo; + var tmpImage = (MapTile) stateInfo; Bitmap tmpTileImage = null; string url; @@ -262,35 +289,43 @@ switch (tmpImage.MapType) { - case MapFunctions.MapType.GMRoad: FilePreFix = "gmr"; + case MapFunctions.MapType.GMRoad: + FilePreFix = "gmr"; break; - case MapFunctions.MapType.GMAerial: FilePreFix = "gma"; + case MapFunctions.MapType.GMAerial: + FilePreFix = "gma"; break; - case MapFunctions.MapType.GMHybrid: FilePreFix = "gmh"; + case MapFunctions.MapType.GMHybrid: + FilePreFix = "gmh"; break; - case MapFunctions.MapType.GMTerrain: FilePreFix = "gmt"; + case MapFunctions.MapType.GMTerrain: + FilePreFix = "gmt"; break; - case MapFunctions.MapType.VERoad: FilePreFix = "ver"; + case MapFunctions.MapType.VERoad: + FilePreFix = "ver"; break; - case MapFunctions.MapType.VEAerial: FilePreFix = "vea"; + case MapFunctions.MapType.VEAerial: + FilePreFix = "vea"; break; - case MapFunctions.MapType.VEHybrid: FilePreFix = "veh"; + case MapFunctions.MapType.VEHybrid: + FilePreFix = "veh"; break; } string UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"; - if (tmpImage.MapType == MapFunctions.MapType.VEAerial || tmpImage.MapType == MapFunctions.MapType.VEHybrid || tmpImage.MapType == MapFunctions.MapType.VERoad) + if (tmpImage.MapType == MapFunctions.MapType.VEAerial || tmpImage.MapType == MapFunctions.MapType.VEHybrid || + tmpImage.MapType == MapFunctions.MapType.VERoad) { UserAgent = "Virtual Earth 3D"; } - HttpWebRequest httpRequest = (HttpWebRequest) WebRequest.Create(url); + var httpRequest = (HttpWebRequest) WebRequest.Create(url); httpRequest.UserAgent = UserAgent; httpRequest.Timeout = 7000; httpRequest.ReadWriteTimeout = 7000; httpRequest.Method = "GET"; HttpWebResponse httpResponse = null; - + try { Stream tmpImageStream; @@ -304,12 +339,13 @@ tmpTileImage = cacheDatabase.GetImage("gma", tmpImage.PosX, tmpImage.PosY, tmpImage.ZoomLevel); } catch (Exception err) - { } + { + } } if (tmpTileImage == null) { - httpResponse = (HttpWebResponse)httpRequest.GetResponse(); + httpResponse = (HttpWebResponse) httpRequest.GetResponse(); tmpImageStream = httpResponse.GetResponseStream(); try @@ -331,15 +367,15 @@ { url = MapFunctions.GetGHybridOverlayUrl(tmpImage.PosX, tmpImage.PosY, tmpImage.ZoomLevel, ref mapConfig); Debug.WriteLine(url); - httpRequest = (HttpWebRequest)WebRequest.Create(url); + httpRequest = (HttpWebRequest) WebRequest.Create(url); httpRequest.UserAgent = UserAgent; httpRequest.Timeout = 7000; httpRequest.ReadWriteTimeout = 7000; httpRequest.Method = "GET"; - httpResponse = (HttpWebResponse)httpRequest.GetResponse(); + httpResponse = (HttpWebResponse) httpRequest.GetResponse(); tmpImageStream = httpResponse.GetResponseStream(); - Bitmap tmpHybridOverlay = new Bitmap(tmpImageStream); + var tmpHybridOverlay = new Bitmap(tmpImageStream); tmpTileImage = ImageFunctions.MergeBitmaps(tmpTileImage, tmpHybridOverlay); } @@ -351,7 +387,7 @@ Debug.WriteLine(err.ToString()); if (err.Status == WebExceptionStatus.ProtocolError) { - httpResponse = (HttpWebResponse)err.Response; + httpResponse = (HttpWebResponse) err.Response; if (httpResponse.StatusCode == HttpStatusCode.Forbidden) { tmpImage.Image = mapConfig.IPBlocked; @@ -370,7 +406,8 @@ httpRequest.Abort(); } catch (Exception err2) - { } + { + } } catch (Exception err) { @@ -384,4 +421,4 @@ ProcessDownloadQueue(); } } -} +} \ No newline at end of file Modified: trunk/plugins/WorldMap/MAPS/TileCacheDatabase.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/TileCacheDatabase.cs 2010-02-01 21:46:38 UTC (rev 3406) +++ trunk/plugins/WorldMap/MAPS/TileCacheDatabase.cs 2010-02-01 21:55:34 UTC (rev 3407) @@ -1,11 +1,10 @@ using System; -using System.Collections.Generic; -using System.Text; +using System.Data; +using System.Data.SQLite; using System.Diagnostics; -using System.Data.SQLite; -using System.Data; +using System.Drawing; +using System.Drawing.Imaging; using System.IO; -using System.Drawing; namespace MAPS { @@ -18,8 +17,8 @@ public class TileCacheDatabase { - private DatabaseOptions options; - private SQLiteConnection CurrentConnection = null; + private readonly DatabaseOptions options; + private SQLiteConnection CurrentConnection; public TileCacheDatabase(DatabaseOptions DatabaseOptions) { @@ -37,9 +36,10 @@ // if the db file doesn't exist, create a new db (New=True to create a db)--- if (!File.Exists(dbpath)) { - SQLiteConnection con = new SQLiteConnection(connString); + var con = new SQLiteConnection(connString); SQLiteCommand cmd = con.CreateCommand(); - cmd.CommandText = "CREATE TABLE MapTiles (TimeStamp timestamp DEFAULT CURRENT_TIMESTAMP NULL, MapType varchar(3), zoomLevel integer, TileX integer, TileY integer,image BLOB)"; + cmd.CommandText = + "CREATE TABLE MapTiles (TimeStamp timestamp DEFAULT CURRENT_TIMESTAMP NULL, MapType varchar(3), zoomLevel integer, TileX integer, TileY integer,image BLOB)"; con.Open(); cmd.ExecuteNonQuery(); @@ -66,57 +66,56 @@ con.Close(); cmd.Dispose(); } - } public void InsertImage(string MapType, int TileX, int TileY, int zoomLevel, Bitmap image) { if (CurrentConnection == null) { - string dbpath = options.cacheFolder + @"\MapTileCache.db"; string connString = @"Data Source=" + dbpath + ";UTF8Encoding=True;Version=3"; CurrentConnection = new SQLiteConnection(connString); } // stream to save the bitmap to - MemoryStream ms = new MemoryStream(); + var ms = new MemoryStream(); // Save to memory using the Jpeg format - image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); + image.Save(ms, ImageFormat.Jpeg); // read to end byte[] imageBytes = ms.GetBuffer(); ms.Close(); IDbComma... [truncated message content] |