public IObservable<Unit> addMap(Map map, System.IO.Stream mapContent) { Func<Task> impl = async () => { try { using (var iso = IsolatedStorageFile.GetUserStoreForApplication()) { var filename = fileNameForMap(map); if (iso.FileExists(filename)) iso.DeleteFile(filename); using (var file = iso.CreateFile(filename)) { await mapContent.CopyToAsync(file, 4 * 1024 * 1024); } } } catch (IsolatedStorageException) { mapContent.Dispose(); } using (var ctx = getContext()) { ctx.Maps.InsertOnSubmit(map); ctx.SubmitChanges(); } }; return impl().ToObservable(); }
private string fileNameForMap(Map map) { return string.Format("{0}/{1}.png", MapFolder, map.ServerKey); }
public void deleteMap(Map map) { using (var iso = IsolatedStorageFile.GetUserStoreForApplication()) { var filename = fileNameForMap(map); if (iso.FileExists(filename)) iso.DeleteFile(filename); } using (var ctx = getContext()) { ctx.Maps.Attach(map); ctx.Maps.DeleteOnSubmit(map); ctx.SubmitChanges(); } }
public System.IO.Stream loadMap(Map map) { #if false var splash = "Images/AppIcons/DivMob_QuadratEnd_s_Splash.png"; var resource = App.GetResourceStream(new Uri(splash, UriKind.Relative)); if (resource != null) return resource.Stream; #endif var iso = IsolatedStorageFile.GetUserStoreForApplication(); var filename = fileNameForMap(map); if (iso.FileExists(filename)) { return iso.OpenFile(filename, System.IO.FileMode.Open); } else return null; }
//The corner coordinates of the map dont define an exact rectangle in all cases. Generally, a convex quadrangle is defined. //The represetation on the screen will be in an rectangle. Hence, the corresponding position is calculated. To perform This, //2 lines are definend: One Going from the upper-left corner to the upper right corner of the map. The other one from the lower left corner to the lower right corner of the map. //A cohort of lines is definend by the connection between those lines parametrized by the percentual scale between the cornerpoint of the 2 lines definend in This way. //Analogously 2 lines are definend in the y-Direction which also define a cohort of lines between them. The GPS-Value is at a specific intersection of these cohorts. //These specific lines of the cohorts can be found by solving a quadratic equation. Theses lines define with their parameters the position of the GPS-Value on the map (On a percentual basis). private static Point? PercentilePositionOnMapImpl(Map This, double GPSLatitude, double GPSLongitude) { double a, b, c, d, e, f, g, h; //This-specific values derived form the position of the cornerpoints. a and e are dependent on addtional values and calculated in the position calculation method bool specialCase;//Criterion for the special case mu=-b/d (which leads to a division by zero in the lambda calculus) a = -GPSLongitude + This.NWLong; b = -This.NWLong + This.NELong; c = -This.NWLong + This.SWLong; d = This.NWLong - This.NELong + This.SELong - This.SWLong; e = -GPSLatitude + This.NWLat; f = -This.NWLat + This.NELat; g = -This.NWLat + This.SWLat; h = This.NWLat - This.NELat + This.SELat - This.SWLat; if (b == 0 || g == 0) { //This coordinates are corrupted return null; } //Check d==0 if (d != 0) { if (a - c * b / d == 0) specialCase = true; else specialCase = false; } else specialCase = false; if (specialCase == false) //=>mu!=-b/d { double alpha, beta, gamma;//Coeffizients for the Mitternachts-Equation double discrim;//Discriminant in the Mitternachts-Equation double mu1, mu2, lambda1, lambda2;//Solution-Parameters. As the equation is quadratic two possible solutions exist. alpha = g * d - h * c; beta = e * d - c * f + g * b - a * h; gamma = -a * f + e * b; if (alpha != 0) { discrim = beta * beta - 4 * alpha * gamma; if (discrim < 0) //Equation unsovable return null; mu1 = (-beta + Math.Sqrt(discrim)) / (2 * alpha); mu2 = (-beta - Math.Sqrt(discrim)) / (2 * alpha); lambda1 = -(a + c * mu1) / (b + d * mu1); lambda2 = -(a + c * mu2) / (b + d * mu2); Point p1 = new Point(lambda1, mu1); Point p2 = new Point(lambda2, mu2); if (p1.X > 0 && p1.X < 1 && p1.Y > 0 && p1.Y < 1) return p1; if (p2.X > 0 && p2.X < 1 && p2.Y > 0 && p2.Y < 1) return p2; return null; } else { if (beta != 0) { mu1 = -gamma / beta; lambda1 = -(a + c * mu1) / (b + d * mu1); Point p1 = new Point(lambda1, mu1); if (p1.X > 0 && p1.X < 1 && p1.Y > 0 && p1.Y < 1) return p1; return null; } else { //No mu-Percentile can be calculated as the equation is either unsovable or there are no restriction to mu. //In both cases no representation on the This can be given return null; } } } else //=> mu=-b/d { double lambda, mu; mu = -b / d; if (b * h - f * c != 0) { lambda = -(e * d - b * g) / (b * h - f * c);//Div by Zero Point p = new Point(lambda, mu); return p; } else { //No mu-Percentile can be calculated as the equation is either unsovable or there are no restriction to mu. //In both cases no representation on the This can be given return null; } } }