16
16
using System . Diagnostics ;
17
17
using System . Drawing ;
18
18
using System . Drawing . Imaging ;
19
+ using System . IO ;
19
20
using System . Linq ;
20
21
using System . Runtime . CompilerServices ;
21
22
using System . Runtime . InteropServices ;
@@ -350,9 +351,12 @@ void imageLoader()
350
351
if ( _center . GetDistance ( core . Position ) > 30 )
351
352
{
352
353
core . Position = _center ;
353
- //core.Zoom = minzoom;
354
354
}
355
355
356
+ if ( DateTime . Now . Second % 3 == 1 && tileArea != null )
357
+ lock ( tileArea )
358
+ CleanupOldTextures ( tileArea ) ;
359
+
356
360
// wait for current to load
357
361
if ( core . tileLoadQueue . Count > 0 )
358
362
{
@@ -366,15 +370,7 @@ void imageLoader()
366
370
367
371
// current has loaded - process
368
372
generateTextures ( ) ;
369
- // change zoom and loop
370
- if ( core . Zoom >= zoom )
371
- {
372
- //System.Threading.Thread.Sleep(5000);
373
- //core.Zoom = minzoom;
374
- //continue;
375
- }
376
373
377
- //core.Zoom = core.Zoom + 1;
378
374
System . Threading . Thread . Sleep ( 100 ) ;
379
375
}
380
376
}
@@ -403,8 +399,9 @@ public Utilities.Vector3 Velocity
403
399
Vector3 myrpy = Vector3 . UnitX ;
404
400
private bool fogon = true ;
405
401
private Lines _flightPlanLines ;
406
- private DateTime _centerTime ;
407
-
402
+ private DateTime _centerTime ;
403
+ private List < tileZoomArea > tileArea = new List < tileZoomArea > ( ) ;
404
+
408
405
double [ ] convertCoords ( PointLatLngAlt plla )
409
406
{
410
407
var utm = plla . ToUTM ( utmzone ) ;
@@ -716,9 +713,9 @@ private void generateTextures()
716
713
core . LevelsKeepInMemmory = 10 ;
717
714
core . Provider = type ;
718
715
//core.ReloadMap();
719
- List < tileZoomArea > tileArea = new List < tileZoomArea > ( ) ;
720
- //if (center.GetDistance(oldcenter) > 30)
716
+ lock ( tileArea )
721
717
{
718
+ tileArea = new List < tileZoomArea > ( ) ;
722
719
for ( int a = minzoom ; a <= zoom ; a ++ )
723
720
{
724
721
var area2 = new RectLatLng ( _center . Lat , _center . Lng , 0 , 0 ) ;
@@ -751,16 +748,17 @@ private void generateTextures()
751
748
}
752
749
}
753
750
}
754
- }
755
-
756
- //Minimumtile(tileArea);
751
+ }
752
+
753
+ //Minimumtile(tileArea);
754
+
755
+ var totaltiles = 0 ;
756
+ foreach ( var a in tileArea ) totaltiles += a . points . Count ;
757
+ Console . Write ( DateTime . Now . Millisecond + " Total tiles " + totaltiles + " \r " ) ;
758
+ if ( DateTime . Now . Second % 3 == 1 )
759
+ CleanupOldTextures ( tileArea ) ;
757
760
}
758
-
759
- var totaltiles = 0 ;
760
- foreach ( var a in tileArea ) totaltiles += a . points . Count ;
761
- Console . Write ( DateTime . Now . Millisecond + " Total tiles " + totaltiles + " \r " ) ;
762
- if ( DateTime . Now . Second % 3 == 1 )
763
- CleanupOldTextures ( tileArea ) ;
761
+
764
762
//https://wiki.openstreetmap.org/wiki/Zoom_levels
765
763
var C = 2 * Math . PI * 6378137.000 ;
766
764
// horizontal distance by each tile square
@@ -769,7 +767,10 @@ private void generateTextures()
769
767
//https://wiki.openstreetmap.org/wiki/Zoom_levels
770
768
// zoom 20 = 38m
771
769
// get tiles & combine into one
772
- foreach ( var tilearea in tileArea )
770
+ tileZoomArea [ ] talist ;
771
+ lock ( tileArea )
772
+ talist = tileArea . ToArray ( ) ;
773
+ foreach ( var tilearea in talist )
773
774
{
774
775
stile = C * Math . Cos ( _center . Lat ) / Math . Pow ( 2 , tilearea . zoom ) ;
775
776
pxstep = ( int ) ( stile / 45 ) ;
@@ -855,6 +856,8 @@ private void generateTextures()
855
856
}
856
857
857
858
textureid [ p ] = ti ;
859
+
860
+ //File.WriteAllText(p.ToString(), ti.ToJSON());
858
861
}
859
862
}
860
863
catch
0 commit comments