Print Shortlink

Java component JMapViewer with offline OpenStreetMap support

For a prototype that is running in an isolated environment I was in need of an offline OpenStreetMap component for Java. Of all the awesomeness that OpenStreetMap does provide this was not one of them.

Luckily I’m not the person that is afraid of some quick hack-n-slash work. After inspecting the code of JMapViewer which is released under GPL by OpenStreetMap I quickly found out to add support for OpenStreetMap by creating an extension of¬†AbstractOsmTileSource. A stunning 29 lines of code later and offline support was ready. I put it up on GitHub in case anyone is interested in it as well:¬†https://github.com/balloob/JMapViewer

I put up a full copy of their SVN-repository with my offline-class included. Just the class can be found here.

How to use it:

JMapViewer map = new JMapViewer(); 
map.setTileSource(new OfflineOsmTileSource("file:///path/to/tiles/",1,9));

Downloading tiles
To download the Open Streetmap tiles to your computer you can use jTileDownloader.

Note that jTileDownloader 0.6 requires Java 7. It will not throw an error when an older JRE is used untill you click the download button.

As of this writing (August 2, 2012) Apple has not released Java 7 for OS X yet.

5 Responses

  1. Nikola

    Hi Paulus,

    Great post! I just wanted to ask if there is possibility to put marker on the offline map using in the way that you described?

  2. Kyle

    Hi Paulus,

    I’m thinking about using JMapViewer as a Display engine for a desktop GIS application that will use a combination of OSM data and private GIS data. But before I get started, I was curious if you of an other projects, companies, or agencies that have developed products using JMapViers?

    Thanks,

    Kyle

  3. Janith

    hi Paulus,

    You know how to add dynamically changing real-time position marks to JMapViewer.

Leave a Reply to Paulus Schoutsen Click here to cancel reply.