Use OSM Tag in jxMapViewer2

Hello community,

I am currenty using Java Swing and jxMapViewer2.
What I would like to achieve is to display hydrant positions on my map
(kinda like an overlay).
Does someone know if it’s possible to use the emergency=fire_hydrant in jxMapViewer2 ?

Thank you in advance

The general approach is:

  1. Obtain the coordinates (pairs of longitude and latitude) of the fire hydrants
  2. Use a WaypointPainter to draw them on the map.

I assume that you’re able to do step 2 (placing markers once you have the coordinates), and are stuck at step 1?

As far as I know, jxMapViewer2 has no built-in functionality for handling OSM data. So to get the hydrant coordinates from OSM, you’ll need a separate library for reading OSM data (osm4j is a good candidate) and some place to get OSM data from. This might be a local XML file if you only need it to work for a small area and are ok with manual updates, or you could use Overpass API to query OSM data.

Here’s an example snippet for getting OSM data from Overpass API into osm4j:

String apiURL = "";
String queryString = "..."; // your Overpass API query, test it on Overpass Turbo first

URL url = new URL(apiURL);

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

try (DataOutputStream printout = new DataOutputStream(connection.getOutputStream())) {

	printout.writeBytes("data=" + URLEncoder.encode(queryString, "utf-8"));


try (InputStream inputStream = connection.getInputStream()) {
	OsmXmlIterator iterator = new OsmXmlIterator(inputStream, false);
	// refer to osm4j documentation for how to use an OsmXmlIterator to access OSM nodes
1 Like

Thanks, will take a look at it