예제 #1
0
    void Start()
    {
        // init utymap library
        _compositionRoot = InitTask.Run((container, config) =>
        {
            container
            .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/ground/ground.mapcss"))
            .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
            .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
            .Register(Component.For <IGeocoder>().Use <UtyMapGeocoder>())
            .Register(Component.For <IElementBuilder>().Use <PlaceElementBuilder>().Named("place"));
        });

        // initial geo position and quad key of character
        var coordinate = new GeoCoordinate(StartLatitude, StartLongitude);
        var quadKey    = GeoUtils.CreateQuadKey(coordinate, LevelOfDetail);

        // init address controller which is responsible for searching address
        _addressController = new AddressController(
            _compositionRoot.GetService <IGeocoder>(),
            Text.GetComponent <Text>());

        // init tile controller which is responsible for tile processing
        _tileController = new TileController(
            _compositionRoot.GetService <IMapDataStore>(),
            _compositionRoot.GetService <Stylesheet>(),
            ElevationType,
            coordinate,
            LevelOfDetail);

        // freeze target till initial tile is loaded
        var rigidbody = CharacterTarget.transform.GetComponent <Rigidbody>();

        rigidbody.isKinematic = true;
        // TODO unsubscribe listener
        _compositionRoot
        .GetService <IMapDataStore>()
        .ObserveOn <Tile>(Scheduler.MainThread)
        .Subscribe(tile =>
        {
            if (!quadKey.Equals(tile.QuadKey))
            {
                return;
            }

            // get elevation at current position
            var elevation = _compositionRoot
                            .GetService <IMapDataLibrary>()
                            .GetElevation(ElevationType, quadKey, coordinate);
            // move character accordingly
            CharacterTarget.transform.localPosition = new Vector3(
                CharacterTarget.transform.localPosition.x,
                (float)elevation + 5f,
                CharacterTarget.transform.localPosition.z);
            rigidbody.isKinematic = false;
        });
    }
예제 #2
0
        void Start()
        {
            // init utymap library
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/default/index.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                .RegisterInstance <IEnumerable <IElementBuilder> >(new List <IElementBuilder>());
            });
            // store map data store reference to member variable
            _mapDataStore = _compositionRoot.GetService <IMapDataStore>();

            // for demo purpose, disable mesh caching to force import data into memory for every run
            _compositionRoot.GetService <IMapDataLibrary>().DisableCache();

            // get reference for active stylesheet.
            var stylesheet = _compositionRoot.GetService <Stylesheet>();
            // get reference to trace.
            var trace = _compositionRoot.GetService <ITrace>();
            // create tile which represents target region to load.
            var tile = new Tile(
                // create quadkey using coordinate and choose proper LOD
                GeoUtils.CreateQuadKey(_coordinate, Scene == SceneType.Bird ? 14 : 16),
                // provide stylesheet (used to be the same as for import)
                stylesheet,
                // use cartesian projection as we want to build flat world
                new CartesianProjection(_coordinate),
                // use flat elevation (all vertices have zero meters elevation)
                ElevationDataType.Flat,
                // parent for built game objects
                gameObject);

            // import data into memory
            _mapDataStore.AddTo(
                // define where geoindex is created (in memory, not persistent)
                MapDataStorages.TransientStorageKey,
                // path to map data
                String.Format(MapDataPathFormat, Scene == SceneType.Bird ? "json" : "xml"),
                // stylesheet is used to import only used data and skip unused
                stylesheet,
                // level of detail (zoom) for which map data should be imported
                new Range <int>(16, 16),
                new CancellationToken())
            // start import and listen for events.
            .Subscribe(
                // NOTE progress callback is ignored
                (progress) => { },
                // exception is reported
                (exception) => trace.Error("import", exception, "Cannot import map data"),
                // once completed, load the corresponding tile
                () => _mapDataStore.OnNext(tile));
        }
예제 #3
0
        void Start()
        {
            // init utymap library
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/default/index.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                .RegisterInstance <IEnumerable <IElementBuilder> >(new List <IElementBuilder>());
            });

            // store map data store reference to member variable
            _mapDataStore = _compositionRoot.GetService <IMapDataStore>();

            // get reference for active stylesheet
            var stylesheet = _compositionRoot.GetService <Stylesheet>();
            // define level of detail
            const int levelOfDetail = 14;
            // create center coordinate;
            var coordinate = (new GeoCoordinate(Latitude, Longitude));
            // create "center" tile
            var center = GeoUtils.CreateQuadKey(coordinate, levelOfDetail);

            // load multiply tiles at once
            for (var tileX = center.TileX - 1; tileX <= center.TileX + 1; ++tileX)
            {
                for (var tileY = center.TileY - 1; tileY <= center.TileY + 1; ++tileY)
                {
                    var quadKey = new QuadKey(tileX, tileY, levelOfDetail);
                    var parent  = new GameObject(quadKey.ToString());
                    parent.transform.SetParent(gameObject.transform);
                    _mapDataStore.OnNext(new Tile(
                                             // quadkey to load.
                                             quadKey,
                                             // provide stylesheet
                                             stylesheet,
                                             // use cartesian projection as we want to build flat world
                                             new CartesianProjection(coordinate),
                                             // use grid elevation: uses mapzen servers by default,
                                             // stores elevation in simple NxN grid format.
                                             ElevationDataType.Grid,
                                             // parent for built game objects
                                             parent));
                }
            }
        }
