Locus Map - forum

Content & Tools => Themes - Vector maps => Topic started by: Tobias on May 05, 2016, 21:12:07

Title: Problems with seemless SVG patterns
Post by: Tobias on May 05, 2016, 21:12:07
As I try to make my themes completely scalable I converted all patterns to SVG.
I only use sizes like 8/16/32/64/128, those scale well with standard mapsforge at every ppi, as standard uses multiples of 64 for scaling. For Locus I add the "dp" unit.

Most of the patterns are seemless and work well with Locus at 160/320ppi. But with odd multiplicators like 240/480ppi they don't work anymore, see attached screenshots of 240/320ppi.

Same problem applies to Locus internal seems, when SVG patterns are used.

How exactly does "dp" work, and is there a possibility to have seemless SVG patterns that scale with screen density?
(http://s32.postimg.org/6tdaznjb5/svg_patterns_240.jpg) (http://postimg.org/image/6tdaznjb5/) (http://s32.postimg.org/6iitjlls1/svg_patterns_320.jpg) (http://postimg.org/image/6iitjlls1/)

Edit - theme for testing is here: http://www.openandromaps.org/wp-content/users/tobias/Elevate4_Locus.zip
Title: Re: Problems with seemless SVG patterns
Post by: SwissPoPo on May 07, 2016, 10:12:18
I assume use Locus the same fixed tile size of 512 as mapsforge (I'm not sure if it is 512). Use this formula to see whether it fits an integer in the tile.  <tilesize>/(<Patternsize>*<AndroidSacleFactor>)
With your pattern sizes you only get integers with Scale Factors 1, 2, 4 (160/320/640dpi), not with 0.75, 1.5, 3 (120/240/480dpi). You already know this thread: https://groups.google.com/d/msg/mapsforge-dev/s7OcnFseBTI/CchcWloQjNIJ
Mapsforge does adjust the pattern size to fit in the tile size. It seems Locus has not implemented this feature.
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 08, 2016, 09:10:02
I think Locus uses a tile size of 256 for all densities.
If you're right about your theory how scaling works there is no possibility to have one SVG size that fits all scale factors, if background SVGs are scaled with odd factors. It would really make sense to use only full integers here.

I tried my luck with fixed sizes so that at least this would be a workaround. There also seems no difference between adding "dp" or not to the value, the SVG is scaled either way. So there seems no possibility to use  SVGs for background patterns. Edit: There is one possibility, just add "px" instead of "dp". Normally in mapsforge no unit means px, so I didn't try this before.

Maybe I'm missing something here, but the documentation (http://docs.locusmap.eu/doku.php?id=manual:advanced:map_tools:theming) is a bit scarce about this.
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 08, 2016, 11:26:37
Hello Tobias,

after loong fight (4 devices, 3 emu), I finally found one emulator with this DPI (change of DPI over ADB were not working correctly). So let's do something with this.

Test sample:
line 617: <area symbol-width="64dp" src="file:../ele_res/p_wood-mixed.svg" />

my device with DPI multiplier 2.5, so Locus correctly generates images with 64x2.5 = 160px. They do fit to 256 even a 512 px tiles (size do not matter here).

So, you suggestion is to round this multiplier to whole numbers that multiply 2 to always correctly fit tiles? So 2.5 round to "2", 3.5 round to "2" (maybe up to 4)? Correct? Or any better solution already used in MapsForge?
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 08, 2016, 16:53:50
Hi Menion,
thanks for testing!

Quote from: menion on May 08, 2016, 11:26:37
So, you suggestion is to round this multiplier to whole numbers that multiply 2 to always correctly fit tiles? So 2.5 round to "2", 3.5 round to "2" (maybe up to 4)? Correct?
That's the easiest solution, but only fits pattern with a side length of a power of 2.

QuoteOr any better solution already used in MapsForge?
I checked this out bit more. At first I thought it works there because tiles are resized by dpi the same way as patterns (e.g. 512px tiles at 320dpi, so 64px patterns get 128px, 768px tiles at 480dpi, 64px get 192px etc.)
But with apps like OruxMaps which use a fixed tile size of 512px no matter what dpi scaling still works perfect, even if pattern side length is not a power of 2, so this is more elegant. The solution is that patterns are scaled without stopping at tile borders, see the attached screenshot with a tile size of 512px and 480 dpi, and a pattern of 64px scaled to 192px. White are pattern borders, black are tile borders.

(http://s32.postimg.org/m94ah76dd/Orux_480.jpg) (http://postimg.org/image/m94ah76dd/)

Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 09, 2016, 10:01:42
Good day Tobias,

thanks for a precise description and tests. I investigate how this is done in new MapsForge library and I have to say, very nice idea and system how it's made. Unfortunately it required quite a lot of work in current library (or let's say Version 3 of old MapsForge). I'm currently thinking if it's better to invest time to improving old modified library or do and commit some optimization changes to new version. Both has it's +/-.

For now, I've at least improved DPI scaling, so now values of density used for scaling will be rounded on all devices to 1, 2, 4 values, so if you will use sizes for your images as 8, 16, 32, 64, you will be fine. Unfortunately my device I use for daily use has density that cause no such troubles, but quick test in emulator and it seems to work fine. Ok for now?

Alternative should be to use new system of mapsForge V4 maps + V4 themes, but seems that difference in speed is still quite huge.
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 09, 2016, 12:07:46
Quote from: menion on May 09, 2016, 10:01:42
For now, I've at least improved DPI scaling, so now values of density used for scaling will be rounded on all devices to 1, 2, 4 values, so if you will use sizes for your images as 8, 16, 32, 64, you will be fine. Unfortunately my device I use for daily use has density that cause no such troubles, but quick test in emulator and it seems to work fine. Ok for now?

That's fine, thanks for the quick fix. I'm fine with any working solution.

I forget to mention that this should also apply to lines with a pattern, not just areas.

Rounding up or down makes sense for me (e.g. 3->4, 2.5->2) etc., as this helps to read the maps. With those crazy high density devices it's often better to have it larger (my testing device is also not troubled at 320dpi, so I also have to emulate this).
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 09, 2016, 12:23:03
You are welcome.

To keep consistency, this change apply on all values defined with "dp" units in theme.xml file, so no worry.
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 09, 2016, 17:49:39
Quote from: menion on May 09, 2016, 12:23:03
To keep consistency, this change apply on all values defined with "dp" units in theme.xml file, so no worry.
So this applies to stroke-width, symbol-size etc. as well?
If yes I think it's better to keep them scaling in the normal way, which works perfect except for patterns with svg/dp.
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 09, 2016, 18:41:54
Hello Tobias, you know best how it should look like. If you want, I may generate a version for you for test. Otherwise probably in Thrisday should be published new version. Because there will be quite a lot of changes, I expected that in two/three days, I'll publish some bugfix version, so there will be at least these two days to test it and fix it if needed. I do not want to do it now, because this task is not so simple (handle differently scale for areas and for paths) and I believe it should not be needed, Thanks
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 09, 2016, 20:43:21
Quote from: menion on May 09, 2016, 18:41:54
because this task is not so simple (handle differently scale for areas and for paths)
I was afraid you would say that :-)
No need for hurry and/or special test version, I'll use fixed size patterns until it works with scalable ones.
But I think other themes (and users) will be affected if not only scaling for patterns will change. We'll see.
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 12, 2016, 09:51:15
If you wanna try, since yesterday is on Google Play new Beta version ( if you use it ). Official version will have smaller delay ( Monday probably ).
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 13, 2016, 09:49:04
Thanks, I'll look into it as soon as I find the time.
Title: Re: Problems with seemless SVG patterns
Post by: LocusUser#1 on May 13, 2016, 10:29:30
I understand this correctly that I must now do for my 240 DPI device all symbols by a factor of 1.5 greater?
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 13, 2016, 10:35:40
Nono, all symbols that serve as patterns, should just keep it's sizes as 8, 16, 32, 64 dp values, then you will be fine on all densities.
Title: Re: Problems with seemless SVG patterns
Post by: LocusUser#1 on May 13, 2016, 12:47:10
Hmm, for me all Symbols and Texts are smaller.  :P

Left is 3.16.2, Right is 3.16.2.12
(http://s32.postimg.org/63y6rbxxd/Screenshot_20160513_122823.jpg) (http://postimg.org/image/63y6rbxxd/)
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 13, 2016, 13:05:27
Damn, it's more then expected. Hmm ... oki, I'll have to separate it and round scaling only for images for areas ...
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 13, 2016, 13:07:48
Quote from: LocusUser#1 on May 13, 2016, 12:47:10
Hmm, for me all Symbols and Texts are smaller. 

Left is 3.16.2, Right is 3.16.2.12
(http://s32.postimg.org/63y6rbxxd/Screenshot_20160513_122823.jpg) (http://postimg.org/image/63y6rbxxd/)
You probably have a device with an odd scale factor, something like 480 dpi. Those are affected and that's what we talked about above when rounding to integers with a power of 2 can happen if this isn't limited to svg patterns.
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 13, 2016, 13:09:58
Quote from: menion on May 13, 2016, 13:05:27
Damn, it's more then expected. Hmm ... oki, I'll have to separate it and round scaling only for images for areas ...
And lines with images :)
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 14, 2016, 20:55:12
Quote from: menion on May 12, 2016, 09:51:15
If you wanna try, since yesterday is on Google Play new Beta version ( if you use it ).
Finally found the time to test the latest beta it in an emulator @480dpi. Still same behavior as above, all patterns 8dp/16dp/32dp/64dp. Did you remove the rounding again?

(http://s32.postimg.org/ti0u3ocq9/svg_patterns_beta.jpg) (http://postimg.org/image/ti0u3ocq9/)
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 15, 2016, 06:09:01
Hello, interesting. Are you sure you have latest Beta version from Google Play?

Before & After
(http://s32.postimg.org/7gh6y11pt/s01.jpg) (http://postimg.org/image/7gh6y11pt/)(http://s32.postimg.org/ze6097qwh/s02.jpg) (http://postimg.org/image/ze6097qwh/)

Before & After
(http://s32.postimg.org/466m3dfxt/s03.jpg) (http://postimg.org/image/466m3dfxt/)(http://s32.postimg.org/tmo9l1alt/s04.jpg) (http://postimg.org/image/tmo9l1alt/)
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 15, 2016, 08:30:02
Quote from: menion on May 15, 2016, 06:09:01
Hello, interesting. Are you sure you have latest Beta version from Google Play?
It says 3.16.2.12 at startup. Just checked again, it works now with 240dpi, but not with 480dpi.
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 15, 2016, 08:40:43
Ah ... give me please a suggestion how you simulate device with this DPI, thanks
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 15, 2016, 08:47:56
Quote from: menion on May 15, 2016, 08:40:43
Ah ... give me please a suggestion how you simulate device with this DPI, thanks
With Genymotion, there's a preset for 1920*1280@480dpi
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 15, 2016, 09:52:09
Thank you @Tobias, issue found and fixed. Also scaling is now rounded for areas and line symbols only.
Title: Re: Problems with seemless SVG patterns
Post by: Tobias on May 17, 2016, 21:50:13
Tested with 3.17 release in emulator @240dpi and @320dpi, seems to work perfect!
Title: Re: Problems with seemless SVG patterns
Post by: Menion on May 17, 2016, 22:23:12
Uff thanks for confirmation

Sent from my SM-G930F using Tapatalk