/// <summary>
        /// Creates the non-flat terrain using a height multiplier
        /// </summary>
        /// <param name="tile"></param>
        /// <param name="heightMultiplier">Multiplier for queried height value</param>
        private void CreateTerrainHeight(UnityTile tile)
        {
            tile.HeightDataState = TilePropertyState.Loading;
            var pngRasterTile = new RawPngRasterTile();

            tile.AddTile(pngRasterTile);
            Progress++;

            pngRasterTile.Initialize(_fileSource, tile.CanonicalTileId, _mapId, () =>
            {
                if (pngRasterTile.HasError)
                {
                    tile.HeightDataState = TilePropertyState.Error;

                    // Handle missing elevation from server (404)!
                    // TODO: optimize this search!
                    if (pngRasterTile.ExceptionsAsString.Contains("404"))
                    {
                        ResetToFlatMesh(tile);
                    }
                    Progress--;
                    return;
                }

                tile.SetHeightData(pngRasterTile.Data, _heightModifier, _useRelativeHeight);
                GenerateTerrainMesh(tile);
                Progress--;
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the non-flat terrain using a height multiplier
        /// </summary>
        /// <param name="tile"></param>
        // <param name="heightMultiplier">Multiplier for queried height value</param>
        private void CreateTerrainHeight(UnityTile tile)
        {
            tile.HeightDataState = TilePropertyState.Loading;
            var pngRasterTile = new RawPngRasterTile();

            tile.AddTile(pngRasterTile);
            Progress++;

            pngRasterTile.Initialize(_fileSource, tile.CanonicalTileId, MapId, () =>
            {
                if (tile == null)
                {
                    return;
                }

                if (pngRasterTile.HasError)
                {
                    OnErrorOccurred(new TileErrorEventArgs(tile.CanonicalTileId, pngRasterTile.GetType(), tile, pngRasterTile.Exceptions));
                    tile.HeightDataState = TilePropertyState.Error;

                    // Handle missing elevation from server (404)!
                    // TODO: optimize this search!
                    if (pngRasterTile.ExceptionsAsString.Contains("404"))
                    {
                        ResetToFlatMesh(tile);
                    }
                    Progress--;
                    return;
                }

                tile.SetHeightData(pngRasterTile.Data, _elevationOptions.requiredOptions.exaggerationFactor);
                GenerateTerrainMesh(tile);
                Progress--;
            });
        }
Ejemplo n.º 3
0
        internal override void OnRegistered(UnityTile tile)
        {
            var vectorTile = new VectorTile();

            tile.AddTile(vectorTile);

            Progress++;
            vectorTile.Initialize(_fileSource, tile.CanonicalTileId, _mapId, () =>
            {
                if (vectorTile.HasError)
                {
                    tile.VectorDataState = TilePropertyState.Error;
                    Progress--;
                    return;
                }

                _cachedData.Add(tile, vectorTile);

                // FIXME: we can make the request BEFORE getting a response from these!
                if (tile.HeightDataState == TilePropertyState.Loading ||
                    tile.RasterDataState == TilePropertyState.Loading)
                {
                    tile.OnHeightDataChanged += DataChangedHandler;
                    tile.OnRasterDataChanged += DataChangedHandler;
                }
                else
                {
                    CreateMeshes(tile);
                }
            });
        }
Ejemplo n.º 4
0
        internal override void OnRegistered(UnityTile tile)
        {
            RasterTile rasterTile;

            if (_mapId.StartsWith("mapbox://", StringComparison.Ordinal))
            {
                rasterTile = _useRetina ? new RetinaRasterTile() : new RasterTile();
            }
            else
            {
                rasterTile = _useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile();
            }

            tile.RasterDataState = TilePropertyState.Loading;

            tile.AddTile(rasterTile);
            Progress++;
            rasterTile.Initialize(_fileSource, tile.CanonicalTileId, _mapId, () =>
            {
                if (rasterTile.HasError)
                {
                    tile.RasterDataState = TilePropertyState.Error;
                    Progress--;
                    return;
                }

                tile.SetRasterData(rasterTile.Data, _useMipMap, _useCompression);
                tile.RasterDataState = TilePropertyState.Loaded;
                Progress--;
            });
        }
Ejemplo n.º 5
0
    //tile here should be totally optional and used only not to have keep a dictionary in terrain factory base
    public void FetchImage(CanonicalTileId canonicalTileId, string mapid, UnityTile tile = null, bool useRetina = false)
    {
        RasterTile rasterTile;

        if (mapid.StartsWith("mapbox://", StringComparison.Ordinal))
        {
            rasterTile = useRetina ? new RetinaRasterTile() : new RasterTile();
        }
        else
        {
            rasterTile = useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile();
        }

        if (tile != null)
        {
            tile.AddTile(rasterTile);
        }

        rasterTile.Initialize(_fileSource, tile.CanonicalTileId, mapid, () =>
        {
            if (rasterTile.HasError)
            {
                FetchingError(tile, new TileErrorEventArgs(tile.CanonicalTileId, rasterTile.GetType(), tile, rasterTile.Exceptions));
                return;
            }

            DataRecieved(tile, rasterTile);
        });
    }
Ejemplo n.º 6
0
        internal override void OnRegistered(UnityTile tile)
        {
            var vectorTile = (_properties.useOptimizedStyle) ? new VectorTile(_properties.optimizedStyle.Id, _properties.optimizedStyle.Modified) : new VectorTile();

            tile.AddTile(vectorTile);

            if (string.IsNullOrEmpty(MapId) || _properties.sourceOptions.isActive == false || _properties.vectorSubLayers.Count == 0)
            {
                // Do nothing;
                Progress++;
                Progress--;
            }
            else
            {
                vectorTile.Initialize(_fileSource, tile.CanonicalTileId, MapId, () =>
                {
                    if (tile == null)
                    {
                        Progress++;
                        Progress--;
                        return;
                    }

                    if (vectorTile.HasError)
                    {
                        OnErrorOccurred(new TileErrorEventArgs(tile.CanonicalTileId, vectorTile.GetType(), tile, vectorTile.Exceptions));
                        tile.VectorDataState = TilePropertyState.Error;
                        Progress++;
                        Progress--;
                        return;
                    }

                    if (_cachedData.ContainsKey(tile))
                    {
                        _cachedData[tile] = vectorTile;
                    }
                    else
                    {
                        _cachedData.Add(tile, vectorTile);
                    }

                    // FIXME: we can make the request BEFORE getting a response from these!
                    if (tile.HeightDataState == TilePropertyState.Loading ||
                        tile.RasterDataState == TilePropertyState.Loading)
                    {
                        tile.OnHeightDataChanged += DataChangedHandler;
                        tile.OnRasterDataChanged += DataChangedHandler;
                    }
                    else
                    {
                        CreateMeshes(tile);
                    }
                });
            }
        }
    //tile here should be totally optional and used only not to have keep a dictionary in terrain factory base
    public void FetchVector(CanonicalTileId canonicalTileId, string mapid, UnityTile tile = null, bool useOptimizedStyle = false, Style style = null)
    {
        var vectorTile = (useOptimizedStyle) ? new VectorTile(style.Id, style.Modified) : new VectorTile();

        tile.AddTile(vectorTile);
        vectorTile.Initialize(_fileSource, tile.CanonicalTileId, mapid, () =>
        {
            if (vectorTile.HasError)
            {
                FetchingError(tile, new TileErrorEventArgs(tile.CanonicalTileId, vectorTile.GetType(), tile, vectorTile.Exceptions));
                tile.VectorDataState = TilePropertyState.Error;
                return;
            }

            DataRecieved(tile, vectorTile);
        });
    }
Ejemplo n.º 8
0
        internal override void OnRegistered(UnityTile tile)
        {
            if (_properties.sourceType == ImagerySourceType.None)
            {
                Progress++;
                Progress--;
                return;
            }

            RasterTile rasterTile;

            if (MapId.StartsWith("mapbox://", StringComparison.Ordinal))
            {
                rasterTile = _properties.rasterOptions.useRetina ? new RetinaRasterTile() : new RasterTile();
            }
            else
            {
                rasterTile = _properties.rasterOptions.useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile();
            }

            tile.RasterDataState = TilePropertyState.Loading;

            tile.AddTile(rasterTile);
            Progress++;
            rasterTile.Initialize(_fileSource, tile.CanonicalTileId, MapId, () =>
            {
                if (tile == null)
                {
                    Progress--;
                    return;
                }

                if (rasterTile.HasError)
                {
                    OnErrorOccurred(new TileErrorEventArgs(tile.CanonicalTileId, rasterTile.GetType(), tile, rasterTile.Exceptions));
                    tile.RasterDataState = TilePropertyState.Error;
                    Progress--;
                    return;
                }

                tile.SetRasterData(rasterTile.Data, _properties.rasterOptions.useMipMap, _properties.rasterOptions.useCompression);
                tile.RasterDataState = TilePropertyState.Loaded;
                Progress--;
            });
        }
Ejemplo n.º 9
0
        internal override void OnRegistered(UnityTile tile)
        {
            var vectorTile = new VectorTile();

            tile.AddTile(vectorTile);


            vectorTile.Initialize(_fileSource, tile.CanonicalTileId, _mapId, () =>
            {
                if (tile == null)
                {
                    return;
                }

                if (vectorTile.HasError)
                {
                    OnErrorOccurred(new TileErrorEventArgs(tile.CanonicalTileId, vectorTile.GetType(), tile, vectorTile.Exceptions));
                    tile.VectorDataState = TilePropertyState.Error;
                    return;
                }

                if (_cachedData.ContainsKey(tile))
                {
                    _cachedData[tile] = vectorTile;
                }
                else
                {
                    _cachedData.Add(tile, vectorTile);
                }

                // FIXME: we can make the request BEFORE getting a response from these!
                if (tile.HeightDataState == TilePropertyState.Loading ||
                    tile.RasterDataState == TilePropertyState.Loading)
                {
                    tile.OnHeightDataChanged += DataChangedHandler;
                    tile.OnRasterDataChanged += DataChangedHandler;
                }
                else
                {
                    CreateMeshes(tile);
                }
            });
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates the non-flat terrain using a height multiplier
        /// </summary>
        /// <param name="tile"></param>
        /// <param name="heightMultiplier">Multiplier for queried height value</param>
        private void CreateTerrainHeight(UnityTile tile)
        {
            tile.HeightDataState = TilePropertyState.Loading;
            var pngRasterTile = new RawPngRasterTile();

            tile.AddTile(pngRasterTile);
            Progress++;

            pngRasterTile.Initialize(_fileSource, tile.CanonicalTileId, _mapId, () =>
            {
                if (tile == null)
                {
                    return;
                }

                if (pngRasterTile.HasError)
                {
                    OnErrorOccurred(new TileErrorEventArgs(tile.CanonicalTileId, pngRasterTile.GetType(), tile, pngRasterTile.Exceptions));
                    tile.HeightDataState = TilePropertyState.Error;

                    // Handle missing elevation from server (404)!
                    // TODO: optimize this search!
                    if (pngRasterTile.ExceptionsAsString.Contains("404"))
                    {
                        ResetToFlatMesh(tile);
                    }
                    Progress--;
                    return;
                }

                tile.SetHeightData(pngRasterTile.Data, _heightModifier, _useRelativeHeight);
                GenerateTerrainMesh(tile);
                // Add a collider this may or may not be worse than the mesh collider that the terrain factory
                // can generate
                // tile.gameObject.AddComponent<BoxCollider>();
                // tile.gameObject.GetComponent<BoxCollider>().size = new Vector3( 99, .1f, 99 );
                // tile.gameObject.GetComponent<BoxCollider>().center = new Vector3( 0 , 0, 0 );
                // Add a tag for generating navmesh
                // tile.gameObject.AddComponent<NavMeshSourceTag>();
                Progress--;
            });
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Fetches the vector data and passes each layer to relevant layer visualizers
        /// </summary>
        /// <param name="tile"></param>
        /// <param name="e"></param>
        private void CreateMeshes(UnityTile tile)
        {
            tile.OnHeightDataChanged -= HeightDataChangedHandler;
            tile.OnRasterDataChanged -= ImageDataChangedHandler;

            tile.VectorDataState = TilePropertyState.Loading;

            var vectorTile = new VectorTile();

            tile.AddTile(vectorTile);

            Progress++;
            vectorTile.Initialize(_fileSource, tile.CanonicalTileId, _mapId, () =>
            {
                if (vectorTile.HasError)
                {
                    tile.VectorDataState = TilePropertyState.Error;
                    Progress--;
                    return;
                }

                // TODO: move unitytile state registrations to layer visualizers. Not everyone is interested in this data
                // and we should not wait for it here!
                foreach (var layerName in vectorTile.Data.LayerNames())
                {
                    if (_layerBuilder.ContainsKey(layerName))
                    {
                        foreach (var builder in _layerBuilder[layerName])
                        {
                            if (builder.Active)
                            {
                                var coroutine = builder.AsyncCreate(vectorTile.Data.GetLayer(layerName), tile, () => {
                                    tile.VectorDataState = TilePropertyState.Loaded;
                                    Progress--;
                                });
                                Runnable.Run(coroutine);
                            }
                        }
                    }
                }
            });
        }
Ejemplo n.º 12
0
    //tile here should be totally optional and used only not to have keep a dictionary in terrain factory base
    public void FetchVector(CanonicalTileId canonicalTileId, string mapid, UnityTile tile = null, bool useOptimizedStyle = false, Style style = null)
    {
        var vectorTile = (useOptimizedStyle) ? new VectorTile(style.Id, style.Modified) : new VectorTile();

        tile.AddTile(vectorTile);
        vectorTile.Initialize(_fileSource, tile.CanonicalTileId, mapid, () =>
        {
            if (tile.CanonicalTileId != vectorTile.Id)
            {
                //this means tile object is recycled and reused. Returned data doesn't belong to this tile but probably the previous one. So we're trashing it.
                return;
            }

            if (vectorTile.HasError)
            {
                FetchingError(tile, vectorTile, new TileErrorEventArgs(tile.CanonicalTileId, vectorTile.GetType(), tile, vectorTile.Exceptions));
            }
            else
            {
                DataRecieved(tile, vectorTile);
            }
        });
    }
    //tile here should be totally optional and used only not to have keep a dictionary in terrain factory base
    public void FetchImage(CanonicalTileId canonicalTileId, string mapid, UnityTile tile = null, bool useRetina = false)
    {
        RasterTile rasterTile;

        if (mapid.StartsWith("mapbox://", StringComparison.Ordinal))
        {
            rasterTile = useRetina ? new RetinaRasterTile() : new RasterTile();
        }
        else
        {
            rasterTile = useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile();
        }

        if (tile != null)
        {
            tile.AddTile(rasterTile);
        }

        rasterTile.Initialize(_fileSource, tile.CanonicalTileId, mapid, () =>
        {
            if (tile.CanonicalTileId != rasterTile.Id)
            {
                //this means tile object is recycled and reused. Returned data doesn't belong to this tile but probably the previous one. So we're trashing it.
                return;
            }

            if (rasterTile.HasError)
            {
                FetchingError(tile, rasterTile, new TileErrorEventArgs(tile.CanonicalTileId, rasterTile.GetType(), tile, rasterTile.Exceptions));
            }
            else
            {
                DataRecieved(tile, rasterTile);
            }
        });
    }