From: <che...@us...> - 2010-08-21 12:53:37
|
Revision: 3760 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3760&view=rev Author: chemelli_sf Date: 2010-08-21 12:53:28 +0000 (Sat, 21 Aug 2010) Log Message: ----------- MyWorldMap 2.0 beta Plugin completly reworked to handle Bing and GoogleMaps APIs. Modified Paths: -------------- trunk/plugins/WorldMap/LocalizeStrings.cs trunk/plugins/WorldMap/MAPS/MapFunctions.cs trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs trunk/plugins/WorldMap/MyWorldMap.csproj trunk/plugins/WorldMap/PlugInBase.cs trunk/plugins/WorldMap/Properties/AssemblyInfo.cs trunk/plugins/WorldMap/Settings.cs trunk/plugins/WorldMap/WorldMap.cs trunk/plugins/WorldMap/WorldMapSearchResults.cs trunk/plugins/WorldMap/WorldmapConfig.Designer.cs trunk/plugins/WorldMap/WorldmapConfig.cs trunk/plugins/WorldMap/WorldmapMenu.cs trunk/plugins/WorldMap/WorldmapSearch.cs trunk/plugins/WorldMap/language/MyWorldmap/strings_en.xml trunk/plugins/WorldMap/language/MyWorldmap/strings_it.xml trunk/plugins/WorldMap/skinFiles/Blue3/MyWorldmapMenu.xml trunk/plugins/WorldMap/skinFiles/Blue3Wide/MyWorldmapMenu.xml Added Paths: ----------- trunk/plugins/WorldMap/MAPS/BingAPI.cs trunk/plugins/WorldMap/MAPS/GoogleAPI.cs trunk/plugins/WorldMap/MAPS/MapImages.cs trunk/plugins/WorldMap/Properties/Settings.Designer.cs trunk/plugins/WorldMap/Properties/Settings.settings trunk/plugins/WorldMap/Web References/ trunk/plugins/WorldMap/Web References/ImageryService/ trunk/plugins/WorldMap/Web References/ImageryService/ImageryMetadataResponse.datasource trunk/plugins/WorldMap/Web References/ImageryService/ImageryService.wsdl trunk/plugins/WorldMap/Web References/ImageryService/ImageryService.xsd trunk/plugins/WorldMap/Web References/ImageryService/ImageryService1.xsd trunk/plugins/WorldMap/Web References/ImageryService/ImageryService2.xsd trunk/plugins/WorldMap/Web References/ImageryService/ImageryService3.xsd trunk/plugins/WorldMap/Web References/ImageryService/ImageryService4.xsd trunk/plugins/WorldMap/Web References/ImageryService/ImageryService5.xsd trunk/plugins/WorldMap/Web References/ImageryService/MapUriResponse.datasource trunk/plugins/WorldMap/Web References/ImageryService/Reference.cs trunk/plugins/WorldMap/Web References/ImageryService/Reference.map trunk/plugins/WorldMap/Web References/ImageryService/imageryservice1.wsdl trunk/plugins/WorldMap/app.config trunk/plugins/WorldMap/language/MyWorldmap/strings_da.xml trunk/plugins/WorldMap/skinFiles/Blue3/Media/MyWorldMap/WorldMap.bmp trunk/plugins/WorldMap/skinFiles/Blue3Wide/Media/MyWorldMap/WorldMap.bmp Removed Paths: ------------- trunk/plugins/WorldMap/Installer/MyWorldmap.xml trunk/plugins/WorldMap/MAPS/ImageFunctions.cs trunk/plugins/WorldMap/MAPS/MapTile.cs trunk/plugins/WorldMap/MAPS/MapTiles.cs trunk/plugins/WorldMap/MAPS/ThreadedDownload.cs trunk/plugins/WorldMap/MAPS/TileCacheDatabase.cs trunk/plugins/WorldMap/Resources/ trunk/plugins/WorldMap/System.Data.SQLite.DLL trunk/plugins/WorldMap/skinFiles/Blue3/Media/MyWorldMap/WMIPBlocked.jpeg trunk/plugins/WorldMap/skinFiles/Blue3/Media/MyWorldMap/WMprogressBarActive.png trunk/plugins/WorldMap/skinFiles/Blue3/Media/MyWorldMap/WMprogressBarQueued.png trunk/plugins/WorldMap/skinFiles/Blue3/Media/MyWorldMap/WMprogressDummy.png trunk/plugins/WorldMap/skinFiles/Blue3Wide/Media/MyWorldMap/WMIPBlocked.jpeg trunk/plugins/WorldMap/skinFiles/Blue3Wide/Media/MyWorldMap/WMprogressBarActive.png trunk/plugins/WorldMap/skinFiles/Blue3Wide/Media/MyWorldMap/WMprogressBarQueued.png trunk/plugins/WorldMap/skinFiles/Blue3Wide/Media/MyWorldMap/WMprogressDummy.png Property Changed: ---------------- trunk/plugins/WorldMap/MAPS/ Deleted: trunk/plugins/WorldMap/Installer/MyWorldmap.xml =================================================================== --- trunk/plugins/WorldMap/Installer/MyWorldmap.xml 2010-08-21 11:27:15 UTC (rev 3759) +++ trunk/plugins/WorldMap/Installer/MyWorldmap.xml 2010-08-21 12:53:28 UTC (rev 3760) @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<profile> - <section name="MyWorldmap"> - <entry name="parmgmaurl">http://khm{0}.google.com/kh?v=57&t={1}</entry> - <entry name="parmgmrurl">http://mt{0}.google.com/vt?v=w2.107&x={1}&y={2}&zoom={3}</entry> - <entry name="parmgmhurl">http://mt{0}.google.com/vt?v=w2t.107&x={1}&y={2}&zoom={3}</entry> - <entry name="parmgmturl">http://mt{0}.google.com/vt?v=w2p.107&x={1}&y={2}&zoom={3}</entry> - <entry name="parmveurl">http://{0}{1}.ortho.tiles.virtualearth.net/tiles/{0}{2}{3}?g=1</entry> - </section> -</profile> \ No newline at end of file Modified: trunk/plugins/WorldMap/LocalizeStrings.cs =================================================================== --- trunk/plugins/WorldMap/LocalizeStrings.cs 2010-08-21 11:27:15 UTC (rev 3759) +++ trunk/plugins/WorldMap/LocalizeStrings.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -38,7 +38,7 @@ /// The text is loaded for the current language from /// the file language/[language]/strings.xml /// </summary> - public class GUILocalizeStrings + public class PluginGuiLocalizeStrings { #region Variables @@ -51,7 +51,7 @@ #region Constructors/Destructors // singleton. Dont allow any instance of this class - private GUILocalizeStrings() + private PluginGuiLocalizeStrings() { } @@ -68,7 +68,7 @@ /// <summary> /// Public method to load the text from a strings/xml file into memory /// </summary> - /// <param name="strFileName">Contains the filename+path for the string.xml file</param> + /// <param name="language">Contains the language name</param> /// <returns> /// true when text is loaded /// false when it was unable to load the text @@ -76,7 +76,7 @@ //[Obsolete("This method has changed", true)] public static bool Load(string language) { - bool isPrefixEnabled = true; + bool isPrefixEnabled; using (var reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) { @@ -103,7 +103,7 @@ if (_stringProvider == null) Load(null); - return _stringProvider.CurrentLanguage.EnglishName; + return _stringProvider != null ? _stringProvider.CurrentLanguage.EnglishName : null; } public static void ChangeLanguage(string language) Property changes on: trunk/plugins/WorldMap/MAPS ___________________________________________________________________ Added: svn:ignore + BindAPIKey.cs Added: trunk/plugins/WorldMap/MAPS/BingAPI.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/BingAPI.cs (rev 0) +++ trunk/plugins/WorldMap/MAPS/BingAPI.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -0,0 +1,120 @@ +using MyWorldMap.ImageryService; + +namespace MyWorldMap.MAPS +{ + internal class BingApi : IMapProvider + { + #region Interface required + + public string Version + { + get { return "v1.0 Web Services"; } + } + + public string Documentation + { + get { return "http://msdn.microsoft.com/en-us/library/dd877180.aspx"; } + } + + public string Description + { + get { return "Bing"; } + } + + public int MaxMapWidth + { + get { return 900; } + } + + public int MinZoom + { + get { return 1; } + } + + public int MaxZoom + { + get { return 21; } + } + + public string UrlGet(MapProperty newMap) + { + var pushpin = new Pushpin(); + var pins = new Pushpin[1]; + + var mapUriRequest = new MapUriRequest + { + Credentials = new Credentials + { + // Set credentials using a valid Bing Maps Key + ApplicationId = BindAPIKey.Load() + }, + Center = new Location + { + Latitude = newMap.Latitude, + LatitudeSpecified = true, + Longitude = newMap.Longitude, + LongitudeSpecified = true + } + }; + + if (newMap.Latitude != 0 && newMap.Longitude != 0) + { + // Not WorldView: show the pushpin + pushpin.Location = new Location + { + Latitude = newMap.Latitude, + LatitudeSpecified = true, + Longitude = newMap.Longitude, + LongitudeSpecified = true + }; + pushpin.IconStyle = "34"; + + pins[0] = pushpin; + mapUriRequest.Pushpins = pins; + } + + // Set the map style and zoom level + var mapUriOptions = new MapUriOptions(); + + switch (newMap.MapType) + { + case MapFunctions.MapType.Hybrid: + mapUriOptions.Style = MapStyle.AerialWithLabels; + break; + case MapFunctions.MapType.Road: + mapUriOptions.Style = MapStyle.Road; + break; + case MapFunctions.MapType.Satellite: + mapUriOptions.Style = MapStyle.Aerial; + break; + default: + mapUriOptions.Style = MapStyle.Road; + break; + } + mapUriOptions.StyleSpecified = true; + + mapUriOptions.ZoomLevel = newMap.Zoom; + mapUriOptions.ZoomLevelSpecified = true; + + // Keep aspect ratio + int width = newMap.Width > MaxMapWidth ? MaxMapWidth : newMap.Width; + int height = width * newMap.Height / newMap.Width; + + mapUriOptions.ImageSize = new SizeOfint + { + Width = width, + WidthSpecified = true, + Height = height, + HeightSpecified = true + }; + + mapUriRequest.Options = mapUriOptions; + var imageryService = new ImageryService.ImageryService(); + MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest); + + return mapUriResponse.Uri; + } + + #endregion + } +} \ No newline at end of file Added: trunk/plugins/WorldMap/MAPS/GoogleAPI.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/GoogleAPI.cs (rev 0) +++ trunk/plugins/WorldMap/MAPS/GoogleAPI.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -0,0 +1,101 @@ +using System; +using System.Globalization; +using MyWorldmap; + +namespace MyWorldMap.MAPS +{ + internal class GoogleApi : IMapProvider + { + #region Interface required + + public string Version + { + get { return "v2 (static)"; } + } + + public string Documentation + { + get { return "http://code.google.com/apis/maps/documentation/staticmaps"; } + } + + public string Description + { + get { return "Google"; } + } + + public int MaxMapWidth + { + get { return 640; } + } + + public int MinZoom + { + get { return 1; } + } + + public int MaxZoom + { + get { return 21; } + } + + public string UrlGet(MapProperty newMap) + { + NumberFormatInfo ni = Settings.NumberFormat(); + string strType; + string urlFinalFormat; + + switch (newMap.MapType) + { + case MapFunctions.MapType.Hybrid: + strType = "hybrid"; + break; + case MapFunctions.MapType.Road: + strType = "roadmap"; + break; + case MapFunctions.MapType.Satellite: + strType = "satellite"; + break; + case MapFunctions.MapType.Terrain: + strType = "terrain"; + break; + default: + strType = "unknown"; + break; + } + + // Keep aspect ratio + int width = newMap.Width > MaxMapWidth ? MaxMapWidth : newMap.Width; + int height = width*newMap.Height/newMap.Width; + + if (newMap.Latitude == 0 && newMap.Longitude == 0) + { + //World view + urlFinalFormat = UrlFormat; + } + else + { + //Specific view + urlFinalFormat = UrlFormatWithMarker; + } + + return string.Format(urlFinalFormat, strType, Convert.ToString(newMap.Latitude, ni), + Convert.ToString(newMap.Longitude, ni), newMap.Zoom, width + "x" + height); + } + + #endregion + + private static string UrlFormatWithMarker + { + get + { + return + "http://maps.google.com/maps/api/staticmap?maptype={0}¢er={1},{2}&zoom={3}&size={4}&markers=color:red|label:A|{1},{2}&sensor=false"; + } + } + + private static string UrlFormat + { + get { return "http://maps.google.com/maps/api/staticmap?maptype={0}¢er={1},{2}&zoom={3}&size={4}&sensor=false"; } + } + } +} \ No newline at end of file Deleted: trunk/plugins/WorldMap/MAPS/ImageFunctions.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/ImageFunctions.cs 2010-08-21 11:27:15 UTC (rev 3759) +++ trunk/plugins/WorldMap/MAPS/ImageFunctions.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -1,72 +0,0 @@ -using System.Drawing; - -namespace MAPS -{ - internal class ImageFunctions - { - public static Bitmap MergeBitmaps(Bitmap Background, Bitmap Overlay) - { - Graphics graphics = Graphics.FromImage(Background); - graphics.DrawImage(Overlay, 0, 0, Background.Width, Background.Height); - - return new Bitmap(Background); - } - - public static Bitmap GetUpperLeftPart(Bitmap Tile) - { - var tmpBitmap = new Bitmap(256, 256); - Graphics graphic = Graphics.FromImage(tmpBitmap); - - 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) - - return tmpBitmap; - } - - public static Bitmap GetUpperRightPart(Bitmap Tile) - { - var tmpBitmap = new Bitmap(256, 256); - Graphics graphic = Graphics.FromImage(tmpBitmap); - - 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) - { - var tmpBitmap = new Bitmap(256, 256); - Graphics graphic = Graphics.FromImage(tmpBitmap); - - 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); - - return tmpBitmap; - } - - public static Bitmap GetLowerRightPart(Bitmap Tile) - { - var tmpBitmap = new Bitmap(256, 256); - Graphics graphic = Graphics.FromImage(tmpBitmap); - - 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-08-21 11:27:15 UTC (rev 3759) +++ trunk/plugins/WorldMap/MAPS/MapFunctions.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -1,6 +1,6 @@ using System; -namespace MAPS +namespace MyWorldMap.MAPS { public class MapFunctions { @@ -8,13 +8,10 @@ public enum MapType { - GMRoad, - GMTerrain, - GMAerial, - GMHybrid, - VERoad, - VEAerial, - VEHybrid + Road, + Terrain, + Satellite, + Hybrid } #endregion @@ -22,479 +19,19 @@ public static MapType GetNextMapType(MapType currentMapType) { Array tmpMapTypes = Enum.GetValues(typeof (MapType)); - int IntMapType = Convert.ToInt32(currentMapType); - IntMapType++; - if (IntMapType > tmpMapTypes.Length - 1) IntMapType = 0; - return (MapType) (Enum.ToObject(typeof (MapType), IntMapType)); + int intMapType = Convert.ToInt32(currentMapType); + intMapType++; + if (intMapType > tmpMapTypes.Length - 1) intMapType = 0; + return (MapType) (Enum.ToObject(typeof (MapType), intMapType)); } - public static MapType GetNextRoadMap(MapType currentMapType) + public static IMapProvider GetNextProvider(IMapProvider currentProvider) { - if (currentMapType == MapType.GMAerial || currentMapType == MapType.GMHybrid) return MapType.GMRoad; - if (currentMapType == MapType.VEAerial || currentMapType == MapType.VEHybrid) return MapType.VERoad; - if (currentMapType == MapType.GMRoad) return MapType.VERoad; - - return MapType.GMRoad; - } - - public static MapType GetNextSateliteMap(MapType currentMapType) - { - if (currentMapType == MapType.GMRoad || currentMapType == MapType.GMHybrid) return MapType.GMAerial; - if (currentMapType == MapType.VERoad || currentMapType == MapType.VEHybrid) return MapType.VEAerial; - if (currentMapType == MapType.GMAerial) return MapType.VEAerial; - - return MapType.GMAerial; - } - - public static MapType GetNextHybridMap(MapType currentMapType) - { - if (currentMapType == MapType.GMAerial || currentMapType == MapType.GMRoad) return MapType.GMHybrid; - if (currentMapType == MapType.VEAerial || currentMapType == MapType.VERoad) return MapType.VEHybrid; - if (currentMapType == MapType.GMHybrid) return MapType.VEHybrid; - - return MapType.GMHybrid; - } - - /// <summary> - /// Get the vertical tile number from a latitude using mercator ptrojection formula - /// </summary> - public static int ConvertLatitudeToTileY(double latitude, int zoomLevel) - { - double maxlat = Math.PI; - - double lat = latitude; - - if (lat > 90) lat = lat - 180; - if (lat < -90) lat = lat + 180; - - // conversion degre=>radians - 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))); - double maxTileY = Math.Pow(2, zoomLevel); - var result = (int) (((1 - res/maxlat)/2)*(maxTileY)); - - return (result); - } - - /// <summary> - /// Get the horizontal tile number from a longitude using mercator ptrojection formula - /// </summary> - public static int ConvertLongitudeToTileX(double longitude, int zoomLevel) - { - if (longitude > 180) + if (currentProvider == new GoogleApi()) { - longitude = longitude - 360; + return new BingApi(); } - if (longitude < -180) - { - longitude = longitude + 360; - } - - double res = (longitude + 180)/360; - return (int) (res*Math.Pow(2, zoomLevel)); + return new GoogleApi(); } - - /// <summary> - /// get latitude/longitude mini of a tile - /// </summary> - //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) - //{ - // PointF res = new PointF(); - // 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); - } - - 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)); - - return (float) ((2*Math.Atan(Math.Exp(numlatrel)) - Math.PI/2)*180/Math.PI); - } - - public static double ConvertZoomLevelToTileSizeDegree(int zoomLevel) - { - double LevelTileSizeDegrees = 360; - - for (int i = 1; i <= zoomLevel; i++) - { - LevelTileSizeDegrees /= 2; - } - return LevelTileSizeDegrees; - } - - public static int ConvertTileSizeDegreeToZoomLevel(double TileSizeDegree) - { - int zoomLevel = 0; - while (TileSizeDegree < 360) - { - TileSizeDegree *= 2; - zoomLevel++; - } - return zoomLevel; - } - - public static string GetGMapSatUrl(double Longitude, double Latitude, int zoomLevel, ref MapConfig 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 ""; - - int servNum = -1; - - try - { - switch (tileCode[tileCode.Length - 1]) - { - case 'q': - servNum = 0; - break; - case 'r': - servNum = 1; - break; - case 's': - servNum = 2; - break; - case 't': - servNum = 3; - break; - } - } - catch (Exception) - { - } - - string StringServNum; - if (servNum == -1) StringServNum = ""; - else StringServNum = servNum.ToString(); - - string fullurl = string.Format(curConfig.GMAUrl, StringServNum, tileCode); - if (tileCode == "transparent") - { - //fullurl = "http://www.google.com/intl/en_ALL/mapfiles/transparent.png"; - fullurl = "***"; - } - return fullurl; - } - - public static string GetGMapSatUrlTileCode(int TileX, int TileY, int zoomLevel) - { - string tileid = "t"; - double halflat = TileY; /**/ - double locxmin, locxmax, locymin, locymax, locxmoy, locymoy; - - 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; - if ((halflat < locymin) || - (halflat > locymax) || - (TileX < locxmin) || - (TileX > locxmax)) - { - return ("transparent"); - } - if (halflat < locymoy) - { - locymax = locymoy; - if (TileX < locxmoy) - { - /*q quadrant (top left)*/ - tileid += "q"; - locxmax = locxmoy; - } - else - { -/*r quadrant (top right)*/ - tileid += "r"; - locxmin = locxmoy; - } - } - else - { - locymin = locymoy; - if (TileX < locxmoy) - { - /*t quadrant (bottom right)*/ - tileid += "t"; - locxmax = locxmoy; - } - else - { -/*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); - if (tileCode == "") return ""; - - int servNum = -1; - - try - { - switch (tileCode[tileCode.Length - 1]) - { - case 'q': - servNum = 0; - break; - case 'r': - servNum = 1; - break; - case 's': - servNum = 2; - break; - case 't': - servNum = 3; - break; - } - } - catch (Exception) - { - } - - string StringServNum; - if (servNum == -1) StringServNum = ""; - else StringServNum = servNum.ToString(); - - string TileCode = GetGMapTileCode(TileX, TileY, zoomLevel); - 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) - { - string tileCode = GetGMapSatUrlTileCode(TileX, TileY, zoomLevel); - if (tileCode == "") return ""; - - int servNum = -1; - - try - { - switch (tileCode[tileCode.Length - 1]) - { - case 'q': - servNum = 0; - break; - case 'r': - servNum = 1; - break; - case 's': - servNum = 2; - break; - case 't': - servNum = 3; - break; - } - } - catch (Exception) - { - } - - string StringServNum; - if (servNum == -1) StringServNum = ""; - else StringServNum = servNum.ToString(); - - string TileCode = GetGMapTileCode(TileX, TileY, zoomLevel); - string[] urltab = TileCode.Split('_'); - 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) - { - string tileCode = GetGMapSatUrlTileCode(TileX, TileY, zoomLevel); - if (tileCode == "") return ""; - - int servNum = -1; - - try - { - switch (tileCode[tileCode.Length - 1]) - { - case 'q': - servNum = 0; - break; - case 'r': - servNum = 1; - break; - case 's': - servNum = 2; - break; - case 't': - servNum = 3; - break; - } - } - catch (Exception) - { - } - - string StringServNum; - if (servNum == -1) StringServNum = ""; - else StringServNum = servNum.ToString(); - - 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 - return fullurl; - } - - public static string GetGMapTileCode(int TileX, int TileY, int zoomLevel) - { - int localzoom = (17 - zoomLevel); - string tileid = ""; - double numLong = TileX; - double numLat = TileY; - tileid = numLong + "_" + ((int) numLat) + "_" + localzoom; - return tileid; - } - - public static string GetGMTileUrl(MapType mapType, int TileX, int TileY, int zoomLevel, ref MapConfig curConfig) - { - string url = null; - switch (mapType) - { - case MapType.GMTerrain: - url = GetGTerrainUrl(TileX, TileY, zoomLevel, ref curConfig); - break; - case MapType.GMRoad: - url = GetGMapUrl(TileX, TileY, zoomLevel, ref curConfig); - break; - case MapType.GMAerial: - url = GetGMapSatUrl(TileX, TileY, zoomLevel, ref curConfig); - break; - case MapType.GMHybrid: - url = GetGMapSatUrl(TileX, TileY, zoomLevel, ref curConfig); - break; - } - return url; - } - - public static string GetVETileUrl(MapType mapType, int TileX, int TileY, int zoomLevel, ref MapConfig curConfig) - { - string url = null; - string mapTypePreFix = null; - string mapExtension = null; - switch (mapType) - { - case MapType.VERoad: - { - mapTypePreFix = "r"; - mapExtension = ".png"; - } - break; - case MapType.VEAerial: - { - mapTypePreFix = "a"; - mapExtension = ".jpeg"; - } - break; - case MapType.VEHybrid: - { - mapTypePreFix = "h"; - mapExtension = ".jpeg"; - } - break; - } - - string quadKey = VETileToQuadKey(TileX, TileY, zoomLevel); - try - { - url = string.Format(curConfig.VEUrl, mapTypePreFix, quadKey[quadKey.Length - 1], quadKey, mapExtension); - } - catch (Exception) - { - } - return url; - } - - public static string VETileToQuadKey(int TileX, int TileY, int zoomLevel) - { - string quad = ""; - - for (int i = zoomLevel; i > 0; i--) - { - int mask = 1 << (i - 1); - int cell = 0; - - if ((TileX & mask) != 0) - { - cell++; - } - - if ((TileY & mask) != 0) - { - cell += 2; - } - quad += cell; - } - return quad; - } - - public static string GetTileUrl(MapType mapType, int TileX, int TileY, int zoomLevel, ref MapConfig curConfig) - { - string url = null; - - switch (mapType) - { - case MapType.GMAerial: - case MapType.GMHybrid: - case MapType.GMTerrain: - 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); - break; - } - - return url; - } } } \ No newline at end of file Copied: trunk/plugins/WorldMap/MAPS/MapImages.cs (from rev 3579, trunk/plugins/WorldMap/MAPS/MapTiles.cs) =================================================================== --- trunk/plugins/WorldMap/MAPS/MapImages.cs (rev 0) +++ trunk/plugins/WorldMap/MAPS/MapImages.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -0,0 +1,72 @@ +using System.Drawing; +using System.IO; +using System.Net; +using MediaPortal.GUI.Library; + +namespace MyWorldMap.MAPS +{ + public class MapProperty + { + public int Height; + public double Latitude; + public double Longitude; + public MapFunctions.MapType MapType; + public int Width; + public int Zoom; + + public static Bitmap Refresh(IMapProvider provider, MapProperty newMap) + { + string url = provider.UrlGet(newMap); + return Download(url, MyWorldmap.MyWorldMap.DownloadTimeout); + } + + private static Bitmap Download(string url, int timeout) + { + Log.Debug("[MyWorldMap]: Url link = {0}", url); + Log.Debug("[MyWorldMap]: Http timeout = {0}s", timeout); + var httpRequest = (HttpWebRequest) WebRequest.Create(url); + httpRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"; + httpRequest.Timeout = 1000*timeout; + httpRequest.ReadWriteTimeout = 1000*timeout; + httpRequest.Method = "GET"; + httpRequest.Proxy.Credentials = CredentialCache.DefaultCredentials; + HttpWebResponse httpResponse; + + Bitmap tmpImage; + try + { + httpResponse = (HttpWebResponse) httpRequest.GetResponse(); + Stream tmpImageStream = httpResponse.GetResponseStream(); + tmpImage = new Bitmap(tmpImageStream); + } + catch (WebException err) + { + switch (err.Status) + { + case WebExceptionStatus.Timeout: + case WebExceptionStatus.ConnectFailure: + tmpImage = (Bitmap) Image.FromFile(MyWorldmap.MyWorldMap.SkinMediaFolder + "WMTilePlaceholder.jpeg"); + break; + default: + Log.Error("[MyWorldMap]: Download() error: {0}", err.ToString()); + tmpImage = new Bitmap(0, 0); // Empty image + break; + } + } + + Log.Debug("[MyWorldMap]: Downloaded image size = {0}x{1}", tmpImage.Width, tmpImage.Height); + return tmpImage; + } + } + + public interface IMapProvider + { + string Version { get; } + string Documentation { get; } + string Description { get; } + int MaxMapWidth { get; } + int MinZoom { get; } + int MaxZoom { get; } + string UrlGet(MapProperty newMap); + } +} \ No newline at end of file Deleted: trunk/plugins/WorldMap/MAPS/MapTile.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/MapTile.cs 2010-08-21 11:27:15 UTC (rev 3759) +++ trunk/plugins/WorldMap/MAPS/MapTile.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -1,126 +0,0 @@ -using System; -using System.Drawing; - -namespace MAPS -{ - public delegate void ImageChangedEventHandler(object sender, ImageChangedEventArgs e); - - public class ImageChangedEventArgs : EventArgs - { - private int TileX, TileY, ZoomMode; - - public ImageChangedEventArgs(int tileX, int tileY, int zoomMode) - { - TileX = tileX; - TileY = tileY; - ZoomMode = zoomMode; - } - } - - public class MapTile - { - private double _BottomLatitude; - private Bitmap _Image; - private double _LeftLongitude; - private MapFunctions.MapType _mapType; - private int _PosX; - private int _PosY; - private double _RightLongitude; - private double _TileHeightDegree; - private double _TileWidthDegree; - private double _TopLatitude; - private int _ZoomLevel; - - 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; } - set - { - _Image = value; - OnImageChangedEvent(new ImageChangedEventArgs(_PosX, _PosY, _ZoomLevel)); - } - } - - public event ImageChangedEventHandler ImageChangedEvent; - - protected virtual void OnImageChangedEvent(ImageChangedEventArgs e) - { - ImageChangedEvent(this, e); - } - } -} \ No newline at end of file Deleted: trunk/plugins/WorldMap/MAPS/MapTiles.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/MapTiles.cs 2010-08-21 11:27:15 UTC (rev 3759) +++ trunk/plugins/WorldMap/MAPS/MapTiles.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -1,198 +0,0 @@ -using System; -using System.Drawing; - -namespace MAPS -{ - public class MapConfig - { - public string CacheFolder; - public int DaysToKeepCachedDetailedTiles; - public int DaysToKeepCachedOverviewTiles; - public Bitmap DownloadPlaceholder; - public string GMAUrl; - public string GMHUrl; - public string GMRUrl; - public string GMTUrl; - public Bitmap IPBlocked; - 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() - { - CacheFolder = "C:\\"; - ThreadCountGMR = 5; - ThreadCountGMA = 5; - ThreadCountGMH = 5; - ThreadCountGMT = 5; - ThreadCountVER = 5; - ThreadCountVEA = 5; - ThreadCountVEH = 5; - DaysToKeepCachedDetailedTiles = 30; - DaysToKeepCachedDetailedTiles = 200; - } - } - - public delegate void CombinedImageChangedEventHandler(object sender, ImageChangedEventArgs e); - - public class MapTiles - { - public Bitmap combinedTiles; - public Bitmap croppedCombinedTiles; - public ThreadedDownload ImageGrabber; - - public int ImageResolutionX; - public int ImageResolutionY; - - 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 MapTiles(int ImageResulotionX, int ImageResulotionY, MapConfig mapConfig) - { - ImageResolutionX = ImageResulotionX; - ImageResolutionY = ImageResulotionY; - - this.mapConfig = mapConfig; - - ImageGrabber = new ThreadedDownload(mapConfig); - - TileCountX = CalcTileCount(ImageResulotionX + 256); - TileCountY = CalcTileCount(ImageResulotionY + 256); - - combinedTiles = new Bitmap(TileCountX * 256, TileCountY * 256); - } - - public event CombinedImageChangedEventHandler CombinedImageChangedEvent; - - protected virtual void OnCombinedImageChangedEvent(ImageChangedEventArgs e) - { - try - { - CombinedImageChangedEvent(this, e); - } - catch (NullReferenceException) - { - } - } - - public void Refresh() - { - int CenterTileX = MapFunctions.ConvertLongitudeToTileX(Longitude, ZoomLevel); - int CenterTileY = MapFunctions.ConvertLatitudeToTileY(Latitude, ZoomLevel); - - StartTileX = CenterTileX - ((int)(TileCountX / 2)); - StartTileY = CenterTileY - ((int)(TileCountY / 2)); - - 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)); - - double tmpLatitudeDelta; - tmpLatitudeDelta = Latitude - tmpTile.TopLatitude; - if (tmpLatitudeDelta < 0) tmpLatitudeDelta *= -1; - - OffsetY = (int)(256 * (((100 / tmpTile.TileHeightDegree) * tmpLatitudeDelta) / 100)); - - Tiles = new MapTile[TileCountX][]; - - //MapTile tmpTile; - tmpTile = null; - - for (int X = 0; X < TileCountX; X++) - { - Tiles[X] = new MapTile[TileCountY]; - for (int Y = 0; Y < TileCountY; Y++) - { - tmpTile = new MapTile(mapType, StartTileX + X, StartTileY + Y, ZoomLevel); - Tiles[X][Y] = tmpTile; - tmpTile.ImageChangedEvent += new ImageChangedEventHandler(tmpTile_ImageChangedEvent); - ImageGrabber.DownloadImage(Tiles[X][Y]); - } - } - } - - private void tmpTile_ImageChangedEvent(object sender, ImageChangedEventArgs e) - { - lock (combinedTiles) - { - bool newTiles = false; - var tmpTile = (MapTile)sender; - try - { - if (tmpTile == null) - { - return; - } - 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) - { - } - catch (InvalidOperationException) - { - } - catch (ArgumentOutOfRangeException) - { - } - - 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; - - //System.Diagnostics.Debug.WriteLine(OffsetX + " : " + OffsetY + " :: " + cropPosX + " : " + cropPosY); - 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); - } - } - } - - public int CalcTileCount(int Pixel) - { - 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; - } - - public void ClearTileDownloadQueue() - { - ImageGrabber.ClearDownloadQueue(); - } - } -} \ No newline at end of file Modified: trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs 2010-08-21 11:27:15 UTC (rev 3759) +++ trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -5,8 +5,9 @@ using System.IO; using System.Net; using System.Xml; +using MyWorldmap; -namespace MAPS +namespace MyWorldMap.MAPS { internal enum GeoCodeService { @@ -40,39 +41,33 @@ { if (ServiceName == GeoCodeService.GoogleGeoCoding) { - Uri url = GetGoogleAdress(); - string XMLString = GetXMLResult(url); - PushGoogleResultToSearchResult(XMLString); + PushGoogleResultToSearchResult(GetXmlResult(GetGoogleAdress())); } if (ServiceName == GeoCodeService.YahooGeoCoding) { - Uri url = GetYahooAdress(); - string XMLString = GetXMLResult(url); - PushYahooResultToSearchResult(XMLString); + PushYahooResultToSearchResult(GetXmlResult(GetYahooAdress())); } if (ServiceName == GeoCodeService.GeoNames) { - Uri url = GetGeoNamesAdress(); - string XMLString = GetXMLResult(url); - PushGeoNamesResultToSearchResult(XMLString); + PushGeoNamesResultToSearchResult(GetXmlResult(GetGeoNamesAdress())); } } - public string GetXMLResult(Uri url) + public string GetXmlResult(Uri url) { string ret = null; - var 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; httpRequest.Method = "GET"; - HttpWebResponse httpResponse = null; + HttpWebResponse httpResponse; try { - httpResponse = (HttpWebResponse)httpRequest.GetResponse(); + httpResponse = (HttpWebResponse) httpRequest.GetResponse(); Stream tmpStream = httpResponse.GetResponseStream(); using (var reader = new StreamReader(tmpStream)) @@ -88,58 +83,52 @@ return ret; } - public void PushYahooResultToSearchResult(string XMLString) + public void PushYahooResultToSearchResult(string xmlString) { SearchResult = new List<GeoCode>(); SearchResult.Clear(); - if (XMLString == null) return; + if (xmlString == null) return; var doc = new XmlDocument(); - doc.LoadXml(XMLString); + doc.LoadXml(xmlString); - //XmlNode root = doc.DocumentElement; - //XmlNodeList nodes = doc.SelectNodes("//ResultSet/Result"); - //nodes = doc.DocumentElement.SelectNodes("Result"); + if (doc.DocumentElement != null) + { + XmlNodeList nodes = doc.DocumentElement.ChildNodes; - XmlNodeList nodes = doc.DocumentElement.ChildNodes; + NumberFormatInfo ni = Settings.NumberFormat(); - CultureInfo ci = CultureInfo.InstalledUICulture; - var ni = (NumberFormatInfo)ci.NumberFormat.Clone(); - ni.NumberDecimalSeparator = "."; - ni.NumberGroupSeparator = ","; - - foreach (XmlNode node in nodes) - { - var tmpGeoCode = new GeoCode(); - tmpGeoCode.Name = ""; - tmpGeoCode.Street = node["Address"].InnerText; - tmpGeoCode.City = node["City"].InnerText; - tmpGeoCode.State = node["State"].InnerText; - tmpGeoCode.Country = node["Country"].InnerText; - tmpGeoCode.Latitude = double.Parse(node["Latitude"].InnerText, ni); - tmpGeoCode.Longitude = double.Parse(node["Longitude"].InnerText, ni); - SearchResult.Add(tmpGeoCode); + foreach (XmlNode node in nodes) + { + var tmpGeoCode = new GeoCode + { + Name = "", + Street = node["Address"].InnerText, + City = node["City"].InnerText, + State = node["State"].InnerText, + Country = node["Country"].InnerText, + Latitude = double.Parse(node["Latitude"].InnerText, ni), + Longitude = double.Parse(node["Longitude"].InnerText, ni) + }; + SearchResult.Add(tmpGeoCode); + } } } - public void PushGeoNamesResultToSearchResult(string XMLString) + public void PushGeoNamesResultToSearchResult(string xmlString) { SearchResult = new List<GeoCode>(); SearchResult.Clear(); - if (XMLString == null) return; + if (xmlString == null) return; var doc = new XmlDocument(); - doc.LoadXml(XMLString); + doc.LoadXml(xmlString); - XmlNode root = doc.DocumentElement; - //XmlNodeList nodes = doc.SelectNodes("//ResultSet/Result"); - //nodes = doc.DocumentElement.SelectNodes("Result"); - XmlNodeList nodes = doc.DocumentElement.ChildNodes; CultureInfo ci = CultureInfo.InstalledUICulture; - var ni = (NumberFormatInfo)ci.NumberFormat.Clone(); + var ni = (NumberFormatInfo) ci.NumberFormat.Clone(); ni.NumberDecimalSeparator = "."; ni.NumberGroupSeparator = ","; @@ -147,8 +136,10 @@ { if (node.Name == "geoname") { - var tmpGeoCode = new GeoCode(); - tmpGeoCode.Name = node["name"].InnerText; + var tmpGeoCode = new GeoCode + { + Name = node["name"].InnerText + }; try { tmpGeoCode.Name += " (" + node["adminName1"].InnerText + ")"; @@ -164,15 +155,15 @@ } } - public void PushGoogleResultToSearchResult(string XMLString) + public void PushGoogleResultToSearchResult(string xmlString) { SearchResult = new List<GeoCode>(); SearchResult.Clear(); - if (XMLString == null) return; + if (xmlString == null) return; var doc = new XmlDocument(); - doc.LoadXml(XMLString); + doc.LoadXml(xmlString); XmlNode root = doc.DocumentElement; root = root["Response"]; @@ -181,30 +172,32 @@ CultureInfo ci = CultureInfo.InstalledUICulture; - var ni = (NumberFormatInfo)ci.NumberFormat.Clone(); + var ni = (NumberFormatInfo) ci.NumberFormat.Clone(); ni.NumberDecimalSeparator = "."; ni.NumberGroupSeparator = ","; foreach (XmlNode node in nodes) { - if (node.Name == "Status") + switch (node.Name) { - Debug.WriteLine(String.Format("MyWorldMap Google GeoCodeSearch. Request:{0} ReturnCode: {1}", - node["request"].InnerText, node["code"].InnerText)); - } + case "Status": + Debug.WriteLine(String.Format("MyWorldMap Google GeoCodeSearch. Request:{0} ReturnCode: {1}", + node["request"].InnerText, node["code"].InnerText)); + break; + case "Placemark": + var tmpGeoCode = new GeoCode + { + Name = node["address"].InnerText + }; - if (node.Name == "Placemark") - { - var tmpGeoCode = new GeoCode(); - tmpGeoCode.Name = node["address"].InnerText; - - XmlNode PointNode = node["Point"]; - string Coordinates = PointNode.FirstChild.InnerText; - 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); + XmlNode pointNode = node["Point"]; + string coordinates = pointNode.FirstChild.InnerText; + 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); + break; } } } @@ -257,7 +250,6 @@ { if (valuesAdded > 0) url += ","; url += Country; - valuesAdded++; } url = ConvertStringToSafeUrl(url); @@ -271,16 +263,16 @@ public string ConvertStringToSafeUrl(string url) { string ret = string.Empty; - string safeChars = "0123456789" + // Numeric - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic - "abcdefghijklmnopqrstuvwxyz" + - ":-_.!~*'()?\\/=&%"; // special - foreach (char Char in url) + const string safeChars = "0123456789" + // Numeric + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic + "abcdefghijklmnopqrstuvwxyz" + + ":-_.!~*'()?\\/=&%"; + foreach (char ch in url) { - if (safeChars.Contains(Char.ToString())) ret += Char; + if (safeChars.Contains(ch.ToString())) ret += ch; else { - ret += String.Format("%{0:X2}", (int)Char); + ret += String.Format("%{0:X2}", (int) ch); } // convert to % plus the "hex value" } Deleted: trunk/plugins/WorldMap/MAPS/ThreadedDownload.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/ThreadedDownload.cs 2010-08-21 11:27:15 UTC (rev 3759) +++ trunk/plugins/WorldMap/MAPS/ThreadedDownload.cs 2010-08-21 12:53:28 UTC (rev 3760) @@ -1,422 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.IO; -using System.Net; -using System.Threading; - -namespace MAPS -{ - internal delegate void ProcessDownloadQueue(); - - internal delegate void ImageThread(Object stateInfo); - - public class ThreadedDownload - { - public TileCacheDatabase cacheDatabase; - public List<Thread> ImageDownloadThreads = new List<Thread>(); - - public MapConfig mapConfig; - public List<MapTile> QueuedImageDownloads = new List<MapTile>(); - - public ThreadedDownload(MapConfig mapConfig) - { - this.mapConfig = mapConfig; - - var databaseOptions = new DatabaseOptions(); - databaseOptions.cacheFolder = mapConfig.CacheFolder; - databaseOptions.DaysToKeepCachedDetailedTiles = mapConfig.DaysToKeepCachedDetailedTiles; - databaseOptions.DaysToKeepCachedOverviewTiles = mapConfig.DaysToKeepCachedOverviewTiles; - - cacheDatabase = new TileCacheDatabase(databaseOptions); - } - - public void DownloadImage(MapTile mapTile) - { - string FilePreFix = null; - - switch (mapTile.MapType) - { - case MapFunctions.MapType.GMRoad: - FilePreFix = "gmr"; - break; - case MapFunctions.MapType.GMAerial: - FilePreFix = "gma"; - break; - case MapFunctions.MapType.GMHybrid: - FilePreFix = "gmh"; - break; - case MapFunctions.MapType.GMTerrain: - FilePreFix = "gmt"; - break; - case MapFunctions.MapType.VERoad: - FilePreFix = "ver"; - break; - case MapFunctions.MapType.VEAerial: - FilePreFix = "vea"; - break; - case MapFunctions.MapType.VEHybrid: - FilePreFix = "veh"; - break; - } - - Bitmap tmpTileImage = null; - - try - { - tmpTileImage = cacheDatabase.GetImage(FilePreFix, mapTile.PosX, mapTile.PosY, mapTile.ZoomLevel); - if (tmpTileImage != null) - { - mapTile.Image = tmpTileImage; - return; - } - } - catch (NullReferenceException) - { - } - catch (Exception err) - { - Debug.WriteLine(err.ToString()); - } - ; - - //tmpTileImage = GetParentTilePart(FilePreFix,mapTile.PosX, mapTile.PosY, mapTile.ZoomLevel); - - if (tmpTileImage == null) - { - tmpTileImage = mapConfig.DownloadPlaceholder; - } - - mapTile.Image = tmpTileImage; - - //System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(ImageThread), tmpImage); - - QueuedImageDownloads.Add(mapTile); - ProcessDownloadQueue(); - } - - 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); - - int parentX = MapFunctions.ConvertLongitudeToTileX(curLongitude, zoomLevel - 1); - int parentY = MapFunctions.ConvertLatitudeToTileY(curLatitude, zoomLevel - 1); - - try - { - Bitmap parentTile = cacheDatabase.GetImage(mapPreFix, parentX, parentY, (zoomLevel - 1)); - if (parentTile != null) - { - string tmpTileCode = MapFunctions.GetGMapSatUrlTileCode(TileX, TileY, zoomLevel); - switch (tmpTileCode[tmpTileCode.Length - 1]) - { - case 'q': - ret = ImageFunctions.GetUpperLeftPart(parentTile); - break; - case 'r': - ret = ImageFunctions.GetUpperRightPart(parentTile); - break; - case 's': - ret = ImageFunctions.GetLowerLeftPart(parentTile); - break; - case 't': - ret = ImageFunctions.GetLowerRightPart(parentTile); - break; - } - } - } - catch (Exception) - { - } - - return ret; - } - - public void ProcessDownloadQueue() - { - int maxThreadCount = 1; - try - { - switch (QueuedImageDownloads[0].MapType) - { - case MapFunctions.MapType.GMRoad: - maxThreadCount = mapConfig.ThreadCountGMR; - break; - case MapFunctions.MapType.GMAerial: - maxThreadCount = mapConfig.ThreadCountGMA; - break; - case MapFunctions.MapType.GMHybrid: - maxThreadCount = mapConfig.ThreadCountGMH; - break; - case MapFunctions.MapType.GMTerrain: - maxThreadCount = mapConfig.ThreadCountGMT; - break; - case MapFunctions.MapType.VERoad: - maxThreadCount = mapConfig.ThreadCountVER; - break; - case MapFunctions.MapType.VEAerial: - maxThreadCount = mapConfig.ThreadCountVEA; - break; - case MapFunctions.MapType.VEHybrid: - maxThreadCount = mapConfig.ThreadCountVEH; - break; - } - } - catch (Exception) - { - } - - if (ImageDownloadThreads.Count < maxThreadCount) - { - if (QueuedImageDownloads.Count > 0) - { - try - { - MapTile tmpTile = QueuedImageDownloads[0]; - QueuedImageDownloads.RemoveAt(0); - - var t = new Thread(new ParameterizedThreadStart(ImageThread)); - t.Priority = ThreadPriority.BelowNormal; - t.Name = "MyWorldMap-TileDownloader"; - t.IsBackground = true; - ImageDownloadThreads.Add(t); - - t.Start(tmpTile); - } - catch (Exception) - { - } - - //if(QueuedImageDownloads.Count>0) QueuedImageDownloads.RemoveAt(0); - } - } - Debug.WriteLine(QueuedImageDownloads.Count + " : " + ImageDownloadThreads.Count); - } - - public void ClearDownloadQueue() - { - QueuedImageDownloads.Clear(); - - while (ImageThreadIsRunning()) - { - for (int i = 0; i < ImageDownloadThreads.Count; i++) - { - try - { - ImageDownloadThreads[i].Abort(); - //while (ImageDownloadThreads[0].IsAlive) { Thread.Sleep(100); } - - //ImageDownloadThreads.RemoveAt(0); - } - catch (Exception) - { - } - } - Thread.Sleep(250); - } - - - ImageDownloadThreads.Clear(); - - GC.ReRegisterForFinalize(QueuedImageDownloads); - GC.ReRegisterForFinalize(ImageDownloadThreads); - GC.Collect(); - //currentlyRunningThreads = 0; - } - - private bool ImageThreadIsRunning() - { - bool ret = false; - for (int i = 0; i < ImageDownloadThreads.Count; i++) - { - try - { - ret |= ImageDownloadThreads[i].IsAlive; - } - catch (Exception) - { - } - } - return ret; - } - - private void RemoveCurrentThreadFromList() - { - for (int i = 0; i < ImageDownloadThreads.Count; i++) - { - try - { - if (ImageDownloadThreads[i].Equals(Thread.CurrentThread)) - { - try - { - ImageDownloadThreads.RemoveAt(i); - } - catch (Exception) - { - } - } - } - catch (Exception) -... [truncated message content] |