Display map in OsmDroid from local Geoserver

388 views
Skip to first unread message

schwantn...@gmail.com

unread,
Mar 5, 2017, 7:29:17 AM3/5/17
to osmdroid
Hi, I cached tiles Geoserver and I've tried it in OpenLayers for sure that works. When I tried display map in OsmDroid, Android studio print for every tile this message:
W/OsmDroid: Problem downloading MapTile: /10/651/444 HTTP response

Here is my main code in MainActivity:

@Override
public void onCreate(Bundle savedInstanceState) {
   
super.onCreate(savedInstanceState);
   
Context ctx = getApplicationContext();
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
    setContentView
(R.layout.activity_main);

   
MapView map = (MapView) findViewById(R.id.map);

   
GeoserverTileSource source = new GeoserverTileSource("geoserver", 10, 18, 256, ".png", GeoserverTileSource.TILE_URL);

    map
.setTileSource(source);

   
IMapController mapController = map.getController();
    mapController
.setZoom(13);
   
GeoPoint startPoint = new GeoPoint(48.82, 22.00);

    mapController.setCenter(startPoint);

   
//map.setTileSource(TileSourceFactory.MAPNIK);
}

public void onResume(){
   
super.onResume();
    Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
}


And GeoserverTileSource class:
public class GeoserverTileSource extends OnlineTileSourceBase {

public static String[] TILE_URL = {"http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/"};

public GeoserverTileSource(String aName, int aZoomMinLevel, int aZoomMaxLevel, int aTileSizePixels, String aImageFilenameEnding, String[] aBaseUrl) {
super(aName, aZoomMinLevel, aZoomMaxLevel, aTileSizePixels, aImageFilenameEnding, aBaseUrl);
}

@Override
public String getTileURLString(MapTile aTile) {
return TILE_URL[0] + aTile.getZoomLevel() + "/" + aTile.getX() + "/" + aTile.getY() + ".png";
}
}

Can you tell me what I wrong? OsmDroid always display only gray grid. I am using osmdroid osmdroid-android:5.6.4 and Geoserver 2.9.4. Thanks


Alex O'Ree

unread,
Mar 5, 2017, 8:09:09 AM3/5/17
to osmdroid
Same question was asked here https://github.com/osmdroid/osmdroid/issues/563

Try turning on the map tile downloading debug option to get additional output.

Put whatever URL osmdroid is trying to download into your browser and confirm geoserver returns a tile.

Also, I was never got the tms endpoint on geoserver to work. Try figuring out the url pattern that the layer preview page uses and then use that.
Message has been deleted

schwantn...@gmail.com

unread,
Mar 5, 2017, 8:57:58 AM3/5/17
to osmdroid
So I check this thread before and don't help me ... I try my code to this:
@Override
public void onCreate(Bundle savedInstanceState) {
   
super.onCreate(savedInstanceState);
   
Context ctx = getApplicationContext();

   
//important! set your user agent to prevent getting banned from the osm servers
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
    setContentView
(R.layout.activity_main);

   
MapView map = (MapView) findViewById(R.id.map);


   
//GeoserverTileSource source = new GeoserverTileSource("geoserver", 10, 18, 256, ".png", GeoserverTileSource.TILE_URL);
    //map.setTileSource(TileSourceFactory.MAPNIK);
    //map.setTileSource(source);
    final MapTileProviderBasic tileProvider = new MapTileProviderBasic(this);
   
final ITileSource tileSource = new XYTileSource("geoserver_tiles", 5, 18, 256, ".png", new String[]{"http://192.168.182.1:8080/geoserver/gwc/service/tms"}) {

       
@Override
        public String getTileURLString(MapTile aTile) {

           
String url = "http://192.168.182.1:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/" + aTile.getZoomLevel() + "/" + aTile.getX() + "/" + aTile.getY() + ".png";
           
Log.d("TILE | ", url);
           
return url;
       
}
   
};
    map
.setTileSource(tileSource);

   
IMapController mapController = map.getController();
    mapController
.setZoom(13);
   
GeoPoint startPoint = new GeoPoint(48.82, 22.00);
    mapController
.setCenter(startPoint);


}

and still not working ... So I try open Url which I printed into android studio, and open it in browser and result of this you can see on picture :

AsmDroid got me same error: W/OsmDroid: Problem downloading MapTile: /13/5205/3579 HTTP response:
Next I try check url, which are called by OpenLayers in my web application, on same server. And when I open it, browser got me image tile and not this message about coverage. So I think OsmDroid call service with wrong tile numbers, but I have no idea how to fix it .. I am totaly new in android. I am using projection 3857 which should works fine.

Dňa nedeľa, 5. marca 2017 14:09:09 UTC+1 Alex O'Ree napísal(-a):

Alex O'Ree

unread,
Aug 20, 2017, 5:11:19 PM8/20/17
to osmdroid
what you need is a wms client. There's some sample code at https://github.com/osmdroid/osmdroid/issues/563 
Reply all
Reply to author
Forward
0 new messages