Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Place label parsing is broken #47

Open
KuraiAndras opened this issue Aug 23, 2022 · 0 comments
Open

Place label parsing is broken #47

KuraiAndras opened this issue Aug 23, 2022 · 0 comments

Comments

@KuraiAndras
Copy link

Right now using the mapbox-streets-v7 and mapbox-streets-v8 tile-sets querying place labels throws excpetions when parsing properties. The exception happens when the API returns duplicated keys. For example for the class property it returns both country and disputed_country.

The problematic code is in VectorTileFeatures.cs GetProperties() method

public Dictionary<string, object> GetProperties()
{

    if (0 != Tags.Count % 2)
    {
        throw new Exception(string.Format("Layer [{0}]: uneven number of feature tag ids", _layer.Name));
    }
    Dictionary<string, object> properties = new Dictionary<string, object>();
    int tagCount = Tags.Count;
    for (int i = 0; i < tagCount; i += 2)
    {
        properties.Add(_layer.Keys[Tags[i]], _layer.Values[Tags[i + 1]]);
    }
    return properties;
}

Suggested fix:

public Dictionary<string, object> GetProperties()
{
    if (Tags.Count % 2 != 0) throw new InvalidOperationException($"Layer [{_layer.Name}]: uneven number of feature tag ids");
    var properties = new Dictionary<string, object>();
    var tagCount = Tags.Count;
    for (var i = 0; i < tagCount; i += 2)
    {
        var key = _layer.Keys[Tags[i]];
        var value = _layer.Values[Tags[i + 1]];

        if (properties.TryGetValue(key, out var oldValue))
        {
            if (Equals(value, oldValue))
            {
                continue;
            }
            else
            {
                // To work around the issue we started using this projects source directly in Unity. This logging should be different in the actual fix
                UnityEngine.Debug.LogWarning($"Overriding tile property. Key: {key}, Old value: {properties[key]}, New value: {value}");
            }
        }

        properties[key] = value;
    }
    return properties;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant