Search in sources :

Example 1 with ObfsCollection

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

the class NativeCoreContext method init.

public static void init(OsmandApplication app) {
    if (!init && NativeCore.isAvailable()) {
        if (!NativeCore.isLoaded())
            NativeCore.load(CoreResourcesFromAndroidAssets.loadFromCurrentApplication(app));
        if (NativeCore.isLoaded()) {
            File directory = app.getAppPath("");
            Logger.get().addLogSink(QIODeviceLogSink.createFileLogSink(directory.getAbsolutePath() + "/osmandcore.log"));
            WindowManager mgr = (WindowManager) app.getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics dm = new DisplayMetrics();
            mgr.getDefaultDisplay().getMetrics(dm);
            ObfsCollection obfsCollection = new ObfsCollection();
            obfsCollection.addDirectory(directory.getAbsolutePath(), false);
            if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
                obfsCollection.addDirectory(app.getAppPath(IndexConstants.SRTM_INDEX_DIR).getAbsolutePath(), false);
            }
            mapRendererContext = new MapRendererContext(app, dm.density);
            mapRendererContext.setupObfMap(new MapStylesCollection(), obfsCollection);
            app.getRendererRegistry().setRendererLoadedEventListener(mapRendererContext);
            init = true;
        }
    }
}
Also used : SRTMPlugin(net.osmand.plus.srtmplugin.SRTMPlugin) ObfsCollection(net.osmand.core.jni.ObfsCollection) File(java.io.File) DisplayMetrics(android.util.DisplayMetrics) MapRendererContext(net.osmand.core.android.MapRendererContext) WindowManager(android.view.WindowManager) MapStylesCollection(net.osmand.core.jni.MapStylesCollection)

