0

I try to create Java Swing Desktop application which show Road map of some area in JFrame. But pc not connected to internet it will be in LAN. Map should be like if we scroll the mouse we go down from height in map. Like zooming the area.

I try to find out by google i get lots of forum links but each showing me.

  1. I have to do web application.
  2. Google not support 'without internet' map facility.
  3. I should use lots of jpgs which store in folder for showing map frenter code hereom various height so it look like when we see any map in Google Earth application.

I found goworldwind.org but not clear understanding right now.

Any clue/idea how should i do?

Hi have used below program to show map in jxbrowser

package dummy;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserFactory;

public class GoogleMapDemo {
public static final int MIN_ZOOM = 0;
public static final int MAX_ZOOM = 21;
private static int zoomValue = 4;

public static void main(String[] args) {
final Browser browser = BrowserFactory.create();

JButton zoomInButton = new JButton("Zoom In");
zoomInButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (zoomValue < MAX_ZOOM) {
browser.executeJavaScript("map.setZoom(" + ++zoomValue + ")");
}
}
});

JButton zoomOutButton = new JButton("Zoom Out");
zoomOutButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (zoomValue > MIN_ZOOM) {
browser.executeJavaScript("map.setZoom(" + --zoomValue + ")");
}
}
});

JPanel toolBar = new JPanel();
toolBar.add(zoomInButton);
toolBar.add(zoomOutButton);

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(browser.getView().getComponent(), BorderLayout.CENTER);
frame.add(toolBar, BorderLayout.NORTH);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

browser.loadURL("/home/StaticMapDemo/map.html");
//browser.loadURL("http://www.google.com");
    }
}

I have map.html file

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB7J1zsErb9_7jxNu5KU5kIENFObAQEbl0&;sensor=false">
</script>
<script type="text/javascript">
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(48.209331, 16.381302),
zoom: 4
};
map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</html>

while running program i am getting below errors on console

11:59:16 INFO: OS name: Linux 11:59:16 INFO: JRE version: 1.7 32-bit 11:59:16 INFO: JxBrowser build: ${build.number} 11:59:16 INFO: Starting IPC... 11:59:16 INFO: Starting IPC Server... 11:59:16 INFO: Starting IPC Process... 11:59:16 INFO: Start Chromium process... 11:59:16 INFO: The '/lib/i386-linux-gnu/libudev.so.0' library exists: FALSE 11:59:16 INFO: The '/tmp/jxbrowser-chromium-31.0.1650.57.8/libudev.so.0' library exists: FALSE 11:59:16 INFO: Looking for libudev.so.x.x.x in '/lib/i386-linux-gnu'... 11:59:16 INFO: Looking for libudev.so.x.x.x in '/lib64'... 11:59:16 INFO: Failed to find libudev.so.x.x.x in '/lib64' and '/lib/i386-linux-gnu' 11:59:16 INFO: Command line: /tmp/jxbrowser-chromium-31.0.1650.57.8/jxbrowser-chromium 1101 11:59:16 INFO: Chromium process exit code 127 11:59:16 INFO: /tmp/jxbrowser-chromium-31.0.1650.57.8/jxbrowser-chromium: error while loading shared libraries: libexpat.so.1: cannot open shared object file: No such file or directory Exception in thread "main" com.teamdev.jxbrowser.chromium.BrowserException: Failed to create Browser. at com.teamdev.jxbrowser.chromium.BrowserFactory.create(Unknown Source) at com.teamdev.jxbrowser.chromium.BrowserFactory.create(Unknown Source) at com.teamdev.jxbrowser.chromium.BrowserFactory.create(Unknown Source) at dummy.GoogleMapDemo.main(GoogleMapDemo.java:25) Caused by: com.teamdev.jxbrowser.chromium.internal.ipc.IPCException: IPC process exited. Exit code: 127 at com.teamdev.jxbrowser.chromium.internal.ipc.k.run(Unknown Source) at java.lang.Thread.run(Thread.java:744) 11:59:16 INFO: Shutdown IPC... Exception in thread "Thread-1" java.lang.NullPointerException at com.teamdev.jxbrowser.chromium.internal.ipc.IPC.b(Unknown Source) at com.teamdev.jxbrowser.chromium.internal.ipc.IPC.shutdown(Unknown Source)` at com.teamdev.jxbrowser.chromium.internal.aq.run(Unknown Source) at java.lang.Thread.run(Thread.java:744)

AM I going in right direction showing static map in swing application on standalone pc if yes then Please help

Neelam Singh
  • 619
  • 1
  • 6
  • 10

1 Answers1

3

If I understand the question right you are looking for a world map that you can use in your application offline? Being able to do this is problematic because a world map would be very large and I don't suppose there is a world map where the author will allow you to download the entire content.

However, if you are satisfied with only a piece of a world map, maybe this website could be to help: http://www.openstreetmap.org/. They offer an open source world map, and if you take a look at the export tab you can find information about how to get a hold of downloadable content for offline use.

If you are looking for a code example with the functionality of moving around and zooming on this map I suggest you try to write it yourself and create a new question if you encounter any code specific problems.

Robin
  • 1,927
  • 3
  • 18
  • 27
  • 1
    +1, [JMapViewer](http://wiki.openstreetmap.org/wiki/JMapViewer) is a Swing component that integrates with OSM. – tenorsax Jul 20 '14 at 15:24
  • Thanks Robin for your answer !!! I have gone through http://www.openstreetmap.org/ link and exported a small piece of map.osm file. After that how can i use map.osm into my swing application Please provide any example links – Neelam Singh Jul 21 '14 at 06:07
  • Hi have used following code to show map in jxbrowser – Neelam Singh Jul 21 '14 at 06:36
  • You could take a look at this GIS-question: http://gis.stackexchange.com/questions/74538/how-to-use-openstreetmap-in-java – Robin Jul 21 '14 at 06:37
  • Hi robin can you have a look on my above question edit wheather I am going in right direction – Neelam Singh Jul 21 '14 at 06:52