28

I use MapsForge 0.8 to display maps in my Android app. When using online tiles (which are just bitmaps and not vector data that can be adjusted in the runtime renderer), the map is really tiny on my Hi-resolution device and I can't read anything.

screenshot

I would like to scale the map and I have tried the following:

mapView.getModel().displayModel.setDefaultUserScaleFactor(2.0f);

And:

mapView.getModel().displayModel.setUserScaleFactor(2.0f);

But it does not change anything.
How to make it display the map bigger?

Update:

And I don't mean zooming in. I mean scaling the current zoom level to make it readable on high-resolution devices. Imagine the screenshot above on a small smartphone - it is tiny. I can't even read the street names.

2nd Update

The current answers below do NOT answer the question. This is about scaling Online tiles which are BITMAPS - and NOT how to influence rendering the vector data.

3rd Update

The accepted answer finally solved the issue!

Community
  • 1
  • 1
juergen d
  • 201,996
  • 37
  • 293
  • 362

6 Answers6

6

As per this documentaion,(Read Specifying the Position section) you can specify area to display and at what zoom level.

this.mapView.setCenter(new LatLong(52.517037, 13.38886));
this.mapView.setZoomLevel((byte) 12);

Above solution will work as it is provided in official documentation.

Apart from this I have also searched regarding this and find out we can also set MapPosition to MapViewPosition like(See this link).

MapPosition mapPosition1 = new MapPosition(new LatLong(52.517037, 13.38886), (byte) 12);
this.mapView.getModel().mapViewPosition.setMapPosition(mapPosition1);

Hope this will help you.

