How do I create maps from OSM?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Two types of minimap: "full map" and "player is the center" (square map and radial map)
  • Had a little game idea I wanted to try and play around with and came across a couple of games made by the developers 'Jutsu Games' and I love the Open Street Maps implementation they've used.

    So my question is how would I go about implementing road layouts, buildings , rivers, open land etc.. using the data from OSM?

    In slightly more depth I want to make it generate a top down 2D map from a set co-ordinate from OSM and the roads and buildings etc.. be in the right place from the map data and then have things like cars pathfinding along the roads picking up and delivering from different 'real world' buildings.

    I make the start of games in my free time and finish 0 of them so don't put yourselves out on this, it's purely a hobby and this is my next dive.

    Thanks in advance for any advice,

    John.

    Edit:

    store.steampowered.com/app/503560/911_Operator

    store.steampowered.com/app/1465460/Infection_Free_Zone

    Hoping its OK to share game links but these are the 2 I've played from them and both use real world maps.

  • At a glance OSM files are just xml files. Load the osm files into the xml plugin and you can get anything you need from that. You'll need to get familiar with xpaths to navigate the file.

    I was slightly curious so here's a start. Add an osm file to the files folder of your project, access the file with the ajax plugin, and finally load it into the xml plugin.

    One basic primitive in osm files are "nodes" which give lat/lons of points. Here's a way create a sprite at every node. Note that you need to adjust the lat/lon to convert them to reasonable xy positions on the layout.

    xmin = float(XML.StringValue("/osm/bounds/@minlon"))
    ymin = float(XML.StringValue("/osm/bounds/@minlat"))
    
    start of layout
    XML: for each node "osm/node"
    -- create sprite at (float(XML.StringValue("./@lon"))-xmin)*3000, -(float(XML.StringValue("./@lat"))-ymin)*3000

    Another basic primitive are "ways" which are made up of a list of the ids of nodes. Basically, polylines. A way to handle those is to first add the nodes to an array, and use a dictionary to relate the node ids to the array indexes.

    Beyond that there are tags in the ways and nodes in the osm file that indicate if they are a river, road or whatnot, but I didn't see any obvious patterns. You'll want to refer to the osm file format perhaps.

    wiki.openstreetmap.org/wiki/OSM_XML

    You could go further to see if there are other things you can access from the file.

    If you want to access osm data dynamically from open maps on the fly then that's out of the scope of what i'm interested in. I just was getting the osm files in my tests by going to the openmaps website, navigating to where I wanted, and exported it.

  • Appreciate it thank you, I will have a play around with it this weekend and see what I can do.

    Cheers.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So... the OSM file format doesn't provide too much. With some fiddling you can parse out roads, building outlines, coastlines, etc...

    You'd have to infer bodies of water, or overlay it over some satellite imagery.

    dropbox.com/scl/fi/mmxnxbiinnwbk65lly8i0/osm_loader.capx

    You can even use ajax to query some websites to get an osm file from any lat/lon. However, what the games you referenced probably do is utilize something like this to get map/satellite imagery on the fly:

    developers.google.com/maps/documentation/maps-static/overview

    You do have to pay a subscription for such a thing.

    If you're happy with offline methods you could use something like this to get the satellite imagery, as well as the height or any 3d buildings directly from google earth. Although I will say the pipeline for using this is pretty poor and incomplete.

    github.com/retroplasma/earth-reverse-engineering/tree/master

    For example I took some satellite imagery and converted it to a textured heightmap to use with mesh distort.

    dropbox.com/scl/fi/7k4acehi6zp9yx45lxal8/island_orbit.c3p

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)