# How to use Offline Navigable Map in Netbeans IDE with Java Swing

#### Seyit

I am developing a program that will run on linux using java swing in netbeans.

I tried using the jxmapviewer library with open street map but I was only able to view the map online.

Since the system will not be connected to the internet, I need to view the map offline, I need to show the information I get from the gps on the map and I need to keep a record of this information.

How can I do it? Thank you for your help.

#### CodeMonkeyJ

Are you using jxmapviewer2? The easiest way to do that would be to create/use a FileBasedLocalCache and pre-populate the cache directory before moving it to the offline system. If you need more help, I'll look further into it.

#### Seyit

Are you using jxmapviewer2? The easiest way to do that would be to create/use a FileBasedLocalCache and pre-populate the cache directory before moving it to the offline system. If you need more help, I'll look further into it.

Yes, I am using jxmapviewer2.

public void InitMap(){
TileFactoryInfo info = new OSMTileFactoryInfo();
DefaultTileFactory tileFactory = new DefaultTileFactory(info);
jXMapViewer.setTileFactory(tileFactory);
GeoPosition geo = new GeoPosition(36.9195515,30.7310971);
jXMapViewer.setZoom(6);

MouseInputListener mm = new PanMouseInputListener(jXMapViewer);
}

I did it as you see above. But when I do that, it reads the map from the internet. I guess I need to download the map and show the file path, but I don't know how to do it. I would be glad if you can help me in more detail.

#### CodeMonkeyJ

Finally cracked it! There's was too much info to sift through. Alrighty, the easiest way is to use QGIS.

2. Add a data layer. This is pretty vague, 'cause there's a LOT of ways you can do it. You can go as far as using the 1500GB Planet.osm file from OpenStreetMap or import a GeoTIFF, such as Natural Earth. In those cases, you hit the Layer menu on top, Add Layer, and use Add Vector Layer (for OSM files and the like) or Add Raster Layer (for GeoTIFFs and other pixel-based images).
3. Use the Processing Toolbox, Raster tools, "Generate XYZ tiles (Directory)". (Processing at the top, Toolbox. When it comes up to the right, under "Raster tools", "Generate XYZ tiles (Directory)").
4. Select your parameters. The Extent is what part of the map to make tiles for, or use the entire map. Min zoom is how far out you can zoom, down to 0. Max zoom is how far in to zoom (I believe 18 is the highest OSM uses?). Select your output directory at the bottom. This process might take a LONG time and a lot of space, depending on your settings and computer.
5. Zip up those numeric folders created (into a .zip). The first folders are the Z or zoom level. They should be the top level of the zip file.
6. Now, follow Sample9 and add new OSMTileFactoryInfo() arguments for the type and the path of the zip file.

If anything is unclear, not working, or not specific enough, let me know!