Search in sources :

Example 1 with MapLayerConfiguration

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

the class MapVectorLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tilesRect, DrawSettings drawSettings) {
    if (!visible) {
        return;
    }
    // if (!isVectorDataVisible() && tileLayer != null) {
    // tileLayer.drawTileMap(canvas, tilesRect);
    // resourceManager.getRenderer().interruptLoadingMap();
    // } else {
    final MapRendererView mapRenderer = view.getMapRenderer();
    if (mapRenderer != null && !oldRender) {
        NativeCoreContext.getMapRendererContext().setNightMode(drawSettings.isNightMode());
        OsmandSettings st = view.getApplication().getSettings();
        if (!Algorithms.objectEquals(st.MAP_UNDERLAY.get(), cachedUnderlay)) {
            cachedUnderlay = st.MAP_UNDERLAY.get();
            ITileSource tileSource = st.getTileSourceByName(cachedUnderlay, false);
            if (tileSource != null) {
                TileSourceProxyProvider prov = new TileSourceProxyProvider(view.getApplication(), tileSource);
                mapRenderer.setMapLayerProvider(-1, prov.instantiateProxy(true));
                prov.swigReleaseOwnership();
            // mapRenderer.setMapLayerProvider(-1,
            // net.osmand.core.jni.OnlineTileSources.getBuiltIn().createProviderFor("Mapnik (OsmAnd)"));
            } else {
                mapRenderer.resetMapLayerProvider(-1);
            }
        }
        if (!Algorithms.objectEquals(st.MAP_TRANSPARENCY.get(), cachedMapTransparency)) {
            cachedMapTransparency = st.MAP_TRANSPARENCY.get();
            MapLayerConfiguration mapLayerConfiguration = new MapLayerConfiguration();
            mapLayerConfiguration.setOpacityFactor(((float) cachedMapTransparency) / 255.0f);
            mapRenderer.setMapLayerConfiguration(0, mapLayerConfiguration);
        }
        if (!Algorithms.objectEquals(st.MAP_OVERLAY.get(), cachedOverlay)) {
            cachedOverlay = st.MAP_OVERLAY.get();
            ITileSource tileSource = st.getTileSourceByName(cachedOverlay, false);
            if (tileSource != null) {
                TileSourceProxyProvider prov = new TileSourceProxyProvider(view.getApplication(), tileSource);
                mapRenderer.setMapLayerProvider(1, prov.instantiateProxy(true));
                prov.swigReleaseOwnership();
            // mapRenderer.setMapLayerProvider(1,
            // net.osmand.core.jni.OnlineTileSources.getBuiltIn().createProviderFor("Mapnik (OsmAnd)"));
            } else {
                mapRenderer.resetMapLayerProvider(1);
            }
        }
        if (!Algorithms.objectEquals(st.MAP_OVERLAY_TRANSPARENCY.get(), cachedOverlayTransparency)) {
            cachedOverlayTransparency = st.MAP_OVERLAY_TRANSPARENCY.get();
            MapLayerConfiguration mapLayerConfiguration = new MapLayerConfiguration();
            mapLayerConfiguration.setOpacityFactor(((float) cachedOverlayTransparency) / 255.0f);
            mapRenderer.setMapLayerConfiguration(1, mapLayerConfiguration);
        }
        // opengl renderer
        LatLon ll = tilesRect.getLatLonFromPixel(tilesRect.getPixWidth() / 2, tilesRect.getPixHeight() / 2);
        mapRenderer.setTarget(new PointI(MapUtils.get31TileNumberX(ll.getLongitude()), MapUtils.get31TileNumberY(ll.getLatitude())));
        mapRenderer.setAzimuth(-tilesRect.getRotate());
        mapRenderer.setZoom((float) (tilesRect.getZoom() + tilesRect.getZoomAnimation() + tilesRect.getZoomFloatPart()));
        float zoomMagnifier = st.MAP_DENSITY.get();
        mapRenderer.setVisualZoomShift(zoomMagnifier - 1.0f);
    } else {
        if (!view.isZooming()) {
            if (resourceManager.updateRenderedMapNeeded(tilesRect, drawSettings)) {
                // pixRect.set(-view.getWidth(), -view.getHeight() / 2, 2 * view.getWidth(), 3 *
                // view.getHeight() / 2);
                final RotatedTileBox copy = tilesRect.copy();
                copy.increasePixelDimensions(copy.getPixWidth() / 3, copy.getPixHeight() / 4);
                resourceManager.updateRendererMap(copy, null);
            }
        }
        MapRenderRepositories renderer = resourceManager.getRenderer();
        drawRenderedMap(canvas, renderer.getBitmap(), renderer.getBitmapLocation(), tilesRect);
        drawRenderedMap(canvas, renderer.getPrevBitmap(), renderer.getPrevBmpLocation(), tilesRect);
    }
}
Also used : LatLon(net.osmand.data.LatLon) RotatedTileBox(net.osmand.data.RotatedTileBox) MapLayerConfiguration(net.osmand.core.jni.MapLayerConfiguration) MapRendererView(net.osmand.core.android.MapRendererView) PointI(net.osmand.core.jni.PointI) ITileSource(net.osmand.map.ITileSource) TileSourceProxyProvider(net.osmand.core.android.TileSourceProxyProvider) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

MapRendererView (net.osmand.core.android.MapRendererView)1 TileSourceProxyProvider (net.osmand.core.android.TileSourceProxyProvider)1 MapLayerConfiguration (net.osmand.core.jni.MapLayerConfiguration)1 PointI (net.osmand.core.jni.PointI)1 LatLon (net.osmand.data.LatLon)1 RotatedTileBox (net.osmand.data.RotatedTileBox)1 ITileSource (net.osmand.map.ITileSource)1 OsmandSettings (net.osmand.plus.OsmandSettings)1