public void SetUpScaling(AbstractMap map) { var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(map.CenterLatitudeLongitude, map.AbsoluteZoom)); map.SetWorldRelativeScale((float)(map.Options.scalingOptions.unityTileSize / referenceTileRect.Size.x)); }
public void SetUpPlacement(AbstractMap map) { var referenceTileRect = Conversions.TileBounds(TileCover.CoordinateToTileId(map.CenterLatitudeLongitude, map.AbsoluteZoom)); map.SetCenterMercator(referenceTileRect.Center); }
/// <summary> /// corrects and adjusts the mapCenterLatLong at the start and after zoom as the user-specified /// string is unlikely to be the actual center coordinates for the center tile at the start, /// or after zoom the coordinates much be updated /// </summary> private void CorrectCenterLatitudeLongitude() { UnwrappedTileId CenterTile = TileCover.CoordinateToTileId(_mapCenterLatitudeLongitude, _zoom); CenterLatitudeLongitude = Conversions.TileIdToCenterLatitudeLongitude(CenterTile.X, CenterTile.Y, CenterTile.Z); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.Space(); EditorGUILayout.PropertyField(token, new GUIContent("Token")); string _notes = "The purpose of this example is to demonstrate a slutty map built with the sdk \n" + " using satellite imagery draped over geometry generated from terrain data.\n" + "At runtime an area that corresponds the specified lat/lon Northeast and Southwest coordinates\n" + "and zoom level will be created. \n" + "The area displayed will be determined by the zoom and bounding box.\n" + " mouse click and drag to pan the map in play mode.\n"; if (string.IsNullOrEmpty(token.stringValue)) { EditorGUILayout.HelpBox("You must have an access token!", MessageType.Error); if (GUILayout.Button("Get a token from mapbox.com for free")) { Application.OpenURL("https://www.mapbox.com/studio/account/tokens/"); } } EditorGUILayout.HelpBox(_notes, MessageType.Info); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Southwest coordinate"); south.doubleValue = EditorGUILayout.DelayedDoubleField(south.doubleValue); west.doubleValue = EditorGUILayout.DelayedDoubleField(west.doubleValue); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Northeast coordinate"); north.doubleValue = EditorGUILayout.DelayedDoubleField(north.doubleValue); east.doubleValue = EditorGUILayout.DelayedDoubleField(east.doubleValue); EditorGUILayout.EndHorizontal(); var bounds = new GeoCoordinateBounds( new GeoCoordinate(south.doubleValue, west.doubleValue), new GeoCoordinate(north.doubleValue, east.doubleValue)); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Center coordinate"); EditorGUILayout.LabelField(bounds.Center.ToString()); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.IntSlider(zoom, 0, 20, new GUIContent("Zoom")); var tileCount = TileCover.Get(bounds, zoom.intValue).Count; EditorGUILayout.Space(); EditorGUILayout.LabelField("Tile count", tileCount.ToString()); if (tileCount > Map <RasterTile> .TileMax) { EditorGUILayout.Space(); EditorGUILayout.HelpBox("Too many tiles!", MessageType.Error); } EditorGUILayout.Space(); edge.floatValue = EditorGUILayout.FloatField("Tile edge", edge.floatValue); serializedObject.ApplyModifiedProperties(); }
void Update() { Vector2dBounds currentViewPortWebMercBnds = getcurrentViewPortWebMerc(); bool bboxChanged = !(_viewPortWebMercBounds.ToString() == currentViewPortWebMercBnds.ToString()); float cameraY = _referenceCamera.transform.localPosition.y; //no zoom, no pan -> don't change tiles if (cameraY == _previousY && !bboxChanged) { return; } _previousY = cameraY; //camera moves within one zoom level, and no panning, don't do anything if ( (cameraY > _cameraZoomingRangeMinY && cameraY < _cameraZoomingRangeMaxY) && !bboxChanged ) { //no changes, bail return; } _viewPortWebMercBounds = currentViewPortWebMercBnds; //panning //TODO: move active tiles on pan //HACK: just deactivate all active tiles //!!!BEWARE!!!: don't compare Vector2d via '==' use 'Equals()' if (!_previousWebMercCenter.Equals(_dynamicZoomMap.CenterMercator)) { _previousWebMercCenter = _dynamicZoomMap.CenterMercator; var remove = _activeTiles.Keys.ToList(); foreach (var r in remove) { RemoveTile(r); } } Vector3 localPosition = _referenceCamera.transform.position; //close to ground, zoom in if (cameraY < _cameraZoomingRangeMinY) { //already at highest level, don't do anything -> camera free to move closer if (_dynamicZoomMap.Zoom == _dynamicZoomMap.MaxZoom) { return; } _dynamicZoomMap.SetZoom(_dynamicZoomMap.Zoom + 1); //reposition camera at max distance localPosition.y = _cameraZoomingRangeMaxY; _referenceCamera.transform.localPosition = localPosition; } //arrived at max distance, zoom out else if (cameraY > _cameraZoomingRangeMaxY) { //already at lowest level, don't do anything -> camera free to move further away if (_dynamicZoomMap.Zoom == _dynamicZoomMap.MinZoom) { return; } _dynamicZoomMap.SetZoom(_dynamicZoomMap.Zoom - 1); //reposition camera at min distance localPosition.y = _cameraZoomingRangeMinY; _referenceCamera.transform.localPosition = localPosition; } //update viewport in case it was changed by switching zoom level _viewPortWebMercBounds = getcurrentViewPortWebMerc(); var tilesNeeded = TileCover.GetWithWebMerc(_viewPortWebMercBounds, _dynamicZoomMap.Zoom); var activeTiles = _activeTiles.Keys.ToList(); List <UnwrappedTileId> toRemove = activeTiles.Except(tilesNeeded).ToList(); foreach (var t2r in toRemove) { RemoveTile(t2r); } var finalTilesNeeded = tilesNeeded.Except(activeTiles); foreach (var tile in finalTilesNeeded) { AddTile(tile); } }