Streetnames openstreetmaps more readable on Android

后端 未结 2 1808
傲寒
傲寒 2021-01-17 03:21

I\'ve build an Android APP with offline map data using Openstreetmaps and OsmDroid. On a device with MDPI 320x480 pixels the map looks OK, but on a device with a HDPI screen

2条回答
  •  悲哀的现实
    2021-01-17 03:40

    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):

    enter image description here

    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:

    
        
        
            
        
    
    

    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

提交回复
热议问题