-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load project boundaries from GeoJSON
The Dossier contains a reference to a GeoJSON file that can be loaded, and for which we emit an event once it has done so. This event is used to center the camera on the returned feature collection's center.
- Loading branch information
Showing
16 changed files
with
324 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
Packages/eu.netherlands3d.geojson/Runtime/Scripts/CenterOnFeatureCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using GeoJSON.Net.Feature; | ||
using Netherlands3D.Coordinates; | ||
using UnityEngine; | ||
using UnityEngine.Events; | ||
|
||
namespace Netherlands.GeoJSON | ||
{ | ||
/// <summary> | ||
/// Positions a game object to match the center of the given feature collection. | ||
/// | ||
/// This component assumes that the attached mesh/sprite equals 1 square unity unit/meter; similar to a regular | ||
/// 3D Plane. | ||
/// </summary> | ||
public class CenterOnFeatureCollection : MonoBehaviour | ||
{ | ||
[SerializeField] private GameObject targetGameObject; | ||
|
||
public UnityEvent<Vector3> onSetPosition = new(); | ||
|
||
private void Awake() | ||
{ | ||
if (targetGameObject == null) | ||
{ | ||
targetGameObject = gameObject; | ||
} | ||
} | ||
|
||
public void CenterOn(FeatureCollection featureCollection) | ||
{ | ||
double[] boundingBox = featureCollection.BoundingBoxes ?? featureCollection.DerivedBoundingBoxes(); | ||
int epsgId = featureCollection.EPSGId(); | ||
|
||
Coordinate topLeft = CoordinateConverter.ConvertTo( | ||
new Coordinate(epsgId, boundingBox[0], boundingBox[1], 0), | ||
CoordinateSystem.Unity | ||
); | ||
Coordinate bottomRight = CoordinateConverter.ConvertTo( | ||
new Coordinate(epsgId, boundingBox[2], boundingBox[3], 0), | ||
CoordinateSystem.Unity | ||
); | ||
Coordinate center = CoordinateConverter.ConvertTo( | ||
new Coordinate( | ||
epsgId, | ||
(boundingBox[0] + boundingBox[2]) / 2d, | ||
(boundingBox[1] + boundingBox[3]) / 2d, | ||
0 | ||
), | ||
CoordinateSystem.Unity | ||
); | ||
|
||
Vector3 position = new Vector3( | ||
center.ToVector3().x, | ||
transform.position.y, | ||
center.ToVector3().z | ||
); | ||
|
||
transform.position = position; | ||
onSetPosition.Invoke(position); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/eu.netherlands3d.geojson/Runtime/Scripts/CenterOnFeatureCollection.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.