use of net.osmand.core.jni.ResolvedMapStyle 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();
}
}
use of net.osmand.core.jni.ResolvedMapStyle in project OsmAnd-tools by osmandapp.
the class QtCorePanel method init.
@Override
public void init(GLAutoDrawable drawable) {
NativeEngineOptions options = new NativeEngineOptions();
options.parseRenderingProperties(renderingProperties);
MapStylesCollection mapStylesCollection = new MapStylesCollection();
ResolvedMapStyle mapStyle = null;
if (this.styleFile != null) {
mapStylesCollection.addStyleFromFile(this.styleFile);
System.out.println("Going to use map style from: " + this.styleFile);
mapStyle = mapStylesCollection.getResolvedStyleByName((new File(this.styleFile)).getName());
} else {
System.out.println("Going to use embedded map style");
mapStyle = mapStylesCollection.getResolvedStyleByName("default");
}
if (mapStyle == null) {
System.err.println("Failed to resolve style");
release();
OsmAndCore.ReleaseCore();
System.exit(0);
}
ObfsCollection obfsCollection = new ObfsCollection();
String filesDir = DataExtractionSettings.getSettings().getBinaryFilesDir();
obfsCollection.addDirectory(filesDir, false);
MapPresentationEnvironment mapPresentationEnvironment = new MapPresentationEnvironment(mapStyle, options.density, 1.0f, options.symbolsScale / options.density, options.getLocaleLanguageId(), options.getLanguagePreference());
referenceTileSize = 256 * options.density;
int rasterTileSize = Integer.highestOneBit((int) referenceTileSize - 1) * 2;
mapPresentationEnvironment.setSettings(options.getStyleSettings());
MapPrimitiviser mapPrimitiviser = new MapPrimitiviser(mapPresentationEnvironment);
ObfMapObjectsProvider obfMapObjectsProvider = new ObfMapObjectsProvider(obfsCollection);
MapPrimitivesProvider mapPrimitivesProvider = new MapPrimitivesProvider(obfMapObjectsProvider, mapPrimitiviser, rasterTileSize);
MapObjectsSymbolsProvider mapObjectsSymbolsProvider = new MapObjectsSymbolsProvider(mapPrimitivesProvider, rasterTileSize);
MapRasterLayerProvider_Software mapRasterLayerProvider = new MapRasterLayerProvider_Software(mapPrimitivesProvider);
mapRenderer = OsmAndCore.createMapRenderer(MapRendererClass.AtlasMapRenderer_OpenGL2plus);
if (mapRenderer == null) {
System.err.println("Failed to create map renderer 'AtlasMapRenderer_OpenGL2plus'");
release();
OsmAndCore.ReleaseCore();
System.exit(0);
}
MapRendererSetupOptions rendererSetupOptions = new MapRendererSetupOptions();
rendererSetupOptions.setGpuWorkerThreadEnabled(false);
rendererSetupOptions.setFrameUpdateRequestCallback(callback.getBinding());
mapRenderer.setup(rendererSetupOptions);
AtlasMapRendererConfiguration atlasRendererConfiguration = AtlasMapRendererConfiguration.Casts.upcastFrom(mapRenderer.getConfiguration());
atlasRendererConfiguration.setReferenceTileSizeOnScreenInPixels(referenceTileSize);
mapRenderer.setConfiguration(AtlasMapRendererConfiguration.Casts.downcastTo_MapRendererConfiguration(atlasRendererConfiguration));
mapRenderer.addSymbolsProvider(mapObjectsSymbolsProvider);
mapRenderer.setAzimuth(0.0f);
mapRenderer.setElevationAngle(90);
mapRenderer.setDebugSettings(options.getDebugSettings());
mapCanvas.updateRenderer();
/*
* IMapRasterLayerProvider mapnik = OnlineTileSources.getBuiltIn().createProviderFor("Mapnik (OsmAnd)"); if
* (mapnik == null) Log.e(TAG, "Failed to create mapnik");
*/
mapRenderer.setMapLayerProvider(0, mapRasterLayerProvider);
}
Aggregations