private void Update()
        {
            if (!_initialized)
            {
                // Debug.Log("Return");
                return;
            }

            _currentTile = TileCover.CoordinateToTileId(_targetTransform.localPosition.GetGeoPosition(_map.CenterMercator, _map.WorldRelativeScale), _map.Zoom);

            Debug.Log(_targetTransform.localPosition);
            Debug.Log(_targetTransform.localPosition.GetGeoPosition(_map.CenterMercator, _map.WorldRelativeScale));
            Debug.Log("Current Tile");
            Debug.Log(_currentTile);
            //Debug.Log("Position");
            //Debug.Log(_targetTransform.localPosition.GetGeoPosition(_map.CenterMercator, _map.WorldRelativeScale).x);

            //Debug.Log(_targetTransform.localPosition.GetGeoPosition(_map.CenterMercator, _map.WorldRelativeScale).y);

            if (!_currentTile.Equals(_cachedTile))
            {
                //Debug.Log("here");
                // Debug.Log("Different Tile");
                for (int x = _currentTile.X - _visibleBuffer; x <= (_currentTile.X + _visibleBuffer); x++)
                {
                    for (int y = _currentTile.Y - _visibleBuffer; y <= (_currentTile.Y + _visibleBuffer); y++)
                    {
                        AddTile(new UnwrappedTileId(_map.Zoom, x, y));
                    }
                }
                _cachedTile = _currentTile;
                //Cleanup(_currentTile);
            }
            // Debug.Log("End");
        }
Example #2
0
    void UpdateMap()
    {
        if (vector == null)
        {
            vector = new Map <VectorTile>(fs);
            vector.Subscribe(this);

            rawpng = new Map <RawPngRasterTile>(fs);
            rawpng.Subscribe(this);
        }

        vector.SetGeoCoordinateBoundsZoom(new GeoCoordinateBounds(
                                              new GeoCoordinate(South, West),
                                              new GeoCoordinate(North, East)),
                                          Zoom);

        nwAnchor = TileCover.CoordinateToTileId(
            new GeoCoordinate(vector.GeoCoordinateBounds.North, vector.GeoCoordinateBounds.West),
            Zoom).Canonical;

        seAnchor = TileCover.CoordinateToTileId(
            new GeoCoordinate(vector.GeoCoordinateBounds.South, vector.GeoCoordinateBounds.East),
            Zoom).Canonical;

        rawpng.SetGeoCoordinateBoundsZoom(vector.GeoCoordinateBounds, vector.Zoom);
    }
Example #3
0
        public void UpdateMapProperties(Vector2d centerLatitudeLongitude, float zoom)
        {
            if (_shouldUpdate)
            {
                float differenceInZoom = 0.0f;
                SetZoomRange(zoom);
                if (Math.Abs(_map.Zoom - ZoomRange) > Constants.EpsilonFloatingPoint)
                {
                    _map.SetZoom(zoom);
                    differenceInZoom = _map.Zoom - _map.InitialZoom;
                }

                //Update center latitude longitude
                double xDelta = centerLatitudeLongitude.x;
                double zDelta = centerLatitudeLongitude.y;

                xDelta = xDelta > 0 ? Mathd.Min(xDelta, Mapbox.Utils.Constants.LatitudeMax) : Mathd.Max(xDelta, -Mapbox.Utils.Constants.LatitudeMax);
                zDelta = zDelta > 0 ? Mathd.Min(zDelta, Mapbox.Utils.Constants.LongitudeMax) : Mathd.Max(zDelta, -Mapbox.Utils.Constants.LongitudeMax);

                //Set Center in Latitude Longitude and Mercator.
                _map.SetCenterLatitudeLongitude(new Vector2d(xDelta, zDelta));
                _map.SetCenterMercator(Conversions.LatLonToMeters(_map.CenterLatitudeLongitude));
                // Update the center based on current zoom level.
                var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(new Vector2d(xDelta, zDelta), _map.AbsoluteZoom));

                _map.SetWorldRelativeScale((float)(_map.UnityTileSize / referenceTileRect.Size.x));
                //Scale the map accordingly.
                if (Math.Abs(differenceInZoom) > Constants.EpsilonFloatingPoint)
                {
                    _map.Root.localScale = Vector3.one * Mathf.Pow(2, differenceInZoom);
                }
            }
        }
