openmobilemaps / maps-core

The lightweight and modern Map SDK for Android and iOS
https://openmobilemaps.io
Mozilla Public License 2.0
158 stars 17 forks source link

Zoom value is always 1 #267

Closed nicolaiendios closed 1 year ago

nicolaiendios commented 1 year ago

I followed the README.md example in order to get the map to work using an open street map URL but the Tiled2dMapLayerConfig always returns 1 as the zoom. My getTileUrl() function looks like this:

 override fun getTileUrl(x: Int, y: Int, zoom: Int): String {
            Log.d(TAG, "getTileUrl x:$x , y:$y , zoom:$zoom")
            return"https://tile.openstreetmap.org/$zoom/$x/$y.png"
        }

The logs tell me that the zoom is always 1 even if I pinch zoom in or out: getTileUrl x:1081 , y:659 , zoom:1 The Map looks like this: activity_open_mobile_maps_dynamic

If I hardcode the zoom value to 15 for example:

 override fun getTileUrl(x: Int, y: Int, zoom: Int): String {
            Log.d(TAG, "getTileUrl x:$x , y:$y , zoom:$zoom")
            return"https://tile.openstreetmap.org/15/$x/$y.png"
        }

I initially see only ocean: activity_open_mobile_maps_zoomed_out_hardcoded

but if I zoom in using pinch gestures I can at some point see the map: activity_open_mobile_maps_zoomed_in_hardcoded

I uploaded the Activity here.

Any idea how I can make it work?

maurhofer-ubique commented 1 year ago

Hi Nicolai,

It seems that the zoomLevelIdentifier-parameter in your layers zoomLevelInfos is always set to 1. When changing those to the correct values, your example works for me. I.e.

private val zoomLevelInfos = ArrayList(
        listOf(
            Tiled2dMapZoomLevelInfo(559082264.029, 40075016f, 1, 1, 0, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(279541132.015, 20037508f, 2, 2, 1, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(139770566.007, 10018754f, 4, 4, 2, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(69885283.0036, 5009377.1f, 8, 8, 3, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(34942641.5018, 2504688.5f, 16, 16, 4, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(17471320.7509, 1252344.3f, 32, 32, 5, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(8735660.37545, 626172.1f, 64, 64, 6, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(4367830.18773, 313086.1f, 128, 128, 7, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(2183915.09386, 156543f, 256, 256, 8, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(1091957.54693, 78271.5f, 512, 512, 9, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(545978.773466, 39135.8f, 1024, 1024, 10, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(272989.386733, 19567.9f, 2048, 2048, 11, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(136494.693366, 9783.94f, 4096, 4096, 12, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(68247.3466832, 4891.97f, 8192, 8192, 13, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(34123.6733416, 2445.98f, 16384, 16384, 14, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(17061.8366708, 1222.99f, 32768, 32768, 15, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(8530.91833540, 611.496f, 65536, 65536, 16, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(4265.45916770, 305.748f, 131072, 131072, 17, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(2132.72958385, 152.874f, 262144, 262144, 18, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(1066.36479193, 76.437f, 524288, 524288, 19, epsg3857Bounds),
            Tiled2dMapZoomLevelInfo(533.18239597, 38.2185f, 1048576, 1048576, 20, epsg3857Bounds)
        )
    )

This maybe could have happened, because this pattern was updated with an additional tile parameter on the develop branch, which in turn is the default branch on the repository. The dependency you are using is from the release of the latest commit on main. Please refer to the matching readme (found here).

Please also note that you only set a camera position with your button click. Without an initial camera adjustment, it is at the 0/0 coordinates of your system, which in the case of EPSG:3857 is near the coast of West Africa.

nicolaiendios commented 1 year ago

Thank you so much for you r fast response @maurhofer-ubique! It works perfectly now!