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());
        }
Example #2
0
        void Update()
        {
            Vector2dBounds currentViewPortWebMercBnds = getcurrentViewPortWebMerc();
            bool           bboxChanged = !(_viewPortWebMercBounds.ToString() == currentViewPortWebMercBnds.ToString());
            float          cameraY     = _referenceCamera.transform.localPosition.y;

            //no zoom, no pan -> don't change tiles
            if (cameraY == _previousY && !bboxChanged)
            {
                return;
            }
            _previousY = cameraY;

            //camera moves within one zoom level, and no panning, don't do anything
            if (
                (cameraY > _cameraZoomingRangeMinY && cameraY < _cameraZoomingRangeMaxY) &&
                !bboxChanged
                )
            {
                //no changes, bail
                return;
            }

            _viewPortWebMercBounds = currentViewPortWebMercBnds;

            //panning
            //TODO: move active tiles on pan
            //HACK: just deactivate all active tiles
            //!!!BEWARE!!!: don't compare Vector2d via '==' use 'Equals()'
            if (!_previousWebMercCenter.Equals(_dynamicZoomMap.CenterMercator))
            {
                _previousWebMercCenter = _dynamicZoomMap.CenterMercator;
                var remove = _activeTiles.Keys.ToList();
                foreach (var r in remove)
                {
                    RemoveTile(r);
                }
            }

            Vector3 localPosition = _referenceCamera.transform.position;

            //close to ground, zoom in
            if (cameraY < _cameraZoomingRangeMinY)
            {
                //already at highest level, don't do anything -> camera free to move closer
                if (_dynamicZoomMap.Zoom == _dynamicZoomMap.MaxZoom)
                {
                    return;
                }
                _dynamicZoomMap.SetZoom(_dynamicZoomMap.Zoom + 1);
                //reposition camera at max distance
                localPosition.y = _cameraZoomingRangeMaxY;
                _referenceCamera.transform.localPosition = localPosition;
            }
            //arrived at max distance, zoom out
            else if (cameraY > _cameraZoomingRangeMaxY)
            {
                //already at lowest level, don't do anything -> camera free to move further away
                if (_dynamicZoomMap.Zoom == _dynamicZoomMap.MinZoom)
                {
                    return;
                }
                _dynamicZoomMap.SetZoom(_dynamicZoomMap.Zoom - 1);
                //reposition camera at min distance
                localPosition.y = _cameraZoomingRangeMinY;
                _referenceCamera.transform.localPosition = localPosition;
            }

            //update viewport in case it was changed by switching zoom level
            _viewPortWebMercBounds = getcurrentViewPortWebMerc();

            var tilesNeeded = TileCover.GetWithWebMerc(_viewPortWebMercBounds, _dynamicZoomMap.Zoom);

            var activeTiles = _activeTiles.Keys.ToList();
            List <UnwrappedTileId> toRemove = activeTiles.Except(tilesNeeded).ToList();

            foreach (var t2r in toRemove)
            {
                RemoveTile(t2r);
            }
            var finalTilesNeeded = tilesNeeded.Except(activeTiles);

            foreach (var tile in finalTilesNeeded)
            {
                AddTile(tile);
            }
        }
Example #3
0
        public void Deserialize()
        {
            Vector2dBounds deserializedVector2dBounds = JsonConvert.DeserializeObject <Vector2dBounds>(this.geoCoordinateBoundsStr, JsonConverters.Converters);

            Assert.AreEqual(this.geoCoordinateBoundsObj.ToString(), deserializedVector2dBounds.ToString());
        }