Example #4
0
        public static void SetUpTiles(IMap map)
        {
            tiles = new HashSet <UnwrappedTileId>();
            var end = coordinates.GetUpperBound(0);

            for (var k = 0; k <= end; k += 2)
            {
                leftTiles.Add(TileCover.CoordinateToTileId(new Vector2d(coordinates[k, 0], coordinates[k, 1]), map.AbsoluteZoom));
            }
            for (var k = 1; k <= end; k += 2)
            {
                rightTiles.Add(TileCover.CoordinateToTileId(new Vector2d(coordinates[k, 0], coordinates[k, 1]), map.AbsoluteZoom));
            }

            var j = 0;

            for (var i = 0; i < leftTiles.Count; i++)
            {
                if (i != leftTiles.Count - 1)
                {
                    j = i + 1;
                }
                else
                {
                    j = i;
                }
                for (var y = leftTiles[j].Y; y <= leftTiles[i].Y; y++)
                {
                    for (var x = leftTiles[i].X; x <= rightTiles[i].X; x++)
                    {
                        tiles.Add(new UnwrappedTileId(map.AbsoluteZoom, x, y));
                    }
                }
            }
        }
Example #5
0
        protected override void PlaceTile(UnwrappedTileId tileId, UnityTile tile, IMapReadable map)
        {
            //get the tile covering the center (Unity 0,0,0) of current extent
            UnwrappedTileId centerTile = TileCover.CoordinateToTileId(map.CenterLatitudeLongitude, map.AbsoluteZoom);
            //get center WebMerc corrdinates of tile covering the center (Unity 0,0,0)
            Vector2d centerTileCenter = Conversions.TileIdToCenterWebMercator(centerTile.X, centerTile.Y, map.AbsoluteZoom);
            //calculate distance between WebMerc center coordinates of center tile and WebMerc coordinates exactly at center
            Vector2d shift         = map.CenterMercator - centerTileCenter;
            var      unityTileSize = map.UnityTileSize;
            // get factor at equator to avoid shifting errors at higher latitudes
            float factor      = Conversions.GetTileScaleInMeters(0f, map.AbsoluteZoom) * 256.0f / unityTileSize;
            var   scaleFactor = Mathf.Pow(2, (map.InitialZoom - map.AbsoluteZoom));

            //position the tile relative to the center tile of the current viewport using the tile id
            //multiply by tile size Unity units (unityTileScale)
            //shift by distance of current viewport center to center of center tile
            float   shiftX   = (float)shift.x / factor;
            float   shiftY   = (float)shift.y / factor;
            Vector3 position = new Vector3(
                ((tileId.X - centerTile.X) * unityTileSize - shiftX) * scaleFactor
                , 0
                , ((centerTile.Y - tileId.Y) * unityTileSize - shiftY) * scaleFactor);

            tile.transform.localPosition = position;
        }
Example #6
0
    private void Update()
    {
        if (!_initialized)
        {
            return;
        }

        _elapsedTime += Time.deltaTime;
        if (_elapsedTime >= _updateInterval)
        {
            _elapsedTime   = 0f;
            _currentLatLng = locationMarker.position.GetGeoPosition(map.CenterMercator, map.WorldRelativeScale);

            _currentTile = TileCover.CoordinateToTileId(_currentLatLng, map.Zoom);

            if (!_currentTile.Equals(_cachedTile))
            {
                for (int x = _currentTile.X - _visibleBuffer; x <= (_currentTile.X + _visibleBuffer); x++)
                {
                    for (int y = _currentTile.Y - _visibleBuffer; y <= (_currentTile.Y + _visibleBuffer); y++)
                    {
                        AddTile(new UnwrappedTileId(map.Zoom, x, y));
                    }
                }
                _cachedTile = _currentTile;
                // Cleanup(_currentTile);
            }
        }
    }
