Topic: Update markers position problem
Hi, I'm using Online maps 4.5.0.1 and Unity 6.3.
I have a custom markers engine just like in the examples. I'm calling UpdateMarkers when map moves (assigned to public Action OnMapUpdated). My application is only 2d. I'm using Canvas with screen overlay mode with canvas scaler - scale with screen size (mode expand). Also my map is in many places in my application and my map views have different sizes, sometimes full screen sometimes they are smaller in popups. In my setup I have a MapCamera that renders the map into a Map render texture. I have multiple RawImages in my project with RawImageTouchForwarders.
The problem I have is that when I move the map markers position is not updated with the same vector. They got desync and point to another location. Seems like something with the canvas scaler is incorrectly calculated... but I cannot find the error in the code.
This is my UpdateMarker method:
private void UpdateMarker(IUIEntity marker, MapController mc)
{
if (marker == null || !marker.hasGameObject || marker.gameObject == null)
{
return;
}
Transform markerTransform = marker.gameObject.transform;
RawImageTouchForwarder forwarder = markerTransform.parent.parent.GetComponentInChildren<RawImageTouchForwarder>(true);
if (forwarder == null)
{
Logger.Error("Could not find raw image touch forwarder for marker: " + marker.gameObject.name);
return;
}
Vector2 screenPosition = mc.control.LocationToScreen(marker.longitude, marker.latitude);
screenPosition = forwarder.MapToForwarderSpace(screenPosition);
RectTransformUtility.ScreenPointToLocalPointInRectangle(markerTransform.parent as RectTransform, screenPosition, null, out Vector2 point);
markerTransform.localPosition = point;
}Thanks for help.