简体   繁体   中英

Java: Scale Mapsforge Map when using online bitmap tiles instead of offline renderer

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.

截屏

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!

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.

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>

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.

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.

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, eg 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.

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

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

to this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM