open street map api is driving me nuts
Before I dig into what’s happening between osm (open street map) and I, I’ll quickly explain what I’m using this api for.
Mapbattle is a game inspired by jet lag the game, a youtube show where people play hide and seek and similar games over multiple days and across large areas (sometimes a whole continent).
In mapbattle, you claim territories by making edits to osm in these territories.
As of now, territories are Seattle’s neighborhoods and the team that makes the most contribution to osm inside that territory is said to be of control of that territory.
The team controlling most territories by the end of the game wins.
Changesets
Players use the app of their choice to make the changes, I then use the api endpoint of `/changesets?display_name=`.
For score I use the field `changes_count` to find out how many changes submitted in that changeset.
For territory though, I used `minlat` and `minlon` to determine which territory encloses this changeset, if it spans 2 territories all scores would count towards one and one only.
Large changesets
After finding lots of the score counting in the wrong territory or shows as being outside of city limits altogether, I needed to debug, to quickly find out that changesets can be as large as users want them to be, and apparently some map editing apps do make them quite large.
https://social.coop/@ammaratef45/116638606967007345
Scores are not accurate anymore, and more needs to be done.
More apis
It turns out that I can get the individual changes inside the changeset by calling the api `/changeset//download`.
The result is a list of modifications, however this is not considered end of story yet.
node
If the modified entity is of type `node` then perfect (or almost perfect) because `lat` and `lon` are attributes available and can be used to determine the territory.
“Almost” because later I found that if the node is deleted in the change then no `lat` or `lon` will be available in the result. I will need to get the version, then call `node//` to get the node details before it was deleted in the change submitted by the player.
way
Ways have multiple nodes, the idea is that if you connect these nodes then you draw the “way”.
My imperfect solution is to find these nodes in the `` tag and use the first node to determine the territory. Would be great if I could determine the player’s location on the way when they made the edit so territory would be more accurate, but this limitation is somewhat acceptable and can be a fun glitch that impacts strategy and game play positively.
If the change was the deletion of a way we would also need to do the whole getting the version before it dance to be able to see any of those nodes.
relation
Relations are … wait a second, I need to consult the wiki.
“Relations are structured collections of objects – nodes, ways and other relations. Along with nodes and ways, they are one of the three core data elements of the OpenStreetMap data model.” — https://wiki.openstreetmap.org/wiki/Relation
Luckily this is clear enough, simple recursion will eventually get a location, a node at which we can say “good enough” and take its location as territory.
I want to add some logging of these relations to study them later and figure out their impact on the mechanics of the game (at least to find a clear way to communicate how score calculation works).
Network volume
These changes make score calculation network intensive, dramatically more network calls, so I will need to rethink the mechanics of updating scores during the game to optimize traffic and speed. If you wanna take a look at the code and follow along [RTM](https://resisttechmonopolies.online/)’s journey of building this app/game duality with the community of urbanists, maps lovers, and open source enthusiasts, here is the repo: https://git.coopcloud.tech/RTM/mapbattle