Search in sources :

Example 1 with ResolvedMapStyle

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();
    }
}
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 ResolvedMapStyle

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);
}
Also used : ResolvedMapStyle(net.osmand.core.jni.ResolvedMapStyle) MapRasterLayerProvider_Software(net.osmand.core.jni.MapRasterLayerProvider_Software) AtlasMapRendererConfiguration(net.osmand.core.jni.AtlasMapRendererConfiguration) Point(java.awt.Point) MapPrimitiviser(net.osmand.core.jni.MapPrimitiviser) MapPresentationEnvironment(net.osmand.core.jni.MapPresentationEnvironment) MapPrimitivesProvider(net.osmand.core.jni.MapPrimitivesProvider) MapObjectsSymbolsProvider(net.osmand.core.jni.MapObjectsSymbolsProvider) MapRendererSetupOptions(net.osmand.core.jni.MapRendererSetupOptions) ObfsCollection(net.osmand.core.jni.ObfsCollection) File(java.io.File) ObfMapObjectsProvider(net.osmand.core.jni.ObfMapObjectsProvider) MapStylesCollection(net.osmand.core.jni.MapStylesCollection)

Aggregations

MapPresentationEnvironment (net.osmand.core.jni.MapPresentationEnvironment)2 ResolvedMapStyle (net.osmand.core.jni.ResolvedMapStyle)2 Point (java.awt.Point)1 File (java.io.File)1 IOException (java.io.IOException)1 AtlasMapRendererConfiguration (net.osmand.core.jni.AtlasMapRendererConfiguration)1 MapObjectsSymbolsProvider (net.osmand.core.jni.MapObjectsSymbolsProvider)1 LanguagePreference (net.osmand.core.jni.MapPresentationEnvironment.LanguagePreference)1 MapPrimitivesProvider (net.osmand.core.jni.MapPrimitivesProvider)1 MapPrimitiviser (net.osmand.core.jni.MapPrimitiviser)1 MapRasterLayerProvider_Software (net.osmand.core.jni.MapRasterLayerProvider_Software)1 MapRendererSetupOptions (net.osmand.core.jni.MapRendererSetupOptions)1 MapStylesCollection (net.osmand.core.jni.MapStylesCollection)1 ObfMapObjectsProvider (net.osmand.core.jni.ObfMapObjectsProvider)1 ObfsCollection (net.osmand.core.jni.ObfsCollection)1 QStringStringHash (net.osmand.core.jni.QStringStringHash)1