I am attempting to place a player avatar on a map that is generated at runtime. I have looked at the "API" and "Routes" ArcGIS example scenes within Unity and learned a lot about creating the map at runtime with the appropriate api.
Yet, the biggest issue, and one I am trying to solve, is that raycasting from above the ground to the ground to get a specific ArcGisPoint returns a point that is hovering a few hundred meters above the actual ground. (Picture 1)
I have created a coroutine that raycasts until it hits the map tile colliders, then it returns the raycast hit point, which I then turn into an ArcGisPoint via a method I found in the sample projects, specifically this
ArcGISPoint HitToGeoPosition(RaycastHit hit, float yOffset = 0)
{
var worldPosition = math.inverse(mapComponent.WorldMatrix).HomogeneousTransformPoint(hit.point.ToDouble3());
var geoPosition = mapComponent.View.WorldToGeographic(worldPosition);
var offsetPosition = new ArcGISPoint(geoPosition.X, geoPosition.Y, geoPosition.Z + yOffset, geoPosition.SpatialReference);
return GeoUtils.ProjectToSpatialReference(offsetPosition, geoPosition.SpatialReference);
}
I have tried changing the spacial references to all be of type
ArcGISSpatialReference.WGS84()
but this create strange glitches.
... Okay, so while writing this, I have discovered that the collider that the raycast hits is not the same as the collider of the map tile that sits right under the map ... it actually hits a preliminary layer that is blank and brown and flat (see picture 3 & 4 below). Once the rest of the elevation and layer load to the final state, the player has already been positioned.
I have sought a way to register a callback to know exactly when the layer and elevation are active (not initializing) ... and I came up with using the ArcGISViewStateLoggingComponent and adding an `action Event` that will be called once the
mapComponent.View.LayerViewStateChanged
event is fired and
status.HasFlag(ArcGISLayerViewStatus.Active)
is true (see picture #5). However, this ALWAYS crashes Unity editor.
What can I do to easily know when the map has fully and properly rendered its tiles? Isn't there a simple callback and Esri has instilled into their API?
Thank you for all of your help!