Search in sources :

Example 1 with LanguagePreference

use of net.osmand.core.jni.MapPresentationEnvironment.LanguagePreference in project Osmand by osmandapp.

the class MapRendererContext method updateMapPresentationEnvironment.

/**
 * Update map presentation environment and everything that depends on it
 */
private void updateMapPresentationEnvironment() {
    // Create new map presentation environment
    String langId = app.getSettings().MAP_PREFERRED_LOCALE.get();
    // TODO make setting
    LanguagePreference langPref = LanguagePreference.LocalizedOrNative;
    String rendName = app.getSettings().RENDERER.get();
    if (rendName.length() == 0 || rendName.equals(RendererRegistry.DEFAULT_RENDER)) {
        rendName = "default";
    }
    if (!mapStyles.containsKey(rendName)) {
        Log.d(TAG, "Style '" + rendName + "' not in cache");
        if (mapStylesCollection.getStyleByName(rendName) == null) {
            Log.d(TAG, "Unknown '" + rendName + "' style, need to load");
            // Ensure parents are loaded (this may also trigger load)
            app.getRendererRegistry().getRenderer(rendName);
            if (mapStylesCollection.getStyleByName(rendName) == null) {
                try {
                    loadStyleFromStream(rendName, app.getRendererRegistry().getInputStream(rendName));
                } catch (IOException e) {
                    Log.e(TAG, "Failed to load '" + rendName + "'", e);
                }
            }
        }
        ResolvedMapStyle mapStyle = mapStylesCollection.getResolvedStyleByName(rendName);
        if (mapStyle != null) {
            mapStyles.put(rendName, mapStyle);
        } else {
            Log.d(TAG, "Failed to resolve '" + rendName + "', will use 'default'");
            rendName = "default";
        }
    }
    ResolvedMapStyle mapStyle = mapStyles.get(rendName);
    CachedMapPresentation pres = new CachedMapPresentation(langId, langPref, mapStyle, density, app.getSettings().MAP_DENSITY.get(), app.getSettings().TEXT_SCALE.get());
    if (this.presentationObjectParams == null || !this.presentationObjectParams.equalsFields(pres)) {
        this.presentationObjectParams = pres;
        mapPresentationEnvironment = new MapPresentationEnvironment(mapStyle, density, app.getSettings().MAP_DENSITY.get(), app.getSettings().TEXT_SCALE.get(), langId, langPref);
    }
    QStringStringHash convertedStyleSettings = getMapStyleSettings();
    mapPresentationEnvironment.setSettings(convertedStyleSettings);
    if (obfMapRasterLayerProvider != null || obfMapSymbolsProvider != null) {
        recreateRasterAndSymbolsProvider();
    }
}
Also used : LanguagePreference(net.osmand.core.jni.MapPresentationEnvironment.LanguagePreference) MapPresentationEnvironment(net.osmand.core.jni.MapPresentationEnvironment) ResolvedMapStyle(net.osmand.core.jni.ResolvedMapStyle) QStringStringHash(net.osmand.core.jni.QStringStringHash) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 MapPresentationEnvironment (net.osmand.core.jni.MapPresentationEnvironment)1 LanguagePreference (net.osmand.core.jni.MapPresentationEnvironment.LanguagePreference)1 QStringStringHash (net.osmand.core.jni.QStringStringHash)1 ResolvedMapStyle (net.osmand.core.jni.ResolvedMapStyle)1