Example #7
0
    public double HeightForPrefab(double lat, double lon, BasicMap _map)
    {
        //get tile ID
        //Debug.Log("lat: " + lat + ", long: " + lon);
        var tileIDUnwrapped = TileCover.CoordinateToTileId(new Mapbox.Utils.Vector2d(lat, lon), 15);
        // Debug.Log(tileIDUnwrapped);
        //get tile
        UnityTile tile = _map._mapVisualizer.GetUnityTileFromUnwrappedTileId(tileIDUnwrapped);

        //lat lon to meters because the tiles rect is also in meters
        Vector2d v2d = Conversions.LatLonToMeters(new Mapbox.Utils.Vector2d(lat, lon));
        //get the origin of the tile in meters
        Vector2d v2dcenter = tile.Rect.Center - new Mapbox.Utils.Vector2d(tile.Rect.Size.x / 2, tile.Rect.Size.y / 2);
        //offset between the tile origin and the lat lon point
        Vector2d diff = v2d - v2dcenter;

        //maping the diffetences to (0-1)
        float Dx = (float)(diff.x / tile.Rect.Size.x);
        float Dy = (float)(diff.y / tile.Rect.Size.y);

        //height in unity units
        var h = tile.QueryHeightData(Dx, Dy);

        //lat lon to unity units
        Vector3 location = Conversions.GeoToWorldPosition(lat, lon, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz();

        //replace y in position
        location = new Vector3(location.x, h, location.z);
        //Debug.Log("our height is: " + h);
        return(h);
    }
Example #8
0
        // updates tile rendering at regular intervals
        void Update()
        {
            _timeElapsed += Time.deltaTime;
            if (_timeElapsed >= _updateInterval)
            {
                _timeElapsed = 0; // reset time
                // what the camera is looking at, center of screen
                _ray = _camera.ViewportPointToRay(_viewportTarget);

                if (_groundPlane.Raycast(_ray, out _hitDistance))
                {
                    // geoegraphical coordinates that the camera is looking at
                    _currentLatitudeLongitude = _ray.GetPoint(_hitDistance).GetGeoPosition(_map.CenterMercator, _map.WorldRelativeScale);
                    // Debug.Log(_currentLatitudeLongitude);
                    // tile that the camera is looking at
                    _currentTile = TileCover.CoordinateToTileId(_currentLatitudeLongitude, _map.Zoom);

                    // camera has moved
                    if (!_currentTile.Equals(_cachedTile))
                    {
                        // FIXME: this results in bugs at world boundaries! Does not cleanly wrap. Negative tileIds are bad.
                        // I just make the screen go dark, not a great fix but shouldn't occur anyway
                        for (int x = Mathd.Max(_currentTile.X - _visibleBuffer, 0); x <= (_currentTile.X + _visibleBuffer); x++)
                        {
                            for (int y = Mathd.Max(_currentTile.Y - _visibleBuffer, 0); y <= (_currentTile.Y + _visibleBuffer); y++)
                            {
                                AddTile(new UnwrappedTileId(_map.Zoom, x, y));
                            }
                        }
                        _cachedTile = _currentTile;
                        Cleanup(_currentTile);
                    }
                }
            }
        }
Example #9
0
        public override void UpdateTileExtent()
        {
            if (!_initialized)
            {
                return;
            }

            _currentExtent.activeTiles.Clear();
            //_toRemove.Clear();
            _currentTile = TileCover.CoordinateToTileId(_map.WorldToGeoPosition(_rangeTileProviderOptions.targetTransform.localPosition), _map.AbsoluteZoom);

            if (!_currentTile.Equals(_cachedTile))
            {
                for (int x = _currentTile.X - _rangeTileProviderOptions.visibleBuffer; x <= (_currentTile.X + _rangeTileProviderOptions.visibleBuffer); x++)
                {
                    for (int y = _currentTile.Y - _rangeTileProviderOptions.visibleBuffer; y <= (_currentTile.Y + _rangeTileProviderOptions.visibleBuffer); y++)
                    {
                        _currentExtent.activeTiles.Add(new UnwrappedTileId(_map.AbsoluteZoom, x, y));
                    }
                }

                _cachedTile = _currentTile;
                OnExtentChanged();
            }
        }
Example #10
0
        void UpdateMap()
        {
            if (raster == null)
            {
                raster       = new Map <RasterTile>(fs);
                raster.MapId = string.IsNullOrEmpty(_styleUrl) ? "mapbox://styles/mapbox/satellite-v9" : _styleUrl;
                //to use a custom map style:
                //raster.Source = "mapbox://styles/mapbox/outdoors-v10";
                raster.Subscribe(this);

                rawpng = new Map <RawPngRasterTile>(fs);
                rawpng.Subscribe(this);
            }

            raster.SetGeoCoordinateBoundsZoom(new GeoCoordinateBounds(
                                                  new GeoCoordinate(South, West),
                                                  new GeoCoordinate(North, East)),
                                              Zoom);

            nwAnchor = TileCover.CoordinateToTileId(
                new GeoCoordinate(raster.GeoCoordinateBounds.North, raster.GeoCoordinateBounds.West),
                Zoom).Canonical;

            seAnchor = TileCover.CoordinateToTileId(
                new GeoCoordinate(raster.GeoCoordinateBounds.South, raster.GeoCoordinateBounds.East),
                Zoom).Canonical;

            rawpng.SetGeoCoordinateBoundsZoom(raster.GeoCoordinateBounds, raster.Zoom);
        }
Example #11
0
        void Update()
        {
            if (!_shouldUpdate)
            {
                return;
            }

            _elapsedTime += Time.deltaTime;
            if (_elapsedTime >= _updateInterval)
            {
                _elapsedTime = 0f;
                _ray         = _camera.ViewportPointToRay(_viewportTarget);
                if (_groundPlane.Raycast(_ray, out _hitDistance))
                {
                    _currentLatitudeLongitude = _ray.GetPoint(_hitDistance).GetGeoPosition(_map.CenterMercator, _map.WorldRelativeScale);
                    _currentTile = TileCover.CoordinateToTileId(_currentLatitudeLongitude, _map.Zoom);

                    if (!_currentTile.Equals(_cachedTile))
                    {
                        // FIXME: this results in bugs at world boundaries! Does not cleanly wrap. Negative tileIds are bad.
                        for (int x = _currentTile.X - _visibleBuffer; x <= (_currentTile.X + _visibleBuffer); x++)
                        {
                            for (int y = _currentTile.Y - _visibleBuffer; y <= (_currentTile.Y + _visibleBuffer); y++)
                            {
                                AddTile(new UnwrappedTileId(_map.Zoom, x, y));
                            }
                        }
                        _cachedTile = _currentTile;
                        Cleanup(_currentTile);
                    }
                }
            }
        }
    /*
     * Get the altitude of a lnt/lat location
     */
    float GetLocationHeight(Vector2d location)
    {
        //Get tile ID
        var tileIDUnwrapped = TileCover.CoordinateToTileId(new Mapbox.Utils.Vector2d(location[0], location[1]), (int)map.Zoom);

        //Get tile
        try
        {
            UnityTile tile = map.MapVisualizer.GetUnityTileFromUnwrappedTileId(tileIDUnwrapped);
            //Lat lon to meters because the tiles rect is also in meters
            Vector2d v2d = Conversions.LatLonToMeters(new Mapbox.Utils.Vector2d(location[0], location[1]));
            //Get the origin of the tile in meters
            Vector2d v2dcenter = tile.Rect.Center - new Mapbox.Utils.Vector2d(tile.Rect.Size.x / 2, tile.Rect.Size.y / 2);
            //Offset between the tile origin and the lat lon point
            Vector2d diff = v2d - v2dcenter;
            //Maping the diffetences to (0-1)
            float Dx = (float)(diff.x / tile.Rect.Size.x);
            float Dy = (float)(diff.y / tile.Rect.Size.y);
            //returns height in unity units
            return(tile.QueryHeightData(Dx, Dy));
        }
        catch (Exception e)
        {
            Mapbox.Unity.Utilities.Console.Instance.Log("ERROR", "red");
        }
        return(480f);
    }
        public override void Initialize(Vector2d latLon, int zoom)
        {
            _worldHeightFixed        = false;
            _centerLatitudeLongitude = latLon;
            _zoom = zoom;

            var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(_centerLatitudeLongitude, _zoom));

            _centerMercator = referenceTileRect.Center;

            _worldRelativeScale = _useRelativeScale ? Mathf.Cos(Mathf.Deg2Rad * (float)_centerLatitudeLongitude.x) : 1f;

            // The magic line.
            _root.localPosition = -Conversions.GeoToWorldPosition(_centerLatitudeLongitude.x, _centerLatitudeLongitude.y, _centerMercator, _worldRelativeScale).ToVector3xz();

            //print("_centerLatitudeLongitude.x = " + _centerLatitudeLongitude.x + "_centerLatitudeLongitude.y = " + _centerLatitudeLongitude.y);
            //print("_centerMercator = " + _centerMercator + "_worldRelativeScale = " + _worldRelativeScale);
            //print("_root.localPosition = " + _root.localPosition);
            sFlightRadar myFlightRadar = GameObject.Find("Boss").GetComponent <sFlightRadar>();

            myFlightRadar.myWorldRelativeScale = _worldRelativeScale;
            myFlightRadar.myCenterMercator     = _centerMercator;
            myFlightRadar.myPosShift           = _root.localPosition;
            string[] myLatLonArray = _latitudeLongitudeString.Split(new char[] { ',', ' ' });
            myFlightRadar.myStartLatitude  = myLatLonArray[0];
            myFlightRadar.myStartLongitude = myLatLonArray[1];

            print("myStartLatitude = " + myFlightRadar.myStartLatitude + "myStartLongitude = " + myFlightRadar.myStartLongitude);

            _mapVisualizer.Initialize(this, _fileSouce);
            _tileProvider.Initialize(this);

            SendInitialized();
        }
Example #14
0
        public void level2()
        {
            Mouse_Touch = FindObjectOfType <Mouse_Touch>();
            Debug.Log("Abstract Map");

            var latLonSplit = _latitudeLongitudeString.Split(',');

            _mapCenterLatitudeLongitude = new Vector2d(double.Parse(latLonSplit[0]), double.Parse(latLonSplit[1]));

            var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(_mapCenterLatitudeLongitude, _zoom));

            _mapCenterMercator = referenceTileRect.Center;

            _worldRelativeScale = (float)(_unityTileSize / referenceTileRect.Size.x);
            Root.localScale     = Vector3.one * _worldRelativeScale;

            _mapVisualizer.Initialize(this, _fileSouce);
            _tileProvider.Initialize(this);

            OnInitialized();

            Debug.Log("Finish");
            FindObjectOfType <PositionWithLocationProvider>().getLocation();
            //FindObjectOfType<BuildMapAtLocation>().startGPS();
        }
Example #15
0
        public void GenerateMyMap()
        {
            _fileSouce = MapboxAccess.Instance;
            _tileProvider.OnTileAdded   += TileProvider_OnTileAdded;
            _tileProvider.OnTileRemoved += TileProvider_OnTileRemoved;
            if (!_root)
            {
                _root = transform;
            }
            var latLonSplit = _latitudeLongitudeString.Split(',');

            _mapCenterLatitudeLongitude = new Vector2d(double.Parse(latLonSplit[0]), double.Parse(latLonSplit[1]));

            var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(_mapCenterLatitudeLongitude, _zoom));

            _mapCenterMercator = referenceTileRect.Center;

            _worldRelativeScale = (float)(_unityTileSize / referenceTileRect.Size.x);
            Root.localScale     = Vector3.one * _worldRelativeScale;

            _mapVisualizer.Initialize(this, _fileSouce);
            _tileProvider.Initialize(this);

            OnInitialized();
        }
Example #16
0
    //Get the Tile Material from the Mapbox
    public UnityTile getTileAt(double lat, double lon)
    {
        //get tile ID
        var tileIDUnwrapped = TileCover.CoordinateToTileId(new Vector2d(lat, lon), (int)_map.Zoom);

        //get tile
        return(_map.MapVisualizer.GetUnityTileFromUnwrappedTileId(tileIDUnwrapped));
    }
    /// <summary>
    /// updates mapCenterMercator and localScale in response to a new zoom value set
    /// </summary>
    private void UpdateOnNewZoomLevelSet()
    {
        var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(_mapCenterLatitudeLongitude, _zoom));

        CenterMercator     = referenceTileRect.Center;
        WorldRelativeScale = (float)(UnityTileSize / referenceTileRect.Size.x);
        Root.localScale    = Vector3.one * _worldRelativeScale;
        CorrectCenterLatitudeLongitude();
    }
Example #18
0
    public static void MoveMapToCoordinateAsCenter(Vector2d CoordinateToMoveTowards)
    {
        // find the tile id of the parent
        UnwrappedTileId parentTileId = TileCover.CoordinateToTileId(CoordinateToMoveTowards, CustomMap.Instance.Zoom);

        // hide all building info tables
        InteractibleMap.Instance.HideAllTables();

        // using event just as a placeholder
        onTileJump.Invoke(parentTileId);
    }
        void Build()
        {
            var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(_mapCenterLatitudeLongitude, _zoom));

            _mapCenterMercator = referenceTileRect.Center;
            _mapVisualizer.Initialize(this, _fileSouce);
            _tileProvider.Initialize(this);
