Page 1 of 2

osmlove library (OSM maps in your Love2D projects)

Posted: Sun Apr 02, 2017 7:04 pm
by dusoft
Hi,

I have created a library that allows you to use geoJSON file (OSM XML to be implemented soon) and draw a map based on this.

Currently, only roads/streets/sidewalks/bridges (OSM type 'highways') are supported, but implementation of others is easy and will be coming. Custom rules can be defined regarding what to draw, what colors to use and parameters passed to draw only selected region based on lat/long coordinates or zoom to be used etc.

You can use it for backgrounds or e.g. drawing a map somewhere as a part of the game - picture on a wall, map on a table etc.

I am resolving some issues with the canvas caching, once it's ready, I'll publish it to github and link it here.

Screenshot of simplified map (b&w only, basic rules defined):
osmlove bratislava, zoom 2 (half city)
osmlove bratislava, zoom 2 (half city)
osmlove.png (289.31 KiB) Viewed 8581 times
osmlove addis ababa, zoom 1 (whole city)
osmlove addis ababa, zoom 1 (whole city)
osmlove2.png (377.9 KiB) Viewed 8576 times

Re: osmlove library (OSM maps in your Love2D projects)

Posted: Mon Apr 03, 2017 4:32 am
by mtdev
Cool! Looking forward to seeing where this goes.

Re: osmlove library (OSM maps in your Love2D projects)

Posted: Mon Apr 03, 2017 6:38 am
by zorg
dusoft wrote: Sun Apr 02, 2017 7:04 pm You can use it for backgrounds or e.g. drawing a map somewhere as a part of the game - picture on a wall, map on a table etc.
I'm pretty sure i could use this data to generate the actual game world based on this, if i wanted to; without height-map information, of course. :3

Re: osmlove library (OSM maps in your Love2D projects)

Posted: Mon Apr 03, 2017 9:52 am
by dusoft
Indeed, creating worlds based on this was my goal (creating street network for transport game) - that's basically, why I have decided to develop this.

Re: osmlove library (OSM maps in your Love2D projects)

Posted: Mon Apr 03, 2017 1:43 pm
by mtdev
Can it create a simple political map of a region? It would be cool to be able to select individual countries, states, provinces, etc. Could be so many possibilities :)

Re: osmlove library (OSM maps in your Love2D projects)

Posted: Mon Apr 03, 2017 3:54 pm
by pedrosgali
This is incredibly cool, I had no idea I wanted this until I saw it and now I can't stop thinking about what I could make with it. Good job.

Re: osmlove library (OSM maps in your Love2D projects)

Posted: Mon Apr 03, 2017 9:49 pm
by dusoft
mtdev wrote: Mon Apr 03, 2017 1:43 pm Can it create a simple political map of a region? It would be cool to be able to select individual countries, states, provinces, etc. Could be so many possibilities :)
Indeed, it can draw anything based on the preset rules. However, as of now only rules for "highway" type of "ways" are supported.
See for OSM element details: https://wiki.openstreetmap.org/wiki/Elements

Re: osmlove library (OSM maps in your Love2D projects)

Posted: Thu Apr 06, 2017 9:43 pm
by dusoft
Enjoy early alpha (v0.1):
https://github.com/nekromoff/osmlove

Re: osmlove library (OSM maps in your Love2D projects)

Posted: Fri Apr 07, 2017 2:03 pm
by dusoft
Please, send me your ideas on what to prioritize during development. What would you use this in your games for?

Generating worlds based on maps? If yes, is data table with existing structures (roads, rivers etc.) useful for you?

Drawing maps in-game? If yes, what further options you need for drawing?

Etc.

Any feedback welcome!

Re: osmlove library (OSM maps in your Love2D projects)

Posted: Fri Apr 07, 2017 2:25 pm
by zorg
A questions:
The init function has a few parameters, but it's somewhat unclear what they really do.
The file is of course self-explanatory, the region limits are there, i assume, because one might download a bigger map, and may only want part of it to be used in-game at a time, for example.
The width and height will be the canvas properities, i suppose.
So, if you define the usable area in terms of the input area, and the usable area in terms of the output graphic, what does the zoom parameter do? Or rather, which other parameter(s) will it modify?

A few ideas:
- Make the library be stateless, in the sense that currently, you require the lib once, and it stores one map you load; it can't create more than one at a time. Here's an interesting read on the subject: http://kiki.to/blog/2014/04/11/rule-4-m ... s-modules/
- Since this is for Löve, i'd prioritize rewriting lua io functions into love.filesystem ones.
- _setupMap resets the active canvas to the screen at its end; you don't know what someone may have set it before calling this function, so you should either store that info in the function with the similarly named getter, and set it back to that at the end of the function, or use love.graphics.push('all'), since that also stores the active canvas, i believe (with that parameter).
- Have a separate function for setting the (coloring) rules, and not do it per-frame with osmlove.drawMap
- Also don't force the alpha+premultiplied drawmode on people; maybe mention it that it should be used.
- This one's a tiny nitpick, but maybe just have the above function be named draw? it would be shorter and more consistent with Löve's API.
- (Similarly, init -> load, though if it's not exposed, it doesn't matter.)