1 (edited by bartosz.wolski 2018-10-17 09:31:19)

Topic: Online Maps Marker Manager

I am using onlineMaps newest beta version.

And I have problem when I have 2 markers close to each other.
I am changing 'active' marker (since user can select one), and switching its texture but it appear behind other markers.

I made a code so that selected marker is removed and added again (to be at the end of childern in marker manager), but it doesn't change anything.

Then I noticed to change it so my marker will be last there are 2 solutions :

1) draw is as last element ( no idea how to do that except what I did).
2) change the "Render Queue" from 3000 to 3001 for example.

I am attaching 2 screenshots showing the situation

Maybe maps are redrawing markers by longitude? or something similar.

Is there any function in markerManagers or some script I could use to fix this issue?

Or am I forced to get that markersMesh as componenet, compare textures and if I see my texture used I will change renger queue each time? (I wish to avoid this since it seems like dirty hack, that might bring more problems in the future).

Post's attachments

Attachment icon 1.PNG 112.45 kb, 17 downloads since 2018-10-17 

Re: Online Maps Marker Manager

Hello.

Online Maps draws markers not in the order in which they go in the inspector.
By default, markers are sorted by latitude.

Example of how to change the order of the markers is in:
Assets / Infinity Code / Online Maps / Examples (API usage) / TilesetMarkerDepthExample.cs.

Kind Regards,
Infinity Code Team

Re: Online Maps Marker Manager

Thanks!
I thought its longitude but I am glad I was close enought to finding at least how they are drawn.

I will check that example out smile thank you in advance.

Re: Online Maps Marker Manager

I am using beta, so well I wasn't able to use that code from example.

But I modified slightly the script in case anyone will need it so for beta version :

OnlineMapsMarkerFlatDrawer.cs :

around line (150) :

            int extraValue = m.needToBeInFront ? 999 : 0;
                double mx, my;
                m.GetPosition(out mx, out my);
                return 90 - my + extraValue;


and on OnlineMapsMarker.cs :

add :

public bool needToBeInFront.

Thanks Alex for guiding me to this script thanks to that I was easly able to add my required modification.

Re: Online Maps Marker Manager

Why not?

For example, how to make a central marker on top (without modification of the asset code):

using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class TilesetMarkerDepthExample2 : MonoBehaviour
{
    /// <summary>
    /// Defines a new comparer.
    /// </summary>
    public class MarkerComparer : IComparer<OnlineMapsMarker>
    {
        public int Compare(OnlineMapsMarker m1, OnlineMapsMarker m2)
        {
            object m1f = m1["isFront"];
            object m2f = m2["isFront"];
            bool m1_front = m1f != null? (bool) m1f: false;
            bool m2_front = m2f != null? (bool) m2f: false;
            if (m1_front && !m2_front) return 1;
            if (m2_front && !m1_front) return -1;

            if (m1.position.y > m2.position.y) return -1;
            if (m1.position.y < m2.position.y) return 1;
            return 0;
        }
    }

    private void Start()
    {
        OnlineMaps map = OnlineMaps.instance;

        // Create markers.
        OnlineMapsMarkerManager.CreateItem(new Vector2(0, 0.01f));
        OnlineMapsMarker frontMarker = OnlineMapsMarkerManager.CreateItem(new Vector2(0, 0));
        frontMarker["isFront"] = true;
        OnlineMapsMarkerManager.CreateItem(new Vector2(0, -0.01f));

        // Sets a new comparer.
        OnlineMapsMarkerFlatDrawer drawer = OnlineMapsTileSetControl.instance.markerDrawer as OnlineMapsMarkerFlatDrawer;
        if (drawer != null) drawer.markerComparer = new MarkerComparer();

        // Get the center point and zoom the best for all markers.
        Vector2 center;
        int zoom;
        OnlineMapsUtils.GetCenterPointAndZoom(OnlineMapsMarkerManager.instance.ToArray(), out center, out zoom);

        // Change the position and zoom of the map.
        map.position = center;
        map.zoom = zoom;
    }
}

You will lose your changes when updating and you will need to do it again.
So I do not recommend making changes that will not included to the asset.
Follow this recommendation or not, everyone makes the decision himself.

Kind Regards,
Infinity Code Team

Re: Online Maps Marker Manager

I agree your solution is better after all, finally I did implemeneted it like you suggested, but at that point I didn't had time to spare on this marker issue and had to move on smile thanks for your help.