コード例 #1
0
ファイル: MeshFactory.cs プロジェクト: VicoDeLaVega/Teddy
        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);
                }
            });
        }
コード例 #2
0
        public override void FetchData(DataFetcherParameters parameters)
        {
            if (!(parameters is BuildingMeshFetcherParameters fetcherParameters))
            {
                return;
            }

            var vectorTile = new VectorTile();

            vectorTile.Initialize(_fileSource, fetcherParameters.canonicalTileId, fetcherParameters.tilesetId, () =>
            {
                if (fetcherParameters.canonicalTileId != vectorTile.Id)
                {
                    return;
                }

                if (vectorTile.HasError)
                {
                    UnityEngine.Debug.LogError("Vector Tile Error!");
                }
                else
                {
                    dataReceived(fetcherParameters.cTile, vectorTile);
                }
            });
        }
コード例 #3
0
ファイル: TileViewer.cs プロジェクト: jmloewen/MapBoxTest
        private void BuildVectorTile()
        {
            // Define which features from the vector tile will be made into game objects
            var builderDictionary = new Dictionary <string, MeshBuilder>()
            {
                {
                    "building", new MeshBuilder()
                    {
                        Modifiers = new List <MeshModifier>()
                        {
                            new PolygonMeshModifier(),
                            new UvModifier(),
                            new HeightModifier()
                        }
                    }
                },
                // Not using these for now.
                //{
                //    "road", new MeshBuilder()
                //    {
                //        Modifiers = new List<MeshModifier>()
                //        {
                //            new LineMeshModifier(),
                //            new UvModifier(),
                //            new HeightModifier()
                //        }
                //    }
                //}
            };

            var parameters = new Tile.Parameters
            {
                Fs = _fileSource,
                Id = new CanonicalTileId(zoomLevel, (int)tileCoordinate.x, (int)tileCoordinate.y)
            };

            // Use VectorTile class for vector tiles. Requests mapbox.mapbox-streets-v7 mapid by default.
            var vectorTile = new VectorTile();

            vectorTile.Initialize(parameters, () =>
            {
                if (vectorTile.Error != null)
                {
                    Debug.Log(vectorTile.Error);
                    return;
                }

                foreach (var builder in builderDictionary)
                {
                    var layer = vectorTile.GetLayer(builder.Key);
                    builder.Value.Create(layer, tileRect, heightData, tileObject.transform, parameters);
                }
            });
        }
コード例 #4
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);
                }
            });
        }
コード例 #5
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);
                            }
                        }
                    }
                }
            });
        }