Exemplo n.º 1
0
        public void InitializeFramework(ConfigBuilder configBuilder, Action <CompositionRoot> initAction)
        {
            IsInitialized = false;

            // Need to dispose all previously used components as we're going to create new ones.
            if (_container != null)
            {
                _container.Dispose();
            }

            // create default container which should not be exposed outside to avoid Service Locator pattern.
            _container = new Container();

            // create trace to log important messages
            _trace = new DebugConsoleTrace();

            // UtyMap requires some files/directories to be precreated.
            InstallationApi.EnsureFileHierarchy(_trace);

            // Setup RX configuration.
            UnityScheduler.SetDefaultForUnity();

            // subscribe to unhandled exceptions in RX
            MainThreadDispatcher.RegisterUnhandledExceptionCallback(ex =>
                                                                    _trace.Error(FatalCategoryName, ex, "Unhandled exception"));

            try
            {
                var config = configBuilder
                             .SetStringIndex("Index/")
                             .SetSpatialIndex("Index/")
                             .Build();

                // create entry point for utymap functionallity
                _compositionRoot = new CompositionRoot(_container, config)
                                   .RegisterAction((c, _) => c.RegisterInstance <ITrace>(_trace))
                                   .RegisterAction((c, _) => c.Register(Component.For <IPathResolver>().Use <DemoPathResolver>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <IModelBuilder>().Use <DemoModelBuilder>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <INetworkService>().Use <DemoNetworkService>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <CustomizationService>().Use <CustomizationService>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <Stylesheet>().Use <Stylesheet>(@"MapCss/default/default.mapcss")));

                // this is the way to insert custom extensions from outside. You may need to do it for
                // some scenes.
                initAction(_compositionRoot);

                // setup object graph
                _compositionRoot.Setup();

                IsInitialized = true;
            }
            catch (Exception ex)
            {
                _trace.Error(FatalCategoryName, ex, "Cannot setup object graph.");
                throw;
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
                }
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }