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.

Usage

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 freedesktop.org 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 geojson.io) 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.

Limitations

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.

Future

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:
Thanks!

5 comments:

  1. Awesome work! Do you plan adding KML and/or GPX support?

    ReplyDelete
    Replies
    1. Hi!

      Thanks! Yes we do plan to add at least KML:
      https://bugzilla.gnome.org/show_bug.cgi?id=757171

      Delete
  2. Geojson-vt is awesome for rendering data. Do you know if it's possible to interact with the data rendered by geojson-vt? (i.e. return feature info on click and hover. I'm using it in conjunction with leaflet).

    ReplyDelete
    Replies
    1. Well, it is possible, but we have not implemented it yet. It would be implemented in GNOME Maps rather than geojson-vt since all geojson-vt is "just" about splitting the feature up in vector-tiles on the fly.

      Bug here: https://bugzilla.gnome.org/show_bug.cgi?id=757144

      Delete
  3. Geojson-vt is awesome for rendering data. Do you know if it's possible to interact with the data rendered by geojson-vt? (i.e. return feature info on click and hover. I'm using it in conjunction with leaflet).

    ReplyDelete