[VTM] Add / Remove theme rules on live

179 views
Skip to first unread message

Mathieu De Brito

unread,
Nov 7, 2016, 11:26:31 AM11/7/16
to mapsforge-dev
Hi guys,

Is that possible to add / remove theme rules on live like (showing/hiding some pois, etc) ?
The ThemeStylerActivity sample does not explain this.

Thank you !

Mathieu De Brito

unread,
Nov 7, 2016, 11:38:29 AM11/7/16
to mapsforge-dev
Or maybe enable / disable the theme rules ?

Emux

unread,
Nov 7, 2016, 12:04:28 PM11/7/16
to mapsfo...@googlegroups.com
Yes it's perfectly possible.

I have integrated the Render Theme Styles feature, like we have it already in Mapsforge.

It allows you to selectively turn theme rules on and off.
Details for it can be found in original Mapsforge render theme documentation, we follow the exact same syntax.

Unfortunately I have not added an example in Samples yet, still Mapsforge Samples can be a guide.

--
Emux

Emux

unread,
Nov 8, 2016, 5:30:39 AM11/8/16
to mapsfo...@googlegroups.com
Check again issue #93, I added a simple render theme styles sample.

--
Emux

Mathieu De Brito

unread,
Nov 8, 2016, 9:43:43 AM11/8/16
to mapsforge-dev
Thank you very much Emux !

I was also working on a pull request to add a sample.
Maybe I should still add the sample since I'm working on the vtm-android-example and not on the GDX example, what do you think ?

Also, I did not use your sample since -to be very honest- I did not really understand it. 
I think we did not have the same use case : I just wanted to show/hide some category without managing the whole list of elements displayed.

Here is my use sample : 
<rendertheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" base-text-scale="1.25"
     map-background="#fffcfa" version="1" xmlns="http://opensciencemap.org/rendertheme"
     xsi:schemaLocation="http://opensciencemap.org/rendertheme https://raw.githubusercontent.com/mapsforge/vtm/master/resources/rendertheme.xsd">
     
     <stylemenu defaultlang="fr" defaultvalue="1" id="menu">
<layer id="custom_layer">
            <cat id="sea" />
</layer>
</stylemenu>

     <!-- Always displayed -->
     <m cat="sea" e="way" k="natural" v="issea|sea">
         <area fill="#0000ff" mesh="true" />
     </m>
 
<!-- Display on user request --> <m cat="land" e="way" k="natural" v="nosea"> <area fill="#00ff00" mesh="true" /> </m> </rendertheme>

boolean displayLand = false;

setTheme(new StreamRenderTheme("", getClass().getResourceAsStream("/assets/styles/categories.xml"), new XmlRenderThemeMenuCallback() {
@Override
public Set<String> getCategories(XmlRenderThemeStyleMenu style) {

String id = "custom_layer";

XmlRenderThemeStyleLayer baseLayer = style.getLayer(id);
if (baseLayer == null) {
Log.w("Custom", "Invalid style " + id);
return null;
}
Set<String> result = new HashSet<>();

// add the categories from overlays that are enabled
for (String category : baseLayer.getCategories()) {

if (category.equals("land")) {
if (displayLand) {
result.add(category);
}
} else {
                result.add(category);
}
}

return result;
}
}));

Mathieu De Brito

unread,
Nov 8, 2016, 9:50:10 AM11/8/16
to mapsforge-dev
oups, 

it's of course cat id="land" and not "sea":
 <stylemenu defaultlang="fr" defaultvalue="1" id="menu">
<layer id="custom_layer">
            <cat id="land" />
</layer>
</stylemenu>

On Monday, November 7, 2016 at 5:26:31 PM UTC+1, Mathieu De Brito wrote:

Emux

unread,
Nov 8, 2016, 9:57:21 AM11/8/16
to mapsfo...@googlegroups.com
Desktop example tries to be simple with just 2 rules, one permanent (sea) and one under user control (land), via keys 1 or 2.

The menu in style.xml may appear a bit complex since it covers most cases, like inheritance, permanent categories, selectable overlays, etc.

You should really study the documentation (mentioned in issue) and try on device the Mapsforge Samples app, which has a complete implementation to see it in action.

