Dear all,
Could you please advise me on the way I could use JMapViewer with stored map data (osm file or tiles extracted by Maperitive) for real-time gps tracking?
I have used the following code to set the tiles or osm source but this does not work:
final JMapViewer map = new JMapViewer();
map.setTileSource(new OfflineOsmTileSource("file://c:/OpenStreetMap/", 1, 12));
where OfflineOsmTileSource class:
public class OfflineOsmTileSource extends AbstractOsmTileSource
{
private final int minZoom;
private final int maxZoom;
public OfflineOsmTileSource(String path, int minZoom, int maxZoom) {
super("Offline from "+path, path);
this.minZoom = minZoom;
this.maxZoom = maxZoom;
}
@Override
public int getMaxZoom() {
return maxZoom;
}
@Override
public int getMinZoom() {
return minZoom;
}
@Override
public TileUpdate getTileUpdate() {
return TileUpdate.None;
}
}
Thanks in advance.
Best wishes
George
asked
27 Aug '14, 13:31
grccr
26●1●1●2
accept rate:
0%
Can you please explain what exactly "does not work"?
That URL definition looks wrong to me. Does this help?
Thank you for your reply. The problem is that it fails to load the osm file or the tiles. osm file: failed loading 3/3/1 c failed loading 3/5/2 c ....... tiles: failed loading 3/5/1 c failed loading 3/5/2 c ......
I changed the argument to map.setTileSource(new OfflineOsmTileSource((new File("C:\OpenStreetMap").toURI().toURL()).toString(), 1, 12)); but the problem remains
output: failed loading 3/4/2 C:\OpenStreetMap\3\4\2.png (The system cannot find the path specified) ....... failed loading 3/4/3 C:\OpenStreetMap\3\4\3.png (The system cannot find the path specified)
What is the correct path for the tiles on your system?
The path is C:\OpenStreetMap
That's not the correct path according to your error message or it doesn't contain any tiles. Please search for files named "2.png" in C:\OpenStreetMap and compare the path with the one passed to
OfflineOsmTileSource
. Maybe there is another subdirectory you forgot to add?Thank you for your time to help me. Maybe I am using the wrong data to load. I have made two attempts: 1) In the directory c:\openstreetmap I saved a map.osm file exported for the openstreetmap.org 2) In the directory c:\openstreetmap I saved tiles generated from the above mentioned map.osm by Maperitive. In this case I have three main folders 17, 18, 19 and each of these folders contains other folders and each of these contains a .png file. I have noticed that next to the three folders there is a tiles.json file. Additionally there is no 2.png file as indicated by the error message.
I have no experience with JMapViewer but it seems like you just got the wrong zoom level. You only have subdirectories for zoom levels 17, 18, 19 but you are trying to open tiles for zoom level 3 (the first number in 3/4/2). Try to generate tiles for all zoom levels (probably expensive) or set
minZoom
to 17 andmaxZoom
to 19.Thanks again for your help. I just changed the zoom levels to 17-19 but the error remains. output: failed loading 17/68800/44416 C:\OpenStreetMap\17\68800\44416.png (The system cannot find the path specified) failed loading 17/68799/44416 C:\OpenStreetMap\17\68799\44416.png (The system cannot find the path specified)
There is no subfolder 68800 or 68799. The available subfolders are: 74685, 74686, 74687. 17/74685/51764.png 17/74685/51765.png 17/74686/61764.png . . .
Then I assume you are looking at the wrong part of the map. For the current location there are no tiles present. Go to a location for which you have tiles generated by Maperitive.
You are correct! At the command map.setDisplayPositionByLatLon(lat, lon, zoom); I have to put a location inside the tiles I am loading and the correct zoom level(in my case 17/18/19) too. Thank you so much for your help! Best wishes George
For those that are interested in JMapViewer the correct command for the tile source is : map.setTileSource(new OfflineOsmTileSource((new File("C:\OpenStreetMap").toURI().toURL()).toString(), 17, 19)); Thank you all for your contribution! Best wishes George