NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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's gravatar image

grccr
26112
accept rate: 0%

edited 27 Aug '14, 14:22

scai's gravatar image

scai ♦
33.3k21309459

1

Can you please explain what exactly "does not work"?

(27 Aug '14, 14:22) scai ♦
1

That URL definition looks wrong to me. Does this help?

(27 Aug '14, 14:31) SomeoneElse ♦

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 ......

(27 Aug '14, 14:36) grccr

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)

(27 Aug '14, 14:47) grccr

What is the correct path for the tiles on your system?

(27 Aug '14, 14:53) scai ♦

The path is C:\OpenStreetMap

(27 Aug '14, 14:56) grccr

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?

(27 Aug '14, 15:00) scai ♦

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.

(27 Aug '14, 15:23) grccr
1

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 and maxZoom to 19.

(27 Aug '14, 15:43) scai ♦

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 . . .

(27 Aug '14, 16:02) grccr
1

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.

(27 Aug '14, 16:30) scai ♦
1

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

(27 Aug '14, 16:47) grccr
2

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

(27 Aug '14, 16:56) grccr
showing 5 of 13 show 8 more comments

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×287
×38
×14

question asked: 27 Aug '14, 13:31

question was seen: 3,796 times

last updated: 27 Aug '14, 16:56

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum