Streetnames openstreetmaps more readable on Android

一个人想着一个人 提交于 2019-12-01 14:46:58

Osmdroid works with tiles that are static PNG images. You can not change the tile images. If you want to have a better mapping solution try MapsForge. This app/library works with maps data and renders them dynamically. This way you have more control on rendering maps and you can customize its texts and fonts and colors.

In this answer I will explain a little bit how I changed the size of the street names.

In the jar file of MapsForge there is a xml-file included that will standard be used for rendering the map data. You can download this file also by checking out the source code from the server: http://mapsforge.googlecode.com or download the xml-file itself from here: http://mapsforge.googlecode.com/svn/trunk/mapsforge-render-theme/src/main/resources/osmarender/osmarender.xml. So, you have a basic to tweak your own render file. I tweeked it a little bit like this:

(snippet of the xml-file):

On the Wiki-page of the MapsForgeRenderThemeAPI page (on the site above) you can find how to tweak your own render file and what e, k, v attributes in the rule element means. As you can see there is a rule element with e="way", k="area", v="~|no|false" inside the no-tunnel way rule-element somewhere under the way rule-element. Every rule-element under this element haves an e="way", k="highway" and v value equal to the openstreetmap parameters. As you login to the edit page on openstreetmap.org you can find out the kind of streets you want to tweak the names for.

Now I gonna tell how you can exactle the font-size you want for a specified type of street. As an example I will take the tertiary road element. Each kind of way rule-element contains some code like this:

<rule e="way" k="highway" v="tertiary">
    <line stroke="#ffff90" stroke-width="1.5" />
    <rule e="way" k="*" v="*" zoom-min="14">
        <pathText k="name" font-style="bold" font-size="32" stroke="#ffff90" stroke-width="2.0" />
    </rule>
</rule>

The line element specifies how the street will be displayed (color, width, black border, ...). There is again a rule-element inside here containing a pathText element. This element specifies how the text will be displayed inside the stroke(color, width, font-size, ...). So, this is the element we need! In my example, as you can see, the font-size for the street names for a tertiary road will be displayed with a size of 32 pixels for a zoom-in-level of 14 or higher.

Now we want to use our own render theme xml file:

I've added my own render-xml file in the assets folder of my project. Than a t launch time, I copy the file to a location from where I can read it out when it is needed. In the activity where you handle your mapsforge map you only have to link to this file by implementing code like this (example):

File f = new File(Environment.getExternalStorageDirectory(), myRenderTheme.xml);
mapView.setRenderTheme(f);

Note that setRenderTheme(File) will throw a FileNotFoundException.

So, this is all for changing the street names with mapsforge. You can render you're whole map as you want!

Thanks to the MapsForge development community.

Have fun!

Kr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!