How to convert v3 Locus themes to new v4 format

Started by TrulloF, April 28, 2023, 08:06:42

0 Members and 2 Guests are viewing this topic.

john_percy

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.
Voluntary and Velocity themes - https://voluntary.nichesite.org
  •  

TrulloF

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...
  •  

Menion

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.
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  
    The following users thanked this post: john_percy

TrulloF

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
  •  

voldapet

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

TrulloF

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.
  •  

TrulloF

Is there a formula to "translate" dp values to new numerics?
  •  

voldapet

#22
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"
  •  

TrulloF

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

voldapet

Well, I could provide the whole python script that was used for conversion from V3 to V4... if you are familiar with python.
  •  

TrulloF

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.
  •  

john_percy

@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.
Voluntary and Velocity themes - https://voluntary.nichesite.org
  •  

voldapet

#27
@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).
  •  
    The following users thanked this post: john_percy

voldapet

@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
  •  
    The following users thanked this post: TrulloF

TrulloF

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.
  •