public void SeveralTiles() { var map = new Map <VectorTile>(_fs); var mapObserver = new Utils.VectorMapObserver(); map.Subscribe(mapObserver); map.Vector2dBounds = Vector2dBounds.World(); map.Zoom = 3; // 64 tiles. map.Update(); _fs.WaitForAllRequests(); Assert.AreEqual(64, mapObserver.Tiles.Count); foreach (var tile in mapObserver.Tiles) { if (!tile.HasError) { Assert.Greater(tile.GeoJson.Length, 41); } else { Assert.GreaterOrEqual(tile.Exceptions.Count, 1, "not set enough exceptions set on 'Tile'"); } } map.Unsubscribe(mapObserver); }
public void World() #endif { var map = new Map <VectorTile>(_fs); map.Vector2dBounds = Vector2dBounds.World(); map.Zoom = 3; var mapObserver = new Utils.VectorMapObserver(); map.Subscribe(mapObserver); map.Update(); #if UNITY_5_6_OR_NEWER IEnumerator enumerator = _fs.WaitForAllRequests(); while (enumerator.MoveNext()) { yield return(null); } #else _fs.WaitForAllRequests(); #endif Assert.AreEqual(64, mapObserver.Tiles.Count); map.Unsubscribe(mapObserver); }
public HashSet <UnwrappedTileId> GetWithWebMerc(Vector2dBounds bounds, int zoom) { _tiles.Clear(); _canonicalTiles.Clear(); if (bounds.IsEmpty()) { return(_tiles); } //stay within WebMerc bounds Vector2d swWebMerc = new Vector2d(Math.Max(bounds.SouthWest.x, -Utils.Constants.WebMercMax), Math.Max(bounds.SouthWest.y, -Utils.Constants.WebMercMax)); Vector2d neWebMerc = new Vector2d(Math.Min(bounds.NorthEast.x, Utils.Constants.WebMercMax), Math.Min(bounds.NorthEast.y, Utils.Constants.WebMercMax)); UnwrappedTileId swTile = WebMercatorToTileId(swWebMerc, zoom); UnwrappedTileId neTile = WebMercatorToTileId(neWebMerc, zoom); for (int x = swTile.X; x <= neTile.X; x++) { for (int y = neTile.Y; y <= swTile.Y; y++) { UnwrappedTileId uwtid = new UnwrappedTileId(zoom, x, y); //hack: currently too many tiles are created at lower zoom levels //investigate formulas, this worked before if (!_canonicalTiles.Contains(uwtid.Canonical)) { _tiles.Add(uwtid); _canonicalTiles.Add(uwtid.Canonical); } } } return(_tiles); }
public void Init() { _className = this.GetType().Name; Runnable.EnableRunnableInEditor(); _allTilesetNames = new string[] { TS_NO_OVERWRITE , TS_FORCE_OVERWRITE , TS_CONCURRENT1 , TS_CONCURRENT2 , TS_CONCURRENT3 , TS_CONCURRENT4 , TS_PRUNE , TS_REINIT }; Vector2d southWest = new Vector2d(48.2174, 16.3662); Vector2d northEast = new Vector2d(48.2310, 16.3877); Vector2dBounds bounds = new Vector2dBounds(southWest, northEast); _tileIds = TileCover.Get(bounds, 19); // delete cache from previous runs string dbFullPath = SQLiteCache.GetFullDbPath(_dbName); if (File.Exists(dbFullPath)) { File.Delete(dbFullPath); } _cache = new SQLiteCache(_maxCacheTileCount, _dbName); }
void AddTiles(Vector2dBounds bounds, int zoom) { var tileCover = TileCover.Get(bounds, zoom); if (zoom == fullZoom) { foreach (var tile in tileCover) { finalTiles.Add(new UnwrappedTileId(tile.Z, tile.X, tile.Y)); } return; } var overlappingTileCover = overlappingTileCoverCache[zoom - _map.Zoom]; foreach (var tile in tileCover) { if (!overlappingTileCover.Contains(tile)) { finalTiles.Add(new UnwrappedTileId(tile.Z, tile.X, tile.Y)); } else { AddTiles(Conversions.TileIdToBounds(tile.X, tile.Y, tile.Z), zoom + 1); } } }
/// <summary> Get a tile cover for the specified bounds and zoom. </summary> /// <param name="bounds"> Geographic bounding box.</param> /// <param name="zoom"> Zoom level. </param> /// <returns> The tile cover set. </returns> /// <example> /// Build a map of Colorado using TileCover: /// <code> /// var sw = new Vector2d(36.997749, -109.0524961); /// var ne = new Vector2d(41.0002612, -102.0609668); /// var coloradoBounds = new Vector2dBounds(sw, ne); /// var tileCover = TileCover.Get(coloradoBounds, 8); /// Console.Write("Tiles Needed: " + tileCover.Count); /// foreach (var id in tileCover) /// { /// var tile = new RasterTile(); /// var parameters = new Tile.Parameters(); /// parameters.Id = id; /// parameters.Fs = MapboxAccess.Instance; /// parameters.MapId = "mapbox://styles/mapbox/outdoors-v10"; /// tile.Initialize(parameters, (Action)(() => /// { /// // Place tiles and load textures. /// })); /// } /// </code> /// </example> public static HashSet <CanonicalTileId> Get(Vector2dBounds bounds, int zoom) { var tiles = new HashSet <CanonicalTileId>(); if (bounds.IsEmpty() || bounds.South > Constants.LatitudeMax || bounds.North < -Constants.LatitudeMax) { return(tiles); } var hull = Vector2dBounds.FromCoordinates( new Vector2d(Math.Max(bounds.South, -Constants.LatitudeMax), bounds.West), new Vector2d(Math.Min(bounds.North, Constants.LatitudeMax), bounds.East)); var sw = CoordinateToTileId(hull.SouthWest, zoom); var ne = CoordinateToTileId(hull.NorthEast, zoom); // Scanlines. for (var x = sw.X; x <= ne.X; ++x) { for (var y = ne.Y; y <= sw.Y; ++y) { tiles.Add(new UnwrappedTileId(zoom, x, y).Canonical); } } return(tiles); }
private void SetZoomToFitBounds(Vector2dBounds targetBounds, Vector2dBounds screenBounds) { // 得到东西差值作为精度差值 var targetLonDelta = targetBounds.East - targetBounds.West; //得到南北差值作为纬度差值 var targetLatDelta = targetBounds.North - targetBounds.South; var screenLonDelta = screenBounds.East - screenBounds.West; var screenLatDelta = screenBounds.North - screenBounds.South; // 维度缩放值 var zoomLatMultiplier = screenLatDelta / targetLatDelta; var zoomLonMultiplier = screenLonDelta / targetLonDelta; var latZoom = Math.Log(zoomLatMultiplier, 2); var lonZoom = Math.Log(zoomLonMultiplier, 2); var zoom = (float)(_mapManager.Zoom + Math.Min(latZoom, lonZoom)); _mapManager.SetZoom(zoom); _mapManager.UpdateMap(); Debug.Log(_mapManager.UnityTileSize); _mapManager.UseCustomScale(3.3f); Debug.Log(_mapManager.UnityTileSize); }
/// <summary> /// Creates a bound from two arbitrary points. Contrary to the constructor, /// this method always creates a non-empty box. /// </summary> /// <param name="a"> The first point. </param> /// <param name="b"> The second point. </param> /// <returns> The convex hull. </returns> public static Vector2dBounds FromCoordinates(Vector2d a, Vector2d b) { var bounds = new Vector2dBounds(a, a); bounds.Extend(b); return(bounds); }
public void SmallBounds() { var a = new Vector2d(0, 0); var b = new Vector2d(10, 10); var bounds = new Vector2dBounds(a, b); Assert.AreEqual("0.00000,0.00000,10.00000,10.00000", bounds.ToString()); }
void Start() { map = new Map <RasterTile>(MapboxAccess.Instance); map.Zoom = 2; map.Vector2dBounds = Vector2dBounds.World(); map.MapId = "mapbox://styles/mapbox/streets-v10"; map.Subscribe(this); map.Update(); }
public void World() { var bounds = Vector2dBounds.World(); Assert.AreEqual(bounds.South, -90); Assert.AreEqual(bounds.West, -180); Assert.AreEqual(bounds.North, 90); Assert.AreEqual(bounds.East, 180); }
void Start() { var map = new Map <RasterTile>(MapboxAccess.Instance); map.Zoom = 2; map.Vector2dBounds = Vector2dBounds.World(); map.MapId = "mapbox://styles/miker256/cj5w36k7r72ev2sr1c1mpnyii"; map.Subscribe(this); map.Update(); }
public void World() { // Zoom > 8 will generate so many tiles that we // might run out of memory. for (int zoom = 0; zoom < 8; ++zoom) { var tiles = TileCover.Get(Vector2dBounds.World(), zoom); Assert.AreEqual(Math.Pow(4, zoom), tiles.Count); } }
public void Hull() { var bounds1 = new Vector2dBounds(new Vector2d(-10, -10), new Vector2d(10, 10)); var bounds2 = Vector2dBounds.FromCoordinates(new Vector2d(10, 10), new Vector2d(-10, -10)); Assert.AreEqual(bounds1.South, bounds2.South); Assert.AreEqual(bounds1.West, bounds2.West); Assert.AreEqual(bounds1.North, bounds2.North); Assert.AreEqual(bounds1.East, bounds2.East); }
public void initializeRasterMap(Vector2 latLong, int zFactor) { var map = new Map <RasterTile>(MapboxAccess.Instance); map.Zoom = zFactor; map.Vector2dBounds = Vector2dBounds.World(); map.Center = new Mapbox.Utils.Vector2d((double)latLong.x, (double)latLong.y); map.Subscribe(this); map.Update(); }
void FetchWorldData(Vector2d coordinates) { _tileScale = (_tileWidthInVoxels / 256f) / Conversions.GetTileScaleInMeters((float)coordinates.x, _zoom); var bounds = new Vector2dBounds(); bounds.Center = coordinates; _raster.SetVector2dBoundsZoom(bounds, _zoom); _elevation.SetVector2dBoundsZoom(bounds, _zoom); _raster.Update(); _elevation.Update(); }
/// <summary> /// iterates through the Dict values and enqueue game objects whose coordinates fit /// within the bound /// </summary> protected virtual void queryObjectsWithinCoordinateBounds(Vector2dBounds bounds) { foreach (CoordinateBoundObject value in GameObjectsInScene.Values) { if (value.coordinates.x.InRange(bounds.North, bounds.South) && value.coordinates.y.InRange(bounds.West, bounds.East)) { ObjectsToLoad.Enqueue(value); } } }
public void Extend() { var bounds1 = new Vector2dBounds(new Vector2d(-10, -10), new Vector2d(10, 10)); var bounds2 = new Vector2dBounds(new Vector2d(-20, -20), new Vector2d(20, 20)); bounds1.Extend(bounds2); Assert.AreEqual(bounds1.South, bounds2.South); Assert.AreEqual(bounds1.West, bounds2.West); Assert.AreEqual(bounds1.North, bounds2.North); Assert.AreEqual(bounds1.East, bounds2.East); }
public void CardinalLimits() { var bounds = new Vector2dBounds(new Vector2d(10, 20), new Vector2d(30, 40)); // SouthWest, first parameter. Assert.AreEqual(bounds.South, 10); Assert.AreEqual(bounds.West, 20); // NorthEast, second parameter. Assert.AreEqual(bounds.North, 30); Assert.AreEqual(bounds.East, 40); }
void Start() { var map = new Map <RasterTile>(MapboxAccess.Instance); map.Zoom = 16; map.Vector2dBounds = Vector2dBounds.World(); //map.Center = new Mapbox.Utils.Vector2d((double)latLong.x, (double)latLong.y); //map.MapId = "mapbox://styles/mapbox/outdoors-v4"; map.MapId = "mapbox://styles/mapbox/streets-v10"; map.Subscribe(this); map.Update(); }
public void SetVector2dBoundsZoom() { var map1 = new Map <RasterTile>(this.fs); var map2 = new Map <RasterTile>(this.fs); map1.Zoom = 3; map1.Vector2dBounds = Vector2dBounds.World(); map2.SetVector2dBoundsZoom(Vector2dBounds.World(), 3); Assert.AreEqual(map1.Tiles.Count, map2.Tiles.Count); }
public override void UpdateTileExtent() { if (!_shouldUpdate) { return; } //update viewport in case it was changed by switching zoom level _viewPortWebMercBounds = getcurrentViewPortWebMerc(); _currentExtent.activeTiles = GetWithWebMerc(_viewPortWebMercBounds, _map.AbsoluteZoom); OnExtentChanged(); }
public void ToVector2d() { var set = TileCover.Get(Vector2dBounds.World(), 5); foreach (var tile in set) { var reverse = TileCover.CoordinateToTileId(tile.ToVector2d(), 5); Assert.AreEqual(tile.Z, reverse.Z); Assert.AreEqual(tile.X, reverse.X); Assert.AreEqual(tile.Y, reverse.Y); } }
public void TileMax() { var map = new Map <RasterTile>(this.fs); map.SetVector2dBoundsZoom(Vector2dBounds.World(), 2); map.Update(); Assert.Less(map.Tiles.Count, Map <RasterTile> .TileMax); // 16 // Should stay the same, ignore requests. map.SetVector2dBoundsZoom(Vector2dBounds.World(), 5); map.Update(); Assert.AreEqual(16, map.Tiles.Count); }
public void IsEmpty() { var bounds1 = new Vector2dBounds(new Vector2d(10, 10), new Vector2d(0, 0)); Assert.IsTrue(bounds1.IsEmpty()); var bounds2 = new Vector2dBounds(new Vector2d(0, 0), new Vector2d(0, 0)); Assert.IsFalse(bounds2.IsEmpty()); var bounds3 = new Vector2dBounds(new Vector2d(0, 0), new Vector2d(10, 10)); Assert.IsFalse(bounds3.IsEmpty()); }
protected override void queryObjectsWithinTileBounds(UnwrappedTileId tileId) { Vector2dBounds bounds = Conversions.TileIdToBounds(tileId); for (int i = 0; i < prefabsHolder.BuildingPrefabList.Count; i++) { CoordinateBoundObject building = prefabsHolder.BuildingPrefabList[i]; if (building.coordinates.x.InRange(bounds.North, bounds.South) && building.coordinates.y.InRange(bounds.West, bounds.East)) { ObjectsToLoad.Enqueue(building); } } }
private void Update() { if (_map.AbsoluteZoom > 5) { throw new System.Exception("Too many tiles! Use a lower zoom level!"); } var tileCover = TileCover.Get(Vector2dBounds.World(), _map.AbsoluteZoom); foreach (var tile in tileCover) { AddTile(new UnwrappedTileId(tile.Z, tile.X, tile.Y)); } }
public override void OnInitialized() { // HACK: don't allow too many tiles to be requested. if (_map.Zoom > 5) { throw new System.Exception("Too many tiles! Use a lower zoom level!"); } var tileCover = TileCover.Get(Vector2dBounds.World(), _map.Zoom); foreach (var tile in tileCover) { AddTile(new UnwrappedTileId(tile.Z, tile.X, tile.Y)); } }
void Update() { //Camera Debugging //Vector3[] frustumCorners = new Vector3[4]; //_cbtpOptions.camera.CalculateFrustumCorners(new Rect(0, 0, 1, 1), _cbtpOptions.camera.transform.position.y, Camera.MonoOrStereoscopicEye.Mono, frustumCorners); //for (int i = 0; i < 4; i++) //{ // var worldSpaceCorner = _cbtpOptions.camera.transform.TransformVector(frustumCorners[i]); // Debug.DrawRay(_cbtpOptions.camera.transform.position, worldSpaceCorner, Color.blue); //} if (!_shouldUpdate) { return; } _elapsedTime += Time.deltaTime; if (_elapsedTime >= _cbtpOptions.updateInterval) { _elapsedTime = 0f; //update viewport in case it was changed by switching zoom level Vector2dBounds _viewPortWebMercBounds = getcurrentViewPortWebMerc(); var tilesToRequest = TileCover.GetWithWebMerc(_viewPortWebMercBounds, _map.AbsoluteZoom); var activeTiles = _activeTiles.Keys.ToList(); List <UnwrappedTileId> toRemove = activeTiles.Except(tilesToRequest).ToList(); foreach (var t2r in toRemove) { RemoveTile(t2r); } var finalTilesNeeded = tilesToRequest.Except(activeTiles); foreach (var tile in activeTiles) { // Reposition tiles in case we panned. RepositionTile(tile); } foreach (var tile in finalTilesNeeded) { AddTile(tile); } } }
public override void UpdateTileExtent() { // HACK: don't allow too many tiles to be requested. if (_map.AbsoluteZoom > 5) { throw new System.Exception("Too many tiles! Use a lower zoom level!"); } var tileCover = TileCover.Get(Vector2dBounds.World(), _map.AbsoluteZoom); foreach (var tile in tileCover) { _currentExtent.activeTiles.Add(new UnwrappedTileId(tile.Z, tile.X, tile.Y)); } OnExtentChanged(); }