Click on a 3D layer building to get building metadata from OSM

05-09-2023 01:19 AM
New Contributor

I am studying the ArcGis for Unity SDK for some time and have been tweaking the SampleArcGisRaycast component from the Unity SDK to various interesting things. Now I want to make a way to get Open Street Map Metadata by clicking on each building. For now, getting them to be written in Debug.Log would be enough.

I followed up on many documentation articles and ArcGis blogs about the subject, but I could not find a way to implement this. To be honest I don't even understand where I should start and the milestones of creating such a system. My starting point was this article>

At the moment, I managed to console log a value called `featureId` from the SampleArcGisRaycast component, --some kind of a value that is uniquely assigned to each building. Is there a way to request OSM building information from this `featureId` value?

here's the updated code I used to get the feature ID:

void Update(){
if (Input.GetKey(KeyCode.LeftShift) && Input.GetMouseButtonDown(0))
			RaycastHit hit;
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

			if (Physics.Raycast(ray, out hit))
				var arcGISRaycastHit = arcGISMapComponent.GetArcGISRaycastHit(hit);
				var layer = arcGISRaycastHit.layer;
				var featureId = arcGISRaycastHit.featureId;
				if (layer != null && featureId != -1)
					// featureText is an UI text 
					featureText.text = featureId.ToString();
					metadataText.text = JSONReader.getCity(featureId.ToString());
					var geoPosition = arcGISMapComponent.EngineToGeographic(hit.point);

					var offsetPosition = new ArcGISPoint(geoPosition.X, geoPosition.Y, geoPosition.Z + 200, geoPosition.SpatialReference);
					var rotation = arcGISCamera.GetComponent<ArcGISLocationComponent>().Rotation;
					var location = canvas.GetComponent<ArcGISLocationComponent>();
					location.Position = offsetPosition;
					location.Rotation = rotation;
					Debug.Log("Location == x: " + location.Position.X + "| y: " + location.Position.Y+"| z: " + location.Position.Z);
					Debug.Log("Location p == x: " + location.position.X + "| y: " + location.position.Y + "| z: " + location.position.Z);
					Debug.Log("GeoPosition == x: " + geoPosition.X + "| y: " + geoPosition.Y + "| z: " + geoPosition.Z);



My other guess to get this working is to somehow get the coordinates of the building and then find a way to get the OSM metadata according to the coordinates. Or should I follow a different path?

0 Kudos
1 Reply
by Esri Contributor
Esri Contributor

which dataset are you using? Note that we don't currently support but this is a highly requested service so it's high on our priority list. 

0 Kudos