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


Joined
Dec 16, 2021
Messages
2
Reaction score
0
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.
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
174
Reaction score
19
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.
 
Joined
Dec 16, 2021
Messages
2
Reaction score
0
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.setAddressLocation(geo);
jXMapViewer.setZoom(6);

MouseInputListener mm = new PanMouseInputListener(jXMapViewer);
jXMapViewer.addMouseListener(mm);
jXMapViewer.addMouseMotionListener(mm);
jXMapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCenter(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.
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
174
Reaction score
19
Finally cracked it! There's was too much info to sift through. Alrighty, the easiest way is to use QGIS.

1. Download and install 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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top