1 (edited by orkasan 2020-07-22 08:21:50)

Topic: Online Maps with GameObjects

Hi,

I would like to add new moving GameObjects to specific coordinates on map, just like marker's mechanism but not marker. As I pan, I would like GameObjects move along with map also on zoom keep their coordinates, and if they are outside of the pan area they will be inactive. There might be 10000 GameObjects at the same time on whole map but only the ones within the pan area will be shown.

What would be the best way to achieve this goal?

Re: Online Maps with GameObjects

Hello.

Subscribe to OnlineMaps.OnChangePosition and OnlineMaps.OnChangeZoom.
http://infinity-code.com/doxygen/online … 37bdd7bfa1
When changing the position or zoom of the map, update the positions of your GameObjects using OnlineMapsControlBaseDynamicMesh.GetWorldPosition.
http://infinity-code.com/doxygen/online … 6316068362

3 (edited by orkasan 2020-07-22 11:44:56)

Re: Online Maps with GameObjects

Hi,

Thanks for the response. I tried the steps you have described however, GetWorldPosition returns quite huge coordinates.

Here is the code I test with:

    void Start()
    {
        OnlineMaps.instance.OnChangePosition += UpdatePosition;
        OnlineMaps.instance.OnChangeZoom += UpdatePosition;
        UpdatePosition();
    }
    public void UpdatePosition()
    {
        this.gameObject.transform.position =OnlineMapsControlBaseDynamicMesh.instance.GetWorldPosition(55.674160, 12.573540);
    }

Re: Online Maps with GameObjects

Your code looks fine.
There may be reasons:
1. You used coordinates that are far from the map view.
2. You used the wrong order of parameters in GetWorldPosition. First longitude, then latitude.

Re: Online Maps with GameObjects

Thanks a lot, now it is solved. I was using lat-lon order..

Re: Online Maps with GameObjects

I have another question. How to determine if the GameObject is inside/outside of the pan area? 

Alex Vertax wrote:

Hello.

Subscribe to OnlineMaps.OnChangePosition and OnlineMaps.OnChangeZoom.
http://infinity-code.com/doxygen/online … 37bdd7bfa1
When changing the position or zoom of the map, update the positions of your GameObjects using OnlineMapsControlBaseDynamicMesh.GetWorldPosition.

Re: Online Maps with GameObjects

OnlineMaps.InMapView
http://infinity-code.com/doxygen/online … 3637fbe9cd

Re: Online Maps with GameObjects

Thanks a lot!

9 (edited by mcb 2020-08-18 16:34:39)

Re: Online Maps with GameObjects

Alex, I'm using the OnlineMapsControlBaseDynamicMesh.instance.GetWorldPosition() to place my models as well, but the model comes in beneath the terrain.
What is the recommended approach to push it up to the surface?  I'm at zoom level 15 if it matters, thanks!

10

Re: Online Maps with GameObjects

I see that a 3d marker solves that issue, but I would still like to know how to do it without refactoring.  Seems like I'm probably missing something very simple

Re: Online Maps with GameObjects

Most likely, your model just has the wrong Y alignment.

How to fix it:
- Create a new empty GameObject.
- Place your model inside GameObject.
- Align your model so that y = 0 is at the bottom of the model.
- Create a prefab from an external GameObject, and use that for GetWorldPosition or markers.

12 (edited by mcb 2020-08-20 20:45:17)

Re: Online Maps with GameObjects

Y position was fine, I ended up just aligning it with the marker

// Marker position. Geographic coordinates.
Vector2 markerPosition = new Vector2((float)actor.actorLongitude, (float)actor.actorLatitude);
// Create 3D marker
marker3D = OnlineMapsMarker3DManager.CreateItem(markerPosition, instance.spawn[actor.actorIndex]);
// create new go at marker position
GameObject newActor = Instantiate(instance.spawn[actor.actorIndex], marker3D.relativePosition, marker3D.rotation);
newActor.transform.eulerAngles = new Vector3(actor.rotationX, actor.rotationY, actor.rotationZ);
// get rid of the marker
Destroy(marker3D.transform.gameObject);

Re: Online Maps with GameObjects

It is a bad idea.
You will have a great loss of performance.

Why are you using marker3D.relativePosition?
This field contains the relative position on the map (XZ contains values 0-1, Y is always 0), not a position in the scene.

Also, you are not destroying the marker, and if you calling this code constantly, you will have a huge memory leak.
The correct way to destroy the marker is OnlineMapsMarker3DManager.RemoveItem.