예제 #4
0
        void Start()
        {
            // init utymap library
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                // NOTE use another mapcss style
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/customization/customization.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                // NOTE for use case 1: put cubes for POI
                .Register(Component.For <IElementBuilder>().Use <PlaceElementBuilder>().Named("place"))
                // NOTE for use case 2: search for capsule object in scene which replaces specific tree
                .Register(Component.For <IElementBuilder>().Use <ImportElementBuilder>().Named("import"));
            });

            // store map data store reference to member variable
            _mapDataStore = _compositionRoot.GetService <IMapDataStore>();

            // disable mesh caching to force import data into memory for every run
            _compositionRoot.GetService <IMapDataLibrary>().DisableCache();

            // import data into memory
            _mapDataStore.AddTo(
                // define where geoindex is created (in memory, not persistent)
                MapDataStorages.TransientStorageKey,
                // path to map data
                MapDataPath,
                // stylesheet is used to import only used data and skip unused
                _compositionRoot.GetService <Stylesheet>(),
                // level of detail (zoom) for which map data should be imported
                new Range <int>(16, 16),
                new CancellationToken())
            // start import and listen for events.
            .Subscribe(
                // NOTE progress callback is ignored
                (progress) => { },
                // exception is reported
                (exception) => _compositionRoot.GetService <ITrace>().Error("import", exception, "Cannot import map data"),
                // once completed, load the corresponding tile
                OnDataImported);
        }
예제 #5
0
        void Start()
        {
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/default/index.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                .Register(Component.For <IElementBuilder>().Use <LabelElementBuilder>().Named("label"));
            });

            var mapDataStore     = _compositionRoot.GetService <IMapDataStore>();
            var stylesheet       = _compositionRoot.GetService <Stylesheet>();
            var materialProvider = _compositionRoot.GetService <MaterialProvider>();
            var startCoord       = new GeoCoordinate(StartLatitude, StartLongitude);

            // scaled radius of Earth in meters, approx. 1:1000
            const float planetRadius = 6371f;
            const float surfaceScale = 0.01f;
            const float detailScale  = 1f;

            _lods = new List <Range <int> > {
                new Range <int>(1, 8), new Range <int>(9, 15), new Range <int>(16, 16)
            };

            var sphereController  = new SphereTileController(mapDataStore, stylesheet, ElevationDataType.Flat, Pivot, _lods[0], planetRadius);
            var surfaceController = new SurfaceTileController(mapDataStore, stylesheet, ElevationDataType.Flat, Pivot, _lods[1], startCoord, surfaceScale, 1000);
            var detailController  = new SurfaceTileController(mapDataStore, stylesheet, ElevationDataType.Flat, Pivot, _lods[2], startCoord, detailScale, 500);

            var sphereGestures  = new SphereGestureStrategy(sphereController, TwoFingerMoveGesture, ManipulationGesture, planetRadius);
            var surfaceGestures = new SurfaceGestureStrategy(surfaceController, TwoFingerMoveGesture, ManipulationGesture);
            var detailGestures  = new SurfaceGestureStrategy(detailController, TwoFingerMoveGesture, ManipulationGesture);

            _spaces = new List <Space>
            {
                new SphereSpace(sphereController, sphereGestures, Planet, materialProvider),
                new SurfaceSpace(surfaceController, surfaceGestures, Surface, materialProvider),
                new SurfaceSpace(detailController, detailGestures, Surface, materialProvider)
            };

            DoTransition(startCoord, StartZoom);
        }
예제 #6
0
        void Start()
        {
            // init utymap library
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                // NOTE use another mapcss style
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/default/index.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                .RegisterInstance <IEnumerable <IElementBuilder> >(new List <IElementBuilder>());
            });

            // get trace for logging.
            _trace = _compositionRoot.GetService <ITrace>();

            // store map data store reference to member variable
            _mapDataStore = _compositionRoot.GetService <IMapDataStore>();

            // disable mesh caching to force import data into memory for every run
            _compositionRoot.GetService <IMapDataLibrary>().DisableCache();

            // import data into memory
            _mapDataStore.AddTo(
                // define where geoindex is created (in memory, not persistent)
                MapDataStorages.TransientStorageKey,
                // path to map data
                MapDataPath,
                // stylesheet is used to import only used data and skip unused
                _compositionRoot.GetService <Stylesheet>(),
                // level of detail (zoom) for which map data should be imported
                _range,
                new CancellationToken())
            // start import and listen for events.
            .Subscribe(
                // NOTE progress callback is ignored
                (progress) => { },
                // exception is reported
                (exception) => _trace.Error("search", exception, "Cannot import map data"),
                // once completed, load the corresponding tile
                OnDataImported);
        }