From cd5a62a2ff1d9e946bcf9120feb23fdc4578a782 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Mon, 16 Oct 2017 13:52:58 +0200 Subject: [PATCH] Mapsforge maps v5 support (#429) --- .../tiling/source/mapfile/ReadBuffer.java | 47 ++++++++++++++++++- .../source/mapfile/header/RequiredFields.java | 2 +- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/vtm/src/org/oscim/tiling/source/mapfile/ReadBuffer.java b/vtm/src/org/oscim/tiling/source/mapfile/ReadBuffer.java index e5392d74..db155065 100644 --- a/vtm/src/org/oscim/tiling/source/mapfile/ReadBuffer.java +++ b/vtm/src/org/oscim/tiling/source/mapfile/ReadBuffer.java @@ -1,6 +1,7 @@ /* * Copyright 2010, 2011, 2012 mapsforge.org * Copyright 2017 devemux86 + * Copyright 2017 Gustl22 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -24,6 +25,9 @@ import org.oscim.utils.Parameters; import java.io.IOException; import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Logger; /** @@ -50,6 +54,18 @@ public class ReadBuffer { return mBufferData[mBufferPosition++]; } + /** + * Converts four bytes from the read buffer to a float. + * + * @return the float value. + */ + public float readFloat() { + byte[] bytes = new byte[4]; + System.arraycopy(mBufferData, mBufferPosition, bytes, 0, 4); + mBufferPosition += 4; + return ByteBuffer.wrap(bytes).getFloat(); + } + /** * Reads the given amount of bytes from the file into the read buffer and * resets the internal buffer position. If @@ -394,6 +410,7 @@ public class ReadBuffer { boolean readTags(TagSet tags, Tag[] wayTags, byte numberOfTags) { tags.clear(); + List ids = new ArrayList<>(); int maxTag = wayTags.length; @@ -401,10 +418,36 @@ public class ReadBuffer { int tagId = readUnsignedInt(); if (tagId < 0 || tagId >= maxTag) { LOG.warning("invalid tag ID: " + tagId); - return true; + break; } - tags.add(wayTags[tagId]); + ids.add(tagId); } + + for (Integer id : ids) { + Tag tag = wayTags[id]; + // Decode variable values of tags + if (tag.value.charAt(0) == '%' && tag.value.length() == 2) { + String value = tag.value; + if (value.charAt(1) == 'b') { + value = String.valueOf(readByte()); + } else if (value.charAt(1) == 'i') { + if (tag.key.contains(":colour")) { + value = "#" + Integer.toHexString(readInt()); + } else { + value = String.valueOf(readInt()); + } + } else if (value.charAt(1) == 'f') { + value = String.valueOf(readFloat()); + } else if (value.charAt(1) == 'h') { + value = String.valueOf(readShort()); + } else if (value.charAt(1) == 's') { + value = readUTF8EncodedString(); + } + tag = new Tag(tag.key, value); + } + tags.add(tag); + } + return true; } diff --git a/vtm/src/org/oscim/tiling/source/mapfile/header/RequiredFields.java b/vtm/src/org/oscim/tiling/source/mapfile/header/RequiredFields.java index 84a060cd..b06b6bf5 100644 --- a/vtm/src/org/oscim/tiling/source/mapfile/header/RequiredFields.java +++ b/vtm/src/org/oscim/tiling/source/mapfile/header/RequiredFields.java @@ -58,7 +58,7 @@ final class RequiredFields { /** * Highest version of the map file format supported by this implementation. */ - private static final int SUPPORTED_FILE_VERSION_MAX = 4; + private static final int SUPPORTED_FILE_VERSION_MAX = 5; /** * The maximum latitude values in microdegrees.