Monday, 26 October 2015

GeoJSON in Maps

For Maps 3.19.1 release we managed to land some support for showing  a GeoJSON layer. This means that you can get a GeoJSON file from somewhere then open it with Maps.


The different ways to load GeoJSON with Maps is currently...
... from the command line: gnome-maps file.geojson
... drag the file to a Maps window
... double click the file to open it with Maps

In order for double clicking the GeoJSON file to work we need to install the application/vnd.geo+json mime-type on the desktop. I have added the mime-type to the component shared-mime-info. So you will need a release from that module or build it yourself from Git.

GeoJSON files can be used to create a custom layer above the map. For instance displaying political areas like counties or voting area. An example would be all the municipalities of Norway.

You can also add different places, for instance GUADEC this year will be at Karlsruhe. The bid I saw included four different options for venue. We could map this using GeoJSON (I used to create a layer showing the different options on the map.

Heavy lifting by Mapbox

It turns out rendering large sets of GeoJSON is non-trivial. Fortunatly it is something that Mapbox already has solved with their JavaScript library called geojson-vt. Under the heading of "Rendering big geodata on the fly with GeoJSON-VT" the article describes how the library breaks down the GeoJSON set into vector tiles by filtering out features, optimizing detail and clipping.

We lift the code into Maps, we have to change the way the geojson-vt modules include each other in order to fit into the gjs way of doing things, but other than that, the code is unchanged. The code is then used to construct a libchamplain tile source and is then added as an overlay source to the map view.


Right now the code will only handle GeoJSON files that do not change the Coordinate Reference System (crs) to something other than the one we are used to (latitude and longitude ranging from -180/-90 to 180/80).

No styling information is taken into account (except the name property for Points). There is no standard GeoJSON styling style. But we could for instance support the one from Mapbox.


Styling and UX for this feature may change before we end up in 3.20. Please try it out and comment and file bugs. It will help us!

If you want to help out now there are some tasks to look at: