mapbox / mapbox/vector-tile-cs
Place label parsing is broken
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 64
- Forks
- 38
- PR merge metrics
- No merged PRs in 30d
Description
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
```csharp
public Dictionary GetProperties()
{
if (0 != Tags.Count % 2)
{
throw new Exception(string.Format("Layer [{0}]: uneven number of feature tag ids", _layer.Name));
}
Dictionary properties = new Dictionary();
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:
```csharp
public Dictionary GetProperties()
{
if (Tags.Count % 2 != 0) throw new InvalidOperationException($"Layer [{_layer.Name}]: uneven number of feature tag ids");
var properties = new Dictionary();
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;
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in VectorTileFeatures.cs at GetProperties() and reproduce the duplicate-key case with the mapbox-streets-v7 or mapbox-streets-v8 tileset. Ensure duplicate properties no longer cause parsing to throw, while uneven tag counts still report an error; adapt the warning behavior appropriately for this project rather than relying on Unity logging.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100