Get Stylemenu from external render theme file

182 views
Skip to first unread message

Erich Melinz

unread,
Feb 14, 2021, 3:59:35 AM2/14/21
to Mapsforge & VTM
I want to display the stylemenu of an external render theme file in my app's option menu.
Why is the following callback-approach not working? How does the solution look like?
Thank you!

File xmlRenderThemeFile = new File(…path to external render theme file filename.xml);
XmlRenderTheme xmlRenderTheme = new ExternalRenderTheme(xmlRenderThemeFile);
xmlRenderTheme.setMenuCallback(new XmlRenderThemeMenuCallback() {
@Override
public Set<String> getCategories(XmlRenderThemeStyleMenu style) {
Log.d(„T“, „Test – style.getLayers()“ + style.getLayers());
return null;
}
});

Emux

unread,
Feb 14, 2021, 4:17:52 AM2/14/21
to mapsfo...@googlegroups.com
See the StyleMenuMapViewer + Settings and run the mapsforge-samples-android where this feature is demonstrated.

You can also check the MapsforgeStyleActivity for a similar implementation.

--
Emux

Erich Melinz

unread,
Feb 15, 2021, 3:59:57 PM2/15/21
to Mapsforge & VTM
Thank you for your fast response. I have tried almost everything, but I don't get it working.

I am currently struggling with two main questions:

1.) What is the latest package version? In the example StyleMenuMapViewer + Settings org.mapsforge.map.rendertheme.XmlRenderThemeMenuCallback is imported, whereas MapsforgeStyleActivity imports org.oscim.theme.XmlRenderThemeMenuCallback. I have implemented 'org.osmdroid:osmdroid-mapsforge:6.1.8'.

2.) What is the minimum amount of required classes and interfaces to get the method public Set<String> getCategories(XmlRenderThemeStyleMenu style) running? In the example StyleMenuMapViewer + Settings the class "StyleMenuMapViewer" is extended by "SamplesBaseActivity", which is again extended by "MapViewerTemplate".

In my current application I can generate a new external render theme object by calling  new ExternalRenderTheme(File-object of external render theme file).
The following callback-approch is not working. What am I missing? Or do I have to create a new AssetsRenderTheme-object? How does the solution look like?

xmlRenderTheme = new ExternalRenderTheme(themeFile, new XmlRenderThemeMenuCallback() {

@Override
public Set<String> getCategories(XmlRenderThemeStyleMenu style) {
Log.d(„T“, „Test – style.getLayers()“ + style.getLayers());
return null;
}
});

Thank you.

Emux

unread,
Feb 16, 2021, 2:36:24 AM2/16/21
to mapsfo...@googlegroups.com
The samples work, so you need to compare / debug your implementation vs the sample code.

All themes support style menus, first load the theme and then process its style menu.

The 2nd example is from VTM OpenGL map library (compatible with Mapsforge).
It has a simpler style menu example, so you can study that too.
The package may be different, but the functionality is the same.

--
Emux

Erich Melinz

unread,
Feb 27, 2021, 4:50:27 PM2/27/21
to Mapsforge & VTM
Thank you for your main hint that I have to first load the theme and then to precess to style menu.

After uncountable hours of debugging I got the solution:

themesDir = new File(getExternalFilesDir(null), "Elevate");
themeFile = new File(themesDir, THEME_ELEVATE_FILE);
try {

xmlRenderTheme = new ExternalRenderTheme(themeFile, new XmlRenderThemeMenuCallback() {
@Override
public Set<String> getCategories(XmlRenderThemeStyleMenu style) {
renderThemeStyleId = sharedPreferences.getString(style.getId(),
style.getDefaultValue());

XmlRenderThemeStyleLayer baseLayer = style.getLayer(renderThemeStyleId);
if (baseLayer == null) {
Log.w("L", "Invalid style " + renderThemeStyleId);
return null;
}
Set<String> result = baseLayer.getCategories();

// add the categories from overlays that are enabled
for (XmlRenderThemeStyleLayer overlay : baseLayer.getOverlays()) {
if (sharedPreferences.getBoolean(overlay.getId(), overlay.isEnabled())) {
result.addAll(overlay.getCategories());
}
}

return result;
}
});
RenderThemeHandler.getRenderTheme(AndroidGraphicFactory.INSTANCE, new DisplayModel(), xmlRenderTheme);
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return;
Reply all
Reply to author
Forward
0 new messages