在OSMDroid中显示Geoserver的地图

时间:2017-03-04 13:40:23

标签: android openlayers osmdroid geoserver tms

我在Geoserver中缓存了瓷砖,我需要在OSMDroid上安装我的Android应用程序中的地图。我已经使用OpenLayers的Web应用程序尝试了它并且工作得很好:

 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'
            })
        })

所以现在我需要在Android中显示它。我已经为自定义磁贴源创建了类:

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();
}

}

这是我的MainActivity类:

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日志打印:

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

geoserver打开geoserver调试日志后: http://pastebin.com/wTw5ASDC

起初我尝试过Mapnik磁贴源,它可以工作......但我的不是:/你能告诉我我做错了什么吗?感谢

编辑: 我已经将我的函数getTileURLString编辑到了这个并且仍然不起作用:

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

所以我在brwser的日志文件中尝试了url,我得到了这个: enter image description here

当我尝试使用“.png”的url时,我得到了这个: enter image description here

android studio terminal打印此:

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:

可能osmdroid调用url参数错误吗?正如你在图片上看到的那样,结构名称略有不同,它们包含下划线。 enter image description here

1 个答案:

答案 0 :(得分:0)

GeoServer说它不知道如何处理如下的请求:

http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/11/9/3

这是因为您没有指定图像格式,因此像这样的URL应该有效:

http://10.0.2.2:8080/geoserver/gwc/service/tms/1.0.0/Bachelor%3Av_slovensko_group@EPSG%3A3857@png/11/9/3.png