Your code uses some fixed strings in the callback, good to be avoided - for an example at least, which needs to be generic.

It's better to discuss what specific parts from documentation or samples you don't understand first.

BTW any pull request is welcome! :)

--
Emux

Mathieu De Brito

unread,
Nov 8, 2016, 10:20:15 AM11/8/16
to mapsforge-dev
Sure, I agree with you that the sample I sent you (which I quickly made on the fly for the reply) would need some work before pushing and the fact that a sample needs to be complete.

I read the documentation many times (since it's a few lines) and did not understand the overlay keyword since it's not mentioned.
So in your sample, I don't understand why there are 2 layers for each "land" and "sea" :p
I understand that the sea is the permanent why but don't see how and why land could be hidden since it's still an overlay in the style.
And as I just wanted to show/hide one category without mentioning others (permanent), I got to do my own sample.

Maybe a few lines of comments could complete your sample (I may not be the only one not understanding it even with having read the doc) ?

Thank you again so much for your answers and your time, it's really appreciated

Emux

unread,
Nov 8, 2016, 12:38:06 PM11/8/16
to mapsfo...@googlegroups.com
A useful help would be also the theme schema which describes all declarations and their connections.

On top there is 'stylemenu' with its a default language and selected style ('defaultvalue').
It can contain many layers.

A 'layer' can have another layer as parent, inheriting its elements.
The 'visible' declares its appearance in the UI (which is implemented by the user).
The 'enabled' declares if the layer is selected and its categories are rendered on map, like checked in example.

A 'layer' can have also many categories ('cat') and many 'overlay'.
The difference between them is that a 'cat' is relevant directly to a 'cat' declared in subsequent theme rules.
An 'overlay' is used in 'visible' UI layers to host another previously declared 'layer'. In that case the enabled state is determined by that layer, not the host and can be shown in UI.

I understand that the whole concept seems a bit complex, but it evolved after many iterations in Mapsforge to become the powerful tool being today.
Best advice is to practice with simple menu like in VTM and study advanced ones like in Mapsforge.

In VTM example the first two layers with ids "sea" and "land", describe only the sea and land and are not visible to possible UI.
Layers with ids "1" and "2" are the visible layers and can contain many other 'cat' and 'overlay'.
Again see Mapsforge menu example for that.

--
Emux

Mathieu De Brito

unread,
Nov 9, 2016, 4:38:15 AM11/9/16
to mapsfo...@googlegroups.com
Wow, thank you again so much for your quick and complete answer. I know the time it takes to answer people, so it's really appreciated !

The schema, the stylemenu and inheritance are well understood since they are common patterns but even after your explanations, I still don't get the overlay feature oO
I already have the vtm and mapsforge projects up and running, but to be honest, it does not help understanding the overlay feature :p (nor reading the doc or running the sample thought I tried hard to understand it)

Be sure that I don't want to remove or change the mapsforge theming features since I trust the mapsforge libs history and power.

As you said, it might take time and some more MapsForge experience to integrate the concept, so I will let the time do its job. That being said, I still think some more explanations / comments about the overlay concept might also be appreciated by other users ;)

Anyway, I got a working POC of what I needs, so all is good for me !
Thank you again :)

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/BKyNNw21sZ0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-dev+unsubscribe@googlegroups.com.
To post to this group, send email to mapsfo...@googlegroups.com.
Visit this group at https://groups.google.com/group/mapsforge-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/61a907ab-3cc2-15ea-48cc-65ce369c1d5d%40gmail.com.

For more options, visit https://groups.google.com/d/optout.

Emux

unread,
Nov 9, 2016, 4:59:36 AM11/9/16
to mapsfo...@googlegroups.com
I updated a little the documentation regarding overlays.

Also I pushed a simpler VTM example with more docs.
Sea and land stand still, while nature layer is toggled on/off.

If you check Mapsforge sample you'll see that running the 1st example and in preferences:
- With a combo box you can select one of the 3 available (visible) styles (aka layer groups)
- And with each selection a list of check boxes appears to turn on/off layers
These are exactly the overlays of each layer group in style xml.

Which we override their state with preferences in that case.
i.e. compare the 2 callbacks: Mapsforge preferences code with VTM default code.

--
Emux
Reply all
Reply to author
Forward
0 new messages