I've cached tiles in Geoserver and I need display map in my android application over OSMDroid. I've tried it with my web application with OpenLayers and works fine like this:
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'http://localhost:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/{z}/{x}/{-y}.png'
})
})
So now I need display it in Android. I've created class for custom tile source:
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();
}
}
and here is my MainActivity class:
public class MainActivity extends AppCompatActivity {
@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(source);
//map.setTileSource(TileSourceFactory.MAPNIK);
}
public void onResume(){
super.onResume();
Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
}
}
Geoserver log print this:
2017-03-04 14:29:20,451 ERROR [geowebcache.GeoWebCacheDispatcher] - null http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/18/642/281
2017-03-04 14:29:20,460 ERROR [geowebcache.GeoWebCacheDispatcher] - null http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/18/639/281
2017-03-04 14:29:20,460 ERROR [geowebcache.GeoWebCacheDispatcher] - null http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/18/640/280
2017-03-04 14:29:20,472 ERROR [geowebcache.GeoWebCacheDispatcher] - null http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/18/637/281
2017-03-04 14:29:20,473 ERROR [geowebcache.GeoWebCacheDispatcher] - null http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/18/638/281
2017-03-04 14:29:20,480 ERROR [geowebcache.GeoWebCacheDispatcher] - null http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/18/639/280
2017-03-04 14:29:20,480 ERROR [geowebcache.GeoWebCacheDispatcher] - null http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/18/641/279
after geoserver turn up geoserver debugging log: http://pastebin.com/wTw5ASDC
At first I've tried Mapnik tile source and it works ... but my not :/ Can you tell me what I do wrong? Thanks
EDIT: I've editted my funcition getTileURLString to this and still not works:
@Override
public String getTileURLString(MapTile aTile) {
return TILE_URL[0] + "/" + aTile.getZoomLevel() + "/" + aTile.getX() + "/" + aTile.getY() + ".png";
}
so I tried url from log file in brwser and I got this:
and when I tried url with ".png" on the end I got this:
android studio terminal print this:
W/OsmDroid: Problem downloading MapTile: /10/651/444 HTTP response:
W/OsmDroid: Problem downloading MapTile: /10/649/444 HTTP response:
W/OsmDroid: Problem downloading MapTile: /10/648/445 HTTP response:
W/OsmDroid: Problem downloading MapTile: /10/650/445 HTTP response:
W/OsmDroid: Problem downloading MapTile: /10/649/445 HTTP response:
Is possible the osmdroid call url with wrong parameters? Becouse as you can see on picture, structure names are little different, and they contains underscore.