如何为0.3.0 mapsforge设置本地项目库

时间:2013-03-30 09:50:29

标签: java android maps

我正在寻求有关设置0.3.0 mapsforge库的确切程序的帮助。我已经从0.3.0分支here下载了所有必需的类,但是我遇到了一个问题,我不确定如何为渲染设置资源。下面是我的logcat错误:

03-30 17:02:23.475: E/DatabaseRenderer(17312): org.xml.sax.SAXException: No input specified.
03-30 17:02:23.475: E/DatabaseRenderer(17312):  at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:288)
03-30 17:02:23.475: E/DatabaseRenderer(17312):  at org.mapsforge.android.maps.rendertheme.RenderThemeHandler.getRenderTheme(RenderThemeHandler.java:77)
03-30 17:02:23.475: E/DatabaseRenderer(17312):  at org.mapsforge.android.maps.mapgenerator.databaserenderer.DatabaseRenderer.getRenderTheme(DatabaseRenderer.java:66)
03-30 17:02:23.475: E/DatabaseRenderer(17312):  at org.mapsforge.android.maps.mapgenerator.databaserenderer.DatabaseRenderer.executeJob(DatabaseRenderer.java:149)
03-30 17:02:23.475: E/DatabaseRenderer(17312):  at org.mapsforge.android.maps.mapgenerator.MapWorker.doWork(MapWorker.java:73)
03-30 17:02:23.475: E/DatabaseRenderer(17312):  at org.mapsforge.android.maps.PausableThread.run(PausableThread.java:94)

我真的很困惑,因为它似乎来自DatabaseRenderer中的这一行:

private static RenderTheme getRenderTheme(JobTheme jobTheme) {
    InputStream inputStream = null;
    try {
        inputStream = jobTheme.getRenderThemeAsStream(); //THIS LINE

当我查看jobTheme课程时会更加困惑:

public interface JobTheme extends Serializable {
/**
 * @return an InputStream to read the render theme data from.
 * @throws FileNotFoundException
 *             if the render theme file cannot be found.
 */
    InputStream getRenderThemeAsStream() throws FileNotFoundException;
}

我很失落如何将此方法作为接口类的方法进行调试。那么如何用jobTheme对象调用它呢?

非常感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

我集成了一个地图forge tile提供程序(用作google地图叠加层中的离线地图),我遇到了类似的问题。内置的InternalRenderTheme.OSMARENDER无法正常工作。

这是我最终做的事情:

/**
 * For some reason, if we just use InternalRenderTheme.OSMARENDER, it fails to work (the XML parser gets a NULL
 * as the input stream).  It must be something to do with class loading in dependent libraries.
 * Anyway, this code properly opens the resource in the MapsForge jar as an input stream.
 */
static private class RenderTheme implements JobTheme
{
    static private final String path = "/org/mapsforge/android/maps/rendertheme/osmarender/osmarender.xml";

    @Override
    public InputStream getRenderThemeAsStream()
    {
        return getClass().getResourceAsStream(path);
    }
}

然后我在初始化我的磁贴提供程序时设置了它:

mapGenerator = new DatabaseRenderer();
mapDatabase = new MapDatabase();
mapGenerator.setMapDatabase(mapDatabase);

jobParameters = new JobParameters(new RenderTheme(), DEFAULT_TEXT_SCALE);

我希望这会有所帮助。