Pravin Divraniya
  • 4,223
  • 2
  • 32
  • 49
  • 1
    Great answer but not what I was looking for. See my update please. – juergen d Jan 17 '17 at 11:49
  • After your update got your point.....You need to scale the map UI elements so that it can be readable while persisting the zoom level. – Pravin Divraniya Jan 17 '17 at 13:10
  • Check this [link](https://github.com/mapsforge/mapsforge/issues/644) . I think this is similar to your question and in _enhancement_. Also check [this](https://github.com/mapsforge/mapsforge/issues/814). – Pravin Divraniya Jan 17 '17 at 13:46
  • When using the renderer - vector graphics that get rendered at runtime - then yes. This already works for maps I downloaded. But the online tiles - which are just bitmaps - are already as is. All I could do is scale the image tiles somehow. But not like you describe. Thanks anyway. – juergen d Jan 17 '17 at 20:02
  • Ok....Whether you have control over that bitmap? I mean are you able to get those list of bitmaps? – Pravin Divraniya Jan 18 '17 at 08:23
  • I could look into the implementation of mapsforge and hack into there - but I am looking for a way to call a method and done. I don't want to start implementing my own mapsforge extension. – juergen d Jan 18 '17 at 08:30
  • May be I am totally wrong but it seems you are finding a way to call **scaleTo(int width, int height)** method in [AndroidBitmap](https://github.com/mapsforge/mapsforge/blob/master/mapsforge-map-android/src/main/java/org/mapsforge/map/android/graphics/AndroidBitmap.java). Is it so then check [AndroidTileBitmap](https://github.com/mapsforge/mapsforge/blob/master/mapsforge-map-android/src/main/java/org/mapsforge/map/android/graphics/AndroidTileBitmap.java) also. – Pravin Divraniya Jan 18 '17 at 08:58
  • It is not that simple. Scaling the bitmaps would mean I also have to adjust the position on the screen since everything would be changing in dimensions. – juergen d Jan 19 '17 at 07:12
  • 1
    Yes...I totally agree with you...This is not a simple thing and would require so much customization in existing library....I just found this method in library so though it will help you in R&D. hope you will find a way to do it. – Pravin Divraniya Jan 19 '17 at 07:23
1

There are a lot of ways of 'scaling' in mapsforge.
As it is shown in this example, you can try to .zoom() the mapViewPosition instead of scaling the Model directly.
If that is what you're asking for, try the following:

Code:

MapViewPosition mapViewPosition = mapView.getModel().mapViewPosition; 
mapViewPosition.zoom((byte) XX); // Change it to a number (i.g. "(byte) 3")

I can't even read the street names.

But if you are talking about the UI TEXT instead, you can try to change it like this:

mapView.setTextScale(XX); // Again, number goes here

If only the text size isn't enough for you, you may try creating a new RenderTheme instead.
Docs' Example:

Code:

tileRendererLayer.setXmlRenderTheme(new ExternalRenderTheme(File)) // File should be
                                                 // the XML file for the RenderTheme

XML:

<?xml version="1.0" encoding="UTF-8"?>
    <rendertheme xmlns="http://mapsforge.org/renderTheme" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mapsforge.org/renderTheme renderTheme.xsd" version="1">

    <!-- matches all ways with a "highway=trunk" or a "highway=motorway" tag -->
    <rule e="way" k="highway" v="trunk|motorway">
        <line stroke="#FF9900" stroke-width="2.5" />
    </rule>

    <!-- matches all closed ways (first node equals last node) with an "amenity=…" tag -->
    <rule e="way" k="amenity" v="*" closed="yes">
        <area fill="#DDEECC" stroke="#006699" stroke-width="0.3" />
    </rule>

    <!-- matches all nodes with a "tourism=hotel" tag on zoom level 16 and above 
-->
    <rule e="node" k="tourism" v="hotel" zoom-min="16">
        <symbol src="file:/path/to/symbol/icon/hotel.png" />
        <caption k="name" font-style="bold" font-size="10" fill="#4040ff" />
    </rule>
</rendertheme>
Mateus
  • 4,863
  • 4
  • 24
  • 32
  • When using the renderer - vector graphics that get rendered at runtime - then yes. This already works for maps I downloaded. But the online tiles - which are just bitmaps - are already as is. All I could do is scale the image tiles somehow. But not like you describe. Thanks anyway. – juergen d Jan 17 '17 at 20:02
1

I searched and found this link and this issue (Support resolution-dependent images in render-themes) about the unreadability problem in high resolution devices. It seem there are two concerns here:

Text rendering: How to make text (labels) larger?

Solution for this problem is to use TileRendererLayer.setTextScale(float textScale):

TileRendererLayer tileRendererLayer = new TileRendererLayer(...);
mapView.getLayerManager().getLayers().add(tileRendererLayer);
tileRendererLayer.setTextScale(...)

Symbols/Icons Rendering:

Ludwig Brinckmann says in second link:

There is quite a bit of support for this in the Rescue branch through the use of SVG images and tile scaling.

This is that branch but I think it's already merged to the project. So it seems for icons, you need to use SVG renderer which according to docs, scale automatically:

SVG Symbols

Symbols can be either defined in the raster PNG format or as vector graphics in SVG format.

...

SVG Scaling

SVG resources can now be automatically scaled to accommodate different device resolutions.

Community
  • 1
  • 1
Omid
  • 5,823
  • 4
  • 41
  • 50
  • When using the renderer - vector graphics that get rendered at runtime - then yes. This already works for maps I downloaded. But the online tiles - which are just bitmaps - are already as is. All I could do is scale the image tiles somehow. But not like you describe. Thanks anyway. – juergen d Jan 17 '17 at 20:01
0

I don't mean zooming in. I mean scaling the current zoom level to make it readable on high-resolution devices.

This is just not a distinction that exists in reality.

What you're describing is basically a texture, so I will use the word 'texture' instead of 'bitmap'.


At any zoom level, a set amount of screen pixels get mapped to a particular real world area in meters. This is your map scale or "zoom level" - the thing in the corner of any map. For example, 10 pixels = 1km.

Your image has an area which it represents, say a 1km square in London, and a size in pixels, say 40x40.

When the software tries to draw your texture to the screen it needs to map the pixels of your texture to screen pixels. In our example, our zoom level is 10 pixels = 1km, so a 1km square on screen is 10x10 pixels. Our texture also represents a 1km square but has more pixels (40x40).

Because these values are different, we need to somehow make our texture smaller. This is called texture filtering, and can also be done to make a texture larger.

The reason your texture looks bad on a high-resolution device is down to how the filtering is behaving. You may be able to achieve acceptable results if you use some kind of mipmap, reducing the level of detail as the user zooms out. This would be analogous to how Google maps removes labels as you get further out.


You will never be able to see a high level of detail from a high zoom level. That's why the answer saying "just zoom in!" are technically right.

If you simply increase the area the texture applies to without equally scaling (zooming) the map, your texture and underlying map will get out of sync and that's definitely not desirable.

Michael
  • 41,989
  • 11
  • 82
  • 128
  • The online tiles are a big image. And this image is fine from the details it has. But for instance the texts are so small that I can't read them on a phone. – juergen d May 17 '17 at 10:24
  • Yes, so use a mipmap which removes those details when they become unreadable. – Michael May 17 '17 at 10:26
  • Even if I zoom in max and only one street is in my view then I would like to see the street name. This is important info. But even then it would be unreadable small. – juergen d May 17 '17 at 10:27
  • Then your texture isn't high enough resolution. Get a higher resolution texture. – Michael May 17 '17 at 10:29
  • Oh. And where do I get it? – juergen d May 17 '17 at 10:29
0

Map view tile size is what defines the rendering, both in vector and raster maps.

We have examples with raster tile sources in Mapsforge samples app, e.g. DownloadLayerViewer. There a fixed tile size 256px is used, as that is provided by the tile source:

this.mapView.getModel().displayModel.setFixedTileSize(256);

If you remove that line, then the map view tile size will be auto-calculated based on device dpi (like in vector maps) and so the raster tiles would appear bigger (though a bit blurry).

Source: MapsForge Google Development Group

Removing this line made it work. Previously I tried setting the tile size to a different value, but never tried to remove the setting completely.

Community
  • 1
  • 1
juergen d
  • 201,996
  • 37
  • 293
  • 362
-4

JUST........ZOOM......... IN!!!!!!!!! Also, try setting this:

mapView.getModel().displayModel.setDefaultUserScaleFactor(2.0f);

to this:

mapView.getModel().displayModel.setDefaultUserScaleFactor(3.0f);
Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
The_CIA
  • 117
  • 8