Example 2 with ObfsCollection

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

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SampleApplication app = getMyApplication();
    gestureDetector = new GestureDetector(this, new MapViewOnGestureListener());
    multiTouchSupport = new MultiTouchSupport(this, new MapViewMultiTouchZoomListener());
    // Inflate views
    setContentView(R.layout.activity_main);
    boolean externalStoragePermissionGranted = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
    if (!externalStoragePermissionGranted) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
    }
    // Get map view
    mapView = (AtlasMapRendererView) findViewById(R.id.mapRendererView);
    textZoom = (TextView) findViewById(R.id.text_zoom);
    searchButton = (ImageButton) findViewById(R.id.search_button);
    searchButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showQuickSearch(ShowQuickSearchMode.NEW_IF_EXPIRED, false);
        }
    });
    compassButton = (ImageButton) findViewById(R.id.map_compass_button);
    compassButton.setContentDescription(app.getString("rotate_map_compass_opt"));
    compassDrawable = new CompassDrawable(app.getIconsCache().getIcon(R.drawable.map_compass));
    compassButton.setImageDrawable(compassDrawable);
    compassButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setAzimuth(0f);
        }
    });
    ImageButton myLocationButton = (ImageButton) findViewById(R.id.map_my_location_button);
    myLocationButton.setImageDrawable(app.getIconsCache().getIcon("map_my_location", R.color.color_myloc_distance));
    myLocationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SampleLocationProvider.isLocationPermissionAvailable(MainActivity.this)) {
                goToLocation();
            } else {
                ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, PERMISSION_REQUEST_LOCATION_ON_BUTTON);
            }
        }
    });
    findViewById(R.id.map_zoom_in_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setZoom(zoom + 1f);
        }
    });
    findViewById(R.id.map_zoom_out_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setZoom(zoom - 1f);
        }
    });
    // Additional log sink
    fileLogSink = QIODeviceLogSink.createFileLogSink(app.getAbsoluteAppPath() + "/osmandcore.log");
    Logger.get().addLogSink(fileLogSink);
    // Get device display density factor
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    displayDensityFactor = displayMetrics.densityDpi / 160.0f;
    referenceTileSize = (int) (256 * displayDensityFactor);
    rasterTileSize = Integer.highestOneBit(referenceTileSize - 1) * 2;
    Log.i(TAG, "displayDensityFactor = " + displayDensityFactor);
    Log.i(TAG, "referenceTileSize = " + referenceTileSize);
    Log.i(TAG, "rasterTileSize = " + rasterTileSize);
    Log.i(TAG, "Going to resolve default embedded style...");
    mapStylesCollection = new MapStylesCollection();
    mapStyle = mapStylesCollection.getResolvedStyleByName("default");
    if (mapStyle == null) {
        Log.e(TAG, "Failed to resolve style 'default'");
        System.exit(0);
    }
    Log.i(TAG, "Going to prepare OBFs collection");
    obfsCollection = new ObfsCollection();
    Log.i(TAG, "Will load OBFs from " + app.getAbsoluteAppPath());
    obfsCollection.addDirectory(app.getAbsoluteAppPath(), false);
    Log.i(TAG, "Going to prepare all resources for renderer");
    mapPresentationEnvironment = new MapPresentationEnvironment(mapStyle, displayDensityFactor, 1.0f, 1.0f, SampleApplication.LANGUAGE);
    // mapPresentationEnvironment->setSettings(configuration.styleSettings);
    mapPrimitiviser = new MapPrimitiviser(mapPresentationEnvironment);
    obfMapObjectsProvider = new ObfMapObjectsProvider(obfsCollection);
    mapPrimitivesProvider = new MapPrimitivesProvider(obfMapObjectsProvider, mapPrimitiviser, rasterTileSize);
    mapObjectsSymbolsProvider = new MapObjectsSymbolsProvider(mapPrimitivesProvider, rasterTileSize);
    mapView.setReferenceTileSizeOnScreenInPixels(referenceTileSize);
    mapView.addSymbolsProvider(mapObjectsSymbolsProvider);
    restoreMapState();
    mapLayerProvider0 = new MapRasterLayerProvider_Software(mapPrimitivesProvider);
    mapView.setMapLayerProvider(0, mapLayerProvider0);
    app.getIconsCache().setDisplayDensityFactor(displayDensityFactor);
    initMapMarkers();
    menu = new MapContextMenu();
    menu.setMainActivity(this);
    if (!InstallOsmandAppDialog.show(getSupportFragmentManager(), this) && externalStoragePermissionGranted) {
        checkMapsInstalled();
    }
}
Also used : MapRasterLayerProvider_Software(net.osmand.core.jni.MapRasterLayerProvider_Software) GestureDetector(android.view.GestureDetector) MapContextMenu(net.osmand.core.samples.android.sample1.mapcontextmenu.MapContextMenu) AtlasMapRendererView(net.osmand.core.android.AtlasMapRendererView) View(android.view.View) TextView(android.widget.TextView) DisplayMetrics(android.util.DisplayMetrics) ImageButton(android.widget.ImageButton) MapPrimitiviser(net.osmand.core.jni.MapPrimitiviser) MapPresentationEnvironment(net.osmand.core.jni.MapPresentationEnvironment) MapPrimitivesProvider(net.osmand.core.jni.MapPrimitivesProvider) MapObjectsSymbolsProvider(net.osmand.core.jni.MapObjectsSymbolsProvider) ObfsCollection(net.osmand.core.jni.ObfsCollection) ObfMapObjectsProvider(net.osmand.core.jni.ObfMapObjectsProvider) IMapStylesCollection(net.osmand.core.jni.IMapStylesCollection) MapStylesCollection(net.osmand.core.jni.MapStylesCollection)

Example 3 with ObfsCollection

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

MapStylesCollection (net.osmand.core.jni.MapStylesCollection)3 ObfsCollection (net.osmand.core.jni.ObfsCollection)3 DisplayMetrics (android.util.DisplayMetrics)2 File (java.io.File)2 MapObjectsSymbolsProvider (net.osmand.core.jni.MapObjectsSymbolsProvider)2 MapPresentationEnvironment (net.osmand.core.jni.MapPresentationEnvironment)2 MapPrimitivesProvider (net.osmand.core.jni.MapPrimitivesProvider)2 MapPrimitiviser (net.osmand.core.jni.MapPrimitiviser)2 MapRasterLayerProvider_Software (net.osmand.core.jni.MapRasterLayerProvider_Software)2 ObfMapObjectsProvider (net.osmand.core.jni.ObfMapObjectsProvider)2 GestureDetector (android.view.GestureDetector)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 ImageButton (android.widget.ImageButton)1 TextView (android.widget.TextView)1 Point (java.awt.Point)1 AtlasMapRendererView (net.osmand.core.android.AtlasMapRendererView)1 MapRendererContext (net.osmand.core.android.MapRendererContext)1 AtlasMapRendererConfiguration (net.osmand.core.jni.AtlasMapRendererConfiguration)1 IMapStylesCollection (net.osmand.core.jni.IMapStylesCollection)1