public void createTerrainObject() { this.BaseTerrainObj = new GameObject("TerrainIsle"); this.BaseTerrainObj.transform.parent = terr.transform; terr.BaseTerrainData.baseMapResolution = 1024; int baseResolution = (int)Math.Pow(2, 8 + terr.terrainScalingFactor) + 1; terr.BaseTerrainData.SetDetailResolution(baseResolution, 16); terr.BaseTerrainData.heightmapResolution = baseResolution; terr.BaseTerrainData.alphamapResolution = baseResolution; terr.BaseTerrainData.size = new Vector3(baseResolution, 600, baseResolution); this.BaseTerrainCollider = this.BaseTerrainObj.AddComponent <TerrainCollider>(); this.BaseTerrainCollider.terrainData = terr.BaseTerrainData; this.terrain = BaseTerrainObj.AddComponent <Terrain>(); this.terrain.terrainData = terr.BaseTerrainData; // get the terrain component //this.terrain = BaseTerrain; // get the generated standard data this.tData = terrain.terrainData; // get the terrain resolution this.xTerrainRes = tData.heightmapWidth; this.yTerrainRes = tData.heightmapHeight; this.terrainWidthScale = tData.size.x; this.terrainLengthScale = tData.size.z; this.terrainHeightScale = tData.size.y; // transform terrain to middle point of global coordinates system this.terrain.transform.position = new Vector3(-terrainWidthScale / 2, 0, -terrainLengthScale / 2); // get the texture resolution this.xTextureRes = tData.alphamapWidth; this.yTextureRes = tData.alphamapHeight; this.alphaMap = new AlphaMap(new float[this.xTextureRes, this.yTextureRes, 6]); this.biomeMap = new int[this.xTextureRes, this.yTextureRes]; this.MountMap = new MountMap(this); this.DetailsMap = new DetailsMap(this); this.TreeMap = new TreeMap(this); tData.SetAlphamaps(0, 0, this.alphaMap.aMap); tData.SetDetailLayer(0, 0, 0, this.DetailsMap.dMap); tData.SetHeights(0, 0, this.MountMap.heightMap); tData.treeInstances = new List <TreeInstance>().ToArray(); //print("Width: " + xTerrainRes + " / " + xTextureRes + " / " + terrainWidthScale + " / " + tData.alphamapResolution); //print("Length: " + yTerrainRes + " / " + yTextureRes + " / " + terrainLengthScale + " / " + tData.detailResolution); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); busArrivalUpdateTimer.Start(); viewModel.RegisterEventHandlers(Dispatcher); UpdateAppBar(true); if (isFiltered == true) { viewModel.LoadArrivalsForStop(viewModel.CurrentViewState.CurrentStop, viewModel.CurrentViewState.CurrentRoute); } else { viewModel.LoadArrivalsForStop(viewModel.CurrentViewState.CurrentStop, null); } // When we enter this page after tombstoning often the location won't be available when the map // data binding queries CurrentLocationSafe. The center doesn't update when the property changes // so we need to explicitly set the center once the location is known. viewModel.LocationTracker.RunWhenLocationKnown(delegate(GeoCoordinate location) { Dispatcher.BeginInvoke(() => { DetailsMap.Center = location; //calculate distance to current stop and zoom map if (viewModel.CurrentViewState.CurrentStop != null) { if (location.IsUnknown || location.Latitude < -90.0 || location.Latitude > 90 || location.Longitude < -180.0 || location.Longitude > 180) { // location is bogus. don't try to set the map view with it. } else { GeoCoordinate stoplocation = new GeoCoordinate(viewModel.CurrentViewState.CurrentStop.coordinate.Latitude, viewModel.CurrentViewState.CurrentStop.coordinate.Longitude); double radius = 2 * location.GetDistanceTo(stoplocation) * 0.009 * 0.001; // convert metres to degrees and double radius = Math.Max(radius, minimumZoomRadius); radius = Math.Min(radius, maximumZoomRadius); DetailsMap.SetView(new LocationRect(location, radius, radius)); } } DetailsMap_MapZoom(this, null); }); } ); }
void FullScreenMapPage_Loaded(object sender, RoutedEventArgs e) { if (viewModel.CurrentViewState.CurrentSearchLocation != null) { // Using mapHasMoved prevents us from relocating the map if the user reloads this // page from the back stack if (mapHasMoved == false) { Dispatcher.BeginInvoke(() => { //DetailsMap.Center = viewModel.CurrentViewState.CurrentSearchLocation.location; DetailsMap.SetView(viewModel.CurrentViewState.CurrentSearchLocation.boundingBox); viewModel.LoadStopsForLocation(viewModel.CurrentViewState.CurrentSearchLocation.location); } ); } } else { viewModel.LocationTracker.RunWhenLocationKnown(delegate(GeoCoordinate location) { Dispatcher.BeginInvoke(() => { // If the user has already moved the map, don't relocate it if (mapHasMoved == false) { DetailsMap.Center = location; } viewModel.LoadStopsForLocation(location); } ); } ); } }