void Start() { var rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = true; _tileController .Where(tile => tile.IsDisposed) .ObserveOn(Scheduler.MainThread) .Subscribe(tile => { _trace.Info(LogCategory, "Remove tile: {0}", tile.ToString()); Destroy(tile.GameObject); }); _tileController .Where(tile => !tile.IsDisposed) .SelectMany(tile => _mapDataLoader.Load(tile) .Select(u => new Tuple <Tile, Union <Element, Mesh> >(tile, u)) .ObserveOn(Scheduler.MainThread) .DoOnCompleted(() => { if (rigidBody.isKinematic) { rigidBody.isKinematic = false; } })) .SubscribeOn(Scheduler.ThreadPool) .ObserveOn(Scheduler.MainThread) .Subscribe(t => t.Item2.Match(e => _modelBuilder.BuildElement(t.Item1, e), m => _modelBuilder.BuildMesh(t.Item1, m))); // NOTE: code below loads region tile by tile. // The region is specified by rectangle defined in world coordinates. //float size = 600; // square side size (in meters) //Scheduler.ThreadPool.Schedule(() => _tileController.OnRegion(new Rectangle(-size / 2, -size / 2, size, size), LevelOfDetails)); }
void Start() { var rigidBody = gameObject.GetComponent <Rigidbody>(); rigidBody.isKinematic = true; _tileController .Where(tile => tile.IsDisposed) .ObserveOn(Scheduler.MainThread) .Subscribe(tile => { _trace.Info(LogCategory, "Remove tile: {0}", tile.ToString()); Destroy(tile.GameObject); }); _tileController .Where(tile => !tile.IsDisposed) .SelectMany(tile => _mapDataLoader.Load(tile) .Select(u => new Tuple <Tile, Union <Element, Mesh> >(tile, u)) .ObserveOn(Scheduler.MainThread) .DoOnCompleted(() => { if (rigidBody.isKinematic) { var position = transform.position; var coordinate = GeoUtils.ToGeoCoordinate(GetWorldZeroPoint(), position.x, position.z); var height = (float)_appManager.GetService <MapElevationLoader>().Load(tile.QuadKey, coordinate); transform.position = new Vector3(position.x, height + 2, position.z); rigidBody.isKinematic = false; } })) .SubscribeOn(Scheduler.ThreadPool) .ObserveOn(Scheduler.MainThread) .Subscribe(t => t.Item2.Match(e => _modelBuilder.BuildElement(t.Item1, e), m => _modelBuilder.BuildMesh(t.Item1, m))); _messageBus .AsObservable <OnZoomRequested>() .Subscribe(msg => { var newLevel = msg.IsZoomOut ? 14 : 16; if (newLevel == _levelOfDetails) { return; } _levelOfDetails = newLevel; _messageBus.Send(new OnZoomChanged(newLevel)); }); // NOTE: code below loads region tile by tile. // The region is specified by rectangle defined in world coordinates. // float size = 600; // square side size (in meters) // Scheduler.ThreadPool.Schedule(() => _tileController.OnRegion(new Rectangle(-size / 2, -size / 2, size, size), _levelOfDetails)); }
// Loads all globe level tiles manually. private void LoadGlobe() { var tileController = _appManager.GetService <ITileController>(); int count = 2; for (var y = 0; y < count; ++y) { for (var x = 0; x < count; ++x) { var quadKey = new QuadKey(x, y, LevelOfDetails); var tile = new Tile(quadKey, tileController.Stylesheet, tileController.Projection); _mapDataLoader .Load(tile) .SubscribeOn(Scheduler.CurrentThread) .ObserveOn(Scheduler.MainThread) .Subscribe(u => u.Match(e => _modelBuilder.BuildElement(tile, e), m => _modelBuilder.BuildMesh(tile, m))); } } }