Locus Map - forum

Content & Tools => Themes - Vector maps => Topic started by: TrulloF on April 28, 2023, 08:06:42

Title: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on April 28, 2023, 08:06:42
Are there any instructions how to convert version 3 themes to be compatible with the new map format? Thanks for any hints. Even after stripping all version 3 specific tags I can't get my theme to work.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: Tapio on April 28, 2023, 09:20:39
Did you already find https://github.com/mapsforge/mapsforge/blob/master/docs/Rendertheme.md
?

Fight, compare, create valid xml
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on April 28, 2023, 16:05:59
Quote from: Tapio on April 28, 2023, 09:20:39Did you already find https://github.com/mapsforge/mapsforge/blob/master/docs/Rendertheme.md
?

Fight, compare, create valid xml
Yes, but I can't find, what's wrong with it. I only get a white map with standard icons...
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: john_percy on April 29, 2023, 16:11:39
@TrulloF Have you tried running your theme through an XML checker? A white map may indicate unmatched tags.


Sent from my moto g(6) plus using Tapatalk
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on April 29, 2023, 21:24:49
Quote from: john_percy on April 29, 2023, 16:11:39@TrulloF Have you tried running your theme through an XML checker? A white map may indicate unmatched tags.


Sent from my moto g(6) plus using Tapatalk

Yes, I use UltraEdit. Are there any incompatible tags I may have missed? I removed Locus specific v3 stuff like scale-icon-size or bg-rect-*. Anything else to look for? I'm desperate because I like my personal theme quite much and would like to continue using it.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: john_percy on April 29, 2023, 22:04:56
Have you also changed the rendertheme tag near the start of the theme?
Something like
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://mapsforge.org/renderTheme" xsi:schemaLocation="http://mapsforge.org/renderTheme https://raw.githubusercontent.com/mapsforge/mapsforge/master/resources/renderTheme.xsd" version="5" map-background="#F8F8F8" map-background-outside="#EEEEEE">
(This doesn't work in Tapatalk - use Webview.)
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on April 29, 2023, 22:26:05
Quote from: john_percy on April 29, 2023, 22:04:56Have you also changed the rendertheme tag near the start of the theme?
Something like
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://mapsforge.org/renderTheme" xsi:schemaLocation="http://mapsforge.org/renderTheme https://raw.githubusercontent.com/mapsforge/mapsforge/master/resources/renderTheme.xsd" version="5" map-background="#F8F8F8" map-background-outside="#EEEEEE">
(This doesn't work in Tapatalk - use Webview.)

Copied that directly from the internal v4 Locus theme. Is there a how-to or faq available anywhere? If I use the version edited for v4 in v3 maps it works as intended.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: Menion on April 30, 2023, 00:02:54
Maybe a @voldapet may help with some tips on how he did it for the app's internal themes ...
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: john_percy on April 30, 2023, 09:23:07
Quote from: TrulloF on April 29, 2023, 22:26:05If I use the version edited for v4 in v3 maps it works as intended.
That shouldn't happen. The rendertheme preamble should mean that your v4 theme doesn't show up in the list of themes for v3 maps and vice versa.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on April 30, 2023, 10:46:44
Quote from: john_percy on April 30, 2023, 09:23:07
Quote from: TrulloF on April 29, 2023, 22:26:05If I use the version edited for v4 in v3 maps it works as intended.
That shouldn't happen. The rendertheme preamble should mean that your v4 theme doesn't show up in the list of themes for v3 maps and vice versa.
Sorry for the misleading description. I changed the version in the header to let it show up for v3 maps, just to check if the theme is broken. It's not, at least for v3. In v4 it shows just a white screen and standard poi icons.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: john_percy on April 30, 2023, 18:34:57
You didn't mention removing all mention of "dp"...

Sent from my moto g(6) plus using Tapatalk

Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on April 30, 2023, 21:21:54
Quote from: john_percy on April 30, 2023, 18:34:57You didn't mention removing all mention of "dp"...

Sent from my moto g(6) plus using Tapatalk


Ok, thank you for the hint. That might be it.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on April 30, 2023, 21:56:06
Quote from: john_percy on April 30, 2023, 18:34:57You didn't mention removing all mention of "dp"...

Sent from my moto g(6) plus using Tapatalk


Removed all dp instances, but still no luck... Anything else to try?
The locus theme checker doesn't throw any error.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on April 30, 2023, 22:00:53
Is a style menu mandatory (cat and stuff)? I don't use these in my theme.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: john_percy on April 30, 2023, 22:14:37
No
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: john_percy on May 01, 2023, 00:54:05
My usual mistake that results in a white map is losing a " mark in editing. Values have to be enclosed in a pair of quote marks with no forgiveness available! But I doubt that this is the problem in your case as your theme works as a v3 theme.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on May 01, 2023, 07:57:33
Quote from: john_percy on May 01, 2023, 00:54:05My usual mistake that results in a white map is losing a " mark in editing. Values have to be enclosed in a pair of quote marks with no forgiveness available! But I doubt that this is the problem in your case as your theme works as a v3 theme.
Thank you for your input. I'll double check that too, but usually xml validation finds these typos. I'm quite puzzled...
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: Menion on May 01, 2023, 08:33:27
You may also share a theme-in-progress with me, I'll check if the app throws any errors in the background if you want.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on May 01, 2023, 15:21:01
Quote from: Menion on May 01, 2023, 08:33:27You may also share a theme-in-progress with me, I'll check if the app throws any errors in the background if you want.
Here you can find the theme. Adlerauge_v4.xml is the theme in question. Thank you in advance. https://1drv.ms/u/s!Av_dQw47TbThg7Z4aMWVjiWQkJdOIw?e=bkwbt3
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: voldapet on May 01, 2023, 19:19:26
@TrulloF
as mentioned above LoMaps V4 uses official Mapsforge renderer and it's needed to remove all tags that are not supported by Mapsforge.

I downloaded your theme and fixed some small issues like 'priority' in rule tag, 'repeat' can not be used for symbol, 'color' for symbol and 'country' attribute used for subways. I commented the subways section so please replace it with the symbol you want to use for subways
(the "fixed" theme in the attachment)
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on May 01, 2023, 19:26:18
Quote from: voldapet on May 01, 2023, 19:19:26@TrulloF
as mentioned above LoMaps V4 uses official Mapsforge renderer and it's needed to remove all tags that are not supported by Mapsforge.

I downloaded your theme and fixed some small issues like 'priority' in rule tag, 'repeat' can not be used for symbol, 'color' for symbol and 'country' attribute used for subways. I commented the subways section so please replace it with the symbol you want to use for subways
(the "fixed" theme in the attachment)
Thank you so much! It works and now I just need to adjust some stuff. You are my hero! Thank you for your efforts.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on May 02, 2023, 07:46:07
Is there a formula to "translate" dp values to new numerics?
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: voldapet on May 02, 2023, 08:38:03
It seems I used several formulas based on the type of attribute. Is it possible for you to understand the following python code? (if not I can translate to the "human language" :)
I think I adjusted some values manually afterward anyway.

Code (python) Select
def process_dp_unit(soup):
    """"
    Remove the 'dp' units and re-compute the offset to pixels
    :param soup:
    """
    # simple remove dp for following without any computation
    attr_to_remove_dp = ['stroke-width', 'repeat-gap', 'r']
    for attr in attr_to_remove_dp:
        for tag in soup.select('[{}]'.format(attr)):
            value = tag[attr].replace('dp', '')
            tag[attr] = value

    # remove dp and round to int because symbol-with
    for tag in soup.select('[symbol-width]'):
        value_float = float(tag['symbol-width'].replace('dp', ''))
        tag['symbol-width'] = round(value_float * 1.5)
        #tag['symbol-width'] = 20

    # remove dp and resize dp at path-text
    for tag in soup.select('[font-size]'):
        value_float = float(tag['font-size'].replace('dp', ''))
        tag['font-size'] = round(1.4 * value_float)


def process_dy(soup):
    """"
    Remove the 'dp' units and re-compute the offset to pixels for dy attribute
    :param soup:
    """
    for tag in soup.select('[dy]'):
        value = tag['dy']
        if tag.name == 'line' or tag.name == 'pathText' or tag.name == 'lineSymbol':
            if 'dp' in value:
                value = float(value.replace('dp', ''))
                value = value / 4.3  #
                tag['dy'] = round(value, 1)

        if tag.name == 'caption':
            tag['dy'] = value.replace('dp', '')

        if tag.name == 'symbol':
            del tag['dy']
            tag['position'] = "above"
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on May 02, 2023, 19:56:00
Quote from: voldapet on May 02, 2023, 08:38:03It seems I used several formulas based on the type of attribute. Is it possible for you to understand the following python code? (if not I can translate to the "human language" :)
I think I adjusted some values manually afterward anyway.

Code (python) Select
def process_dp_unit(soup):
    """"
    Remove the 'dp' units and re-compute the offset to pixels
    :param soup:
    """
    # simple remove dp for following without any computation
    attr_to_remove_dp = ['stroke-width', 'repeat-gap', 'r']
    for attr in attr_to_remove_dp:
        for tag in soup.select('[{}]'.format(attr)):
            value = tag[attr].replace('dp', '')
            tag[attr] = value

    # remove dp and round to int because symbol-with
    for tag in soup.select('[symbol-width]'):
        value_float = float(tag['symbol-width'].replace('dp', ''))
        tag['symbol-width'] = round(value_float * 1.5)
        #tag['symbol-width'] = 20

    # remove dp and resize dp at path-text
    for tag in soup.select('[font-size]'):
        value_float = float(tag['font-size'].replace('dp', ''))
        tag['font-size'] = round(1.4 * value_float)


def process_dy(soup):
    """"
    Remove the 'dp' units and re-compute the offset to pixels for dy attribute
    :param soup:
    """
    for tag in soup.select('[dy]'):
        value = tag['dy']
        if tag.name == 'line' or tag.name == 'pathText' or tag.name == 'lineSymbol':
            if 'dp' in value:
                value = float(value.replace('dp', ''))
                value = value / 4.3  #
                tag['dy'] = round(value, 1)

        if tag.name == 'caption':
            tag['dy'] = value.replace('dp', '')

        if tag.name == 'symbol':
            del tag['dy']
            tag['position'] = "above"

I'll have a look at it. Thanks. Seems to be a lot of effort anyway  :)
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: voldapet on May 02, 2023, 21:23:37
Well, I could provide the whole python script that was used for conversion from V3 to V4... if you are familiar with python.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on May 02, 2023, 21:50:41
Quote from: voldapet on May 02, 2023, 21:23:37Well, I could provide the whole python script that was used for conversion from V3 to V4... if you are familiar with python.
That would be great! Thank you in advance for sharing.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: john_percy on May 02, 2023, 22:16:14
@voldapet
In your theme, captions have both dy and position set. Is that intentional?
I thought position needed an id to be set to link the caption with the symbol (which also has an id set) it has to be above or below. Is that not so? Certainly if I remove the dy then position on its own doesn't seem to do anything useful.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: voldapet on May 03, 2023, 08:46:28
@john_percy Honestly, the position for captions remains in the theme very likely from my testing of this attribute. As I recall, "position" without an ID has minimal effect. It basically changes the defining point for the text box (the minimum rectangle around the text).
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: voldapet on May 08, 2023, 21:30:09
@TrulloF
We published the python script that can help with the conversion theme from "Custom Locus V3" style to official Mapsforge V4
https://github.com/asamm/lomaps-mapsforge/tree/main/theme-v3-to-v4-converter
The conversion is not 1:1 but it can help to remove not supported attributes or convert DP units to "pixels" in V4
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on May 09, 2023, 19:24:27
Quote from: voldapet on May 08, 2023, 21:30:09@TrulloF
We published the python script that can help with the conversion theme from "Custom Locus V3" style to official Mapsforge V4
https://github.com/asamm/lomaps-mapsforge/tree/main/theme-v3-to-v4-converter
The conversion is not 1:1 but it can help to remove not supported attributes or convert DP units to "pixels" in V4
Did most of it by hand in the meantime  :), but thanks for sharing.
Title: Re: How to convert v3 Locus themes to new v4 format
Post by: TrulloF on May 09, 2023, 23:16:43
Quote from: voldapet on May 08, 2023, 21:30:09@TrulloF
We published the python script that can help with the conversion theme from "Custom Locus V3" style to official Mapsforge V4
https://github.com/asamm/lomaps-mapsforge/tree/main/theme-v3-to-v4-converter
The conversion is not 1:1 but it can help to remove not supported attributes or convert DP units to "pixels" in V4
Needed to install some additional modules (e.g. lxml), but then conversion worked without a problem. There are several typos in the readme, but it wasn't to hard to figure them out  ;).