use of net.osmand.map.ITileSource 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);
}
}
use of net.osmand.map.ITileSource in project Osmand by osmandapp.
the class MapTileLayer method drawTileMap.
public void drawTileMap(Canvas canvas, RotatedTileBox tileBox) {
ITileSource map = this.map;
if (map == null) {
return;
}
ResourceManager mgr = resourceManager;
int nzoom = tileBox.getZoom();
final QuadRect tilesRect = tileBox.getTileBounds();
// recalculate for ellipsoid coordinates
float ellipticTileCorrection = 0;
if (map.isEllipticYTile()) {
ellipticTileCorrection = (float) (MapUtils.getTileEllipsoidNumberY(nzoom, tileBox.getLatitude()) - tileBox.getCenterTileY());
}
int left = (int) Math.floor(tilesRect.left);
int top = (int) Math.floor(tilesRect.top + ellipticTileCorrection);
int width = (int) Math.ceil(tilesRect.right - left);
int height = (int) Math.ceil(tilesRect.bottom + ellipticTileCorrection - top);
boolean useInternet = (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null || OsmandPlugin.getEnabledPlugin(MapillaryPlugin.class) != null) && settings.USE_INTERNET_TO_DOWNLOAD_TILES.get() && settings.isInternetConnectionAvailable() && map.couldBeDownloadedFromInternet();
int maxLevel = map.getMaximumZoomSupported();
int tileSize = map.getTileSize();
boolean oneTileShown = false;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int leftPlusI = left + i;
int topPlusJ = top + j;
int x1 = tileBox.getPixXFromTileXNoRot(leftPlusI);
int x2 = tileBox.getPixXFromTileXNoRot(leftPlusI + 1);
int y1 = tileBox.getPixYFromTileYNoRot(topPlusJ - ellipticTileCorrection);
int y2 = tileBox.getPixYFromTileYNoRot(topPlusJ + 1 - ellipticTileCorrection);
bitmapToDraw.set(x1, y1, x2, y2);
final int tileX = leftPlusI;
final int tileY = topPlusJ;
Bitmap bmp = null;
String ordImgTile = mgr.calculateTileId(map, tileX, tileY, nzoom);
// asking tile image async
boolean imgExist = mgr.tileExistOnFileSystem(ordImgTile, map, tileX, tileY, nzoom);
boolean originalWillBeLoaded = useInternet && nzoom <= maxLevel;
if (imgExist || originalWillBeLoaded) {
bmp = mgr.getBitmapTilesCache().getTileForMapAsync(ordImgTile, map, tileX, tileY, nzoom, useInternet);
}
if (bmp == null) {
int div = 1;
boolean readFromCache = originalWillBeLoaded || imgExist;
boolean loadIfExists = !readFromCache;
// asking if there is small version of the map (in cache)
int allowedScale = Math.min(OVERZOOM_IN + Math.max(0, nzoom - map.getMaximumZoomSupported()), 8);
int kzoom = 1;
for (; kzoom <= allowedScale; kzoom++) {
div *= 2;
String imgTileId = mgr.calculateTileId(map, tileX / div, tileY / div, nzoom - kzoom);
if (readFromCache) {
bmp = mgr.getBitmapTilesCache().get(imgTileId);
if (bmp != null) {
break;
}
} else if (loadIfExists) {
if (mgr.tileExistOnFileSystem(imgTileId, map, tileX / div, tileY / div, nzoom - kzoom) || (useInternet && nzoom - kzoom <= maxLevel)) {
bmp = mgr.getBitmapTilesCache().getTileForMapAsync(imgTileId, map, tileX / div, tileY / div, nzoom - kzoom, useInternet);
break;
}
}
}
if (bmp != null) {
int xZoom = (tileX % div) * tileSize / div;
int yZoom = (tileY % div) * tileSize / div;
// nice scale
boolean useSampling = kzoom > 3;
bitmapToZoom.set(Math.max(xZoom, 0), Math.max(yZoom, 0), Math.min(xZoom + tileSize / div, tileSize), Math.min(yZoom + tileSize / div, tileSize));
if (!useSampling) {
canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap);
} else {
int margin = 1;
int scaledSize = tileSize / div;
float innerMargin = 0.5f;
RectF src = new RectF(0, 0, scaledSize, scaledSize);
if (bitmapToZoom.left >= margin) {
bitmapToZoom.left -= margin;
src.left = innerMargin;
src.right += margin;
}
if (bitmapToZoom.top >= margin) {
bitmapToZoom.top -= margin;
src.top = innerMargin;
src.bottom += margin;
}
if (bitmapToZoom.right + margin <= tileSize) {
bitmapToZoom.right += margin;
src.right += margin - innerMargin;
}
if (bitmapToZoom.bottom + margin <= tileSize) {
bitmapToZoom.bottom += margin;
src.bottom += margin - innerMargin;
}
Matrix m = new Matrix();
RectF dest = new RectF(0, 0, tileSize, tileSize);
m.setRectToRect(src, dest, Matrix.ScaleToFit.FILL);
Bitmap sampled = Bitmap.createBitmap(bmp, bitmapToZoom.left, bitmapToZoom.top, bitmapToZoom.width(), bitmapToZoom.height(), m, true);
bitmapToZoom.set(0, 0, tileSize, tileSize);
// very expensive that's why put in the cache
mgr.getBitmapTilesCache().put(ordImgTile, sampled);
canvas.drawBitmap(sampled, bitmapToZoom, bitmapToDraw, paintBitmap);
}
}
} else {
bitmapToZoom.set(0, 0, tileSize, tileSize);
canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap);
}
if (bmp != null) {
oneTileShown = true;
}
}
}
if (mainMap && !oneTileShown && !useInternet && warningToSwitchMapShown < 3) {
if (resourceManager.getRenderer().containsLatLonMapData(view.getLatitude(), view.getLongitude(), nzoom)) {
Toast.makeText(view.getContext(), R.string.switch_to_vector_map_to_see, Toast.LENGTH_LONG).show();
warningToSwitchMapShown++;
}
}
}
use of net.osmand.map.ITileSource in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method updateLayer.
public void updateLayer(OsmandMapTileView mapView, OsmandSettings settings, MapTileLayer layer, CommonPreference<String> preference, float layerOrder, boolean warnWhenSelected) {
ITileSource overlay = settings.getTileSourceByName(preference.get(), warnWhenSelected);
if (!Algorithms.objectEquals(overlay, layer.getMap())) {
if (overlay == null) {
mapView.removeLayer(layer);
} else if (mapView.getMapRenderer() == null) {
mapView.addLayer(layer, layerOrder);
}
layer.setMap(overlay);
mapView.refreshMap();
}
}
use of net.osmand.map.ITileSource in project Osmand by osmandapp.
the class OsmandRasterMapsPlugin method toggleUnderlayState.
public void toggleUnderlayState(@NonNull MapActivity mapActivity, @NonNull RasterMapType type, @Nullable OnMapSelectedCallback callback) {
OsmandMapTileView mapView = mapActivity.getMapView();
CommonPreference<String> mapTypePreference;
CommonPreference<String> exMapTypePreference;
OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
ITileSource map;
if (type == RasterMapType.OVERLAY) {
mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY;
mapTypePreference = settings.MAP_OVERLAY;
exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS;
map = overlayLayer.getMap();
} else {
// Underlay expected
mapTransparencyPreference = settings.MAP_TRANSPARENCY;
mapTypePreference = settings.MAP_UNDERLAY;
exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
map = underlayLayer.getMap();
}
boolean isChecked = map == null;
boolean showSeekbar = isChecked && RasterMapMenu.isSeekbarVisible(app, type);
boolean hideSeekbar = !isChecked && RasterMapMenu.isSeekbarVisible(app, type);
MapActivityLayers mapLayers = mapActivity.getMapLayers();
CommonPreference<LayerTransparencySeekbarMode> seekbarModePref = settings.LAYER_TRANSPARENCY_SEEKBAR_MODE;
if (showSeekbar) {
mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
mapLayers.getMapControlsLayer().setTransparencyBarEnabled(true);
if (seekbarModePref.get() == LayerTransparencySeekbarMode.UNDEFINED) {
final OsmandSettings.LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == OsmandRasterMapsPlugin.RasterMapType.OVERLAY ? OsmandSettings.LayerTransparencySeekbarMode.OVERLAY : OsmandSettings.LayerTransparencySeekbarMode.UNDERLAY;
seekbarModePref.set(currentMapTypeSeekbarMode);
}
} else if (hideSeekbar) {
mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
mapLayers.getMapControlsLayer().setTransparencyBarEnabled(false);
}
if (map != null) {
mapTypePreference.set(null);
if (callback != null) {
callback.onMapSelected(false);
}
updateMapLayers(mapView, null, mapLayers);
} else {
selectMapOverlayLayer(mapView, mapTypePreference, exMapTypePreference, false, mapActivity, callback);
}
}
Aggregations