#if !UNITY_EDITOR
            _root.localPosition = -Conversions.GeoToWorldPosition(_mapCenterLatitudeLongitude.x, _mapCenterLatitudeLongitude.y, _mapCenterMercator, 1f).ToVector3xz();
#endif
            OnInitialized();
        }
Example #20
0
        protected override void OnInitialized()
        {
            var centerTile = TileCover.CoordinateToTileId(_map.CenterLatitudeLongitude, _map.Zoom);

            for (int x = (int)(centerTile.X - _range.x); x <= (centerTile.X + _range.z); x++)
            {
                for (int y = (int)(centerTile.Y - _range.y); y <= (centerTile.Y + _range.w); y++)
                {
                    AddTile(new UnwrappedTileId(_map.Zoom, x, y));
                }
            }
        }
Example #21
0
        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);
            }
        }
Example #22
0
        public override void OnInitialized()
        {
            var centerTile = TileCover.CoordinateToTileId(_map.CenterLatitudeLongitude, _map.AbsoluteZoom);

            AddTile(new UnwrappedTileId(_map.AbsoluteZoom, centerTile.X, centerTile.Y));
            for (int x = (int)(centerTile.X - _west); x <= (centerTile.X + _east); x++)
            {
                for (int y = (int)(centerTile.Y - _north); y <= (centerTile.Y + _south); y++)
                {
                    AddTile(new UnwrappedTileId(_map.AbsoluteZoom, x, y));
                }
            }
        }
Example #23
0
    /// <summary>
    /// finds the tile object that should parent the building with a latitude/longitude
    /// </summary>
    public static GameObject FindParentTile(Vector2d latLong)
    {
        UnwrappedTileId parentTile = TileCover.CoordinateToTileId(latLong, CustomMap.Instance.Zoom);
        GameObject      tileObject;

        if (CustomRangeTileProvider.InstantiatedTiles.TryGetValue(parentTile, out tileObject))
        {
            return(tileObject);
        }
        else
        {
            return(null);
        }
    }
        public override void UpdateTileExtent()
        {
            if (!_initialized || Options == null)
            {
                return;
            }

            _currentExtent.activeTiles.Clear();
            //_toRemove.Clear();
            var centerTile = TileCover.CoordinateToTileId(_map.CenterLatitudeLongitude, _map.AbsoluteZoom);

            _currentExtent.activeTiles.Add(new UnwrappedTileId(_map.AbsoluteZoom, centerTile.X, centerTile.Y));

            for (int x = (centerTile.X - _rangeTileProviderOptions.west); x <= (centerTile.X + _rangeTileProviderOptions.east); x++)
            {
                for (int y = (centerTile.Y - _rangeTileProviderOptions.north); y <= (centerTile.Y + _rangeTileProviderOptions.south); y++)
                {
                    _currentExtent.activeTiles.Add(new UnwrappedTileId(_map.AbsoluteZoom, x, y));
                }
            }

            OnExtentChanged();
            //foreach (var item in _activeTiles)
            //{
            //	if (!_tilesToRequest.Contains(item.Key))
            //	{
            //		_toRemove.Add(item.Key);
            //	}
            //}

            //foreach (var t2r in _toRemove)
            //{
            //	RemoveTile(t2r);
            //}

            //foreach (var tile in _activeTiles)
            //{
            //	// Reposition tiles in case we panned.
            //	RepositionTile(tile.Key);
            //}

            //foreach (var tile in _tilesToRequest)
            //{
            //	if (!_activeTiles.ContainsKey(tile))
            //	{
            //		AddTile(tile);
            //	}
            //}
        }
Example #25
0
        public override void Initialize(Vector2d latLon, int zoom)
        {
            _worldHeightFixed        = false;
            _centerLatitudeLongitude = latLon;
            _zoom = zoom;

            var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(_centerLatitudeLongitude, _zoom));

            _centerMercator = referenceTileRect.Center;

            _worldRelativeScale = (float)(_unityTileSize / referenceTileRect.Size.x);
            _mapVisualizer.Initialize(this, _fileSouce);
            _tileProvider.Initialize(this);

            SendInitialized();
        }
    /// <summary>
    /// finds the tile gameObject that is directly below the center of the polygon
    /// and set its transform to polygon's parent transform
    /// </summary>
    private Vector2d setPolygonParentToMapTile(GameObject polygon)
    {
        Vector2d        polygonCoordinates = LocationHelper.WorldPositionToGeoCoordinate(polygon.transform.position);
        UnwrappedTileId parentTileId       = TileCover.CoordinateToTileId(polygonCoordinates, CustomMap.Instance.Zoom);
        GameObject      parentTileObject   = null;

        if (CustomRangeTileProvider.InstantiatedTiles.TryGetValue(parentTileId, out parentTileObject))
        {
            polygon.transform.SetParent(parentTileObject.transform, true);
        }
        else
        {
            Debug.Log("Parent not found!");
        }
        return(polygonCoordinates);
    }
Example #27
0
        private static HashSet <UnwrappedTileId> Test(IMap map)
        {
            var latLng     = new Vector2d(map.CenterLatitudeLongitude.x, map.CenterLatitudeLongitude.y);
            var centerTile = TileCover.CoordinateToTileId(latLng, map.AbsoluteZoom);

            Tiles.Add(new UnwrappedTileId(map.AbsoluteZoom, centerTile.X, centerTile.Y));

            for (var x = (centerTile.X - 1); x <= (centerTile.X + 1); x++)
            {
                for (var y = (centerTile.Y - 1); y <= (centerTile.Y + 1); y++)
                {
                    Tiles.Add(new UnwrappedTileId(map.AbsoluteZoom, x, y));
                }
            }

            return(Tiles);
        }
Example #28
0
        public override void Initialize(Vector2d latLon, int zoom)
        {
            _worldHeightFixed        = false;
            _centerLatitudeLongitude = latLon;
            _zoom = zoom;

            var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(_centerLatitudeLongitude, _zoom));

            // FIXME: The only difference from BasicMap? Can we solve this another way?
            _centerMercator     = Conversions.LatLonToMeters(_centerLatitudeLongitude);
            _worldRelativeScale = (float)(1f / referenceTileRect.Size.x);

            _mapVisualizer.Initialize(this, _fileSouce);
            _tileProvider.Initialize(this);

            SendInitialized();
        }
Example #29
0
        private void Update()
        {
            if (!_initialized)
            {
                return;
            }

            if (Options == null)
            {
                return;
            }
            var activeTiles = _activeTiles.Keys.ToList();

            List <UnwrappedTileId> tilesToRequest = new List <UnwrappedTileId>();
            var centerTile = TileCover.CoordinateToTileId(_map.CenterLatitudeLongitude, _map.AbsoluteZoom);

            tilesToRequest.Add(new UnwrappedTileId(_map.AbsoluteZoom, centerTile.X, centerTile.Y));

            for (int x = (int)(centerTile.X - _rangeTileProviderOptions.west); x <= (centerTile.X + _rangeTileProviderOptions.east); x++)
            {
                for (int y = (int)(centerTile.Y - _rangeTileProviderOptions.north); y <= (centerTile.Y + _rangeTileProviderOptions.south); y++)
                {
                    tilesToRequest.Add(new UnwrappedTileId(_map.AbsoluteZoom, x, y));
                }
            }

            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);
            }
        }
Example #30
0
        // This is the part that is abstract?
        protected virtual void Start()
        {
            var latLonSplit = _latitudeLongitudeString.Split(',');

            _mapCenterLatitudeLongitude = new Vector2d(double.Parse(latLonSplit[0]), double.Parse(latLonSplit[1]));

            var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(_mapCenterLatitudeLongitude, _zoom));

            _mapCenterMercator = referenceTileRect.Center;

            _worldRelativeScale = (float)(_unityTileSize / referenceTileRect.Size.x);
            Root.localScale     = Vector3.one * _worldRelativeScale;

            _mapVisualizer.Initialize(this, _fileSouce);
            _tileProvider.Initialize(this);

            OnInitialized();
        }