5

我是OSMOSMdroid的新手。

我正在按照这个非常好的教程来显示离线地图。所以基本上我所做的是:

  • 使用 Mobile Atlas Creator 创建了一个 zip 格式的切片包
  • 使用 MapQuest 源,JPEG 格式
  • 将压缩包放入正确的文件夹:/mnt/sdcard/osmdroid/

问题是没有渲染瓷砖。我有一个空白页。

我找到了这个解决方案,来解决我的问题。

但是现在,我不得不使用 PNG 文件,这让我很困扰,这会占用更多的空间。这对我的应用程序来说并不是很有效,因为用户必须下载一个更大的包。

我的问题是:如何在 OSMDroid 和 MapQuest 中使用 JPEG 图块?

提前致谢。

4

3 回答 3

3

这可以获取 JPG 而不是 PNG:

MapView myOpenMapView;
myOpenMapView = (MapView) findViewById(R.id.openmapview);
myOpenMapView.setTileSource(new XYTileSource("MapquestOSM", ResourceProxy.string.mapquest_osm, 0, 18, 256, ".jpg", new String[] {
                "http://otile1.mqcdn.com/tiles/1.0.0/map/", "http://otile2.mqcdn.com/tiles/1.0.0/map/", "http://otile3.mqcdn.com/tiles/1.0.0/map/",
                "http://otile4.mqcdn.com/tiles/1.0.0/map/" }));

注意第 3 行中的“.jpg”。

于 2014-06-06T22:29:52.197 回答
1

我创建了一个支持 jpg 的图块源,您可以查看并调整您的案例,请注意 getTileRelativeFilenameString 不会包含 .title 分机。该部分将由 (MapTileFilesystemProvider) 添加

import java.io.File;
import java.io.InputStream;
import java.util.Random;

import org.osmdroid.ResourceProxy;
import org.osmdroid.ResourceProxy.string;
import org.osmdroid.tileprovider.MapTile;
import org.osmdroid.tileprovider.tilesource.BitmapTileSourceBase.LowMemoryException;
import org.osmdroid.tileprovider.tilesource.ITileSource;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class MapTilerCustomDataSource implements ITileSource {

    private static int globalOrdinal = 0;

    private final int mMinimumZoomLevel;
    private final int mMaximumZoomLevel;

    private final int mOrdinal;
    protected final String mName;
    protected final String mImageFilenameEnding;
    protected final Random random = new Random();

    private final int mTileSizePixels;

    private final string mResourceId;

    public MapTilerCustomDataSource() {
        mResourceId = null;
        mOrdinal = globalOrdinal++;
        mName = "MapquestOSM";
        mMinimumZoomLevel = 0;
        mMaximumZoomLevel = 20;
        mTileSizePixels = 256;
        mImageFilenameEnding = ".jpg";

    }

    @Override
    public String getTileRelativeFilenameString(final MapTile tile) {
        final StringBuilder sb = new StringBuilder();
        sb.append(pathBase());
        sb.append('/');
        sb.append(tile.getZoomLevel());
        sb.append('/');
        sb.append(tile.getX());
        sb.append('/');
        sb.append(tile.getY());
        sb.append(imageFilenameEnding());
        return sb.toString();
    }

    @Override
    public Drawable getDrawable(String aFilePath) throws LowMemoryException {
        try {
            // default implementation will load the file as a bitmap and create
            // a BitmapDrawable from it
            final Bitmap bitmap = BitmapFactory.decodeFile(aFilePath);
            if (bitmap != null) {
                return new BitmapDrawable(bitmap);
            } else {
                // if we couldn't load it then it's invalid - delete it
                try {
                    new File(aFilePath).delete();
                } catch (final Throwable e) {
                }
            }
        } catch (final OutOfMemoryError e) {
            System.gc();
        }
        return null;

    }

    @Override
    public Drawable getDrawable(InputStream aFileInputStream) throws LowMemoryException {
        try {
            // default implementation will load the file as a bitmap and create
            // a BitmapDrawable from it
            final Bitmap bitmap = BitmapFactory.decodeStream(aFileInputStream);
            if (bitmap != null) {
                return new BitmapDrawable(bitmap);
            }
        } catch (final OutOfMemoryError e) {
            System.gc();
        }
        return null;

    }

    @Override
    public int ordinal() {
        return mOrdinal;
    }

    @Override
    public String name() {
        return mName;
    }

    public String pathBase() {
        return mName;
    }

    public String imageFilenameEnding() {
        return mImageFilenameEnding;
    }

    @Override
    public int getMinimumZoomLevel() {
        return mMinimumZoomLevel;
    }

    @Override
    public int getMaximumZoomLevel() {
        return mMaximumZoomLevel;
    }

    @Override
    public int getTileSizePixels() {
        return mTileSizePixels;
    }

    @Override
    public String localizedName(final ResourceProxy proxy) {
        return proxy.getString(mResourceId);
    }

}
于 2013-12-30T07:47:50.873 回答
0

下载“xxx.JPG.tile”文件并将它们重命名为“xxx.PNG.tile”。

于 2014-01-30T18:45:11.673 回答