Search in sources :

Example 1 with QStringStringHash

use of net.osmand.core.jni.QStringStringHash 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)

Example 2 with QStringStringHash

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

the class MapRendererContext method getMapStyleSettings.

protected QStringStringHash getMapStyleSettings() {
    // Apply map style settings
    OsmandSettings prefs = app.getSettings();
    RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();
    Map<String, String> props = new HashMap<String, String>();
    for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) {
        if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) {
            continue;
        } else if (customProp.isBoolean()) {
            CommonPreference<Boolean> pref = prefs.getCustomRenderBooleanProperty(customProp.getAttrName());
            props.put(customProp.getAttrName(), pref.get() + "");
        } else {
            CommonPreference<String> settings = prefs.getCustomRenderProperty(customProp.getAttrName());
            String res = settings.get();
            if (!Algorithms.isEmpty(res)) {
                props.put(customProp.getAttrName(), res);
            }
        }
    }
    QStringStringHash convertedStyleSettings = new QStringStringHash();
    for (Map.Entry<String, String> setting : props.entrySet()) {
        convertedStyleSettings.set(setting.getKey(), setting.getValue());
    }
    if (nightMode) {
        convertedStyleSettings.set("nightMode", "true");
    }
    return convertedStyleSettings;
}
Also used : CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) HashMap(java.util.HashMap) QStringStringHash(net.osmand.core.jni.QStringStringHash) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) HashMap(java.util.HashMap) Map(java.util.Map) OsmandSettings(net.osmand.plus.OsmandSettings) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage)

Aggregations

QStringStringHash (net.osmand.core.jni.QStringStringHash)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MapPresentationEnvironment (net.osmand.core.jni.MapPresentationEnvironment)1 LanguagePreference (net.osmand.core.jni.MapPresentationEnvironment.LanguagePreference)1 ResolvedMapStyle (net.osmand.core.jni.ResolvedMapStyle)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 CommonPreference (net.osmand.plus.OsmandSettings.CommonPreference)1 RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)1 RenderingRulesStorage (net.osmand.render.RenderingRulesStorage)1