在android中使用.bundlx .bundle格式地图数据

地图数据


image.png
image.png
    public static String bundlesDirIMG= SDCardUtils.getSDCardPathByEnvironment() + Constants.MAP_BUNDLES_DARK;

    public static byte[] mapIMG(int level, int row, int col) throws IOException {
        byte[] result = {};
        String l = "0" + level;
        int lLength = l.length();
        if (lLength > 2) {
            l = l.substring(lLength - 2);
        }
        l = "L" + l;
        //r补0
        int rGroup = 128 * (row / 128);
        String rName = Integer.toHexString(rGroup);
        StringBuilder rbu0 = new StringBuilder();
        if (rName.length() < 4) {
            int i = 4 - rName.length();

            for (int i1 = 0; i1 < i; i1++) {
                rbu0.append("0");
            }

        }
        rbu0.append(rName);
        rbu0.insert(0, "R");
        //c补0
        int cGroup = 128 * (col / 128);
        String cName = Integer.toHexString(cGroup);
        StringBuilder cbu0 = new StringBuilder();
        if (cName.length() < 4) {
            int i = 4 - cName.length();

            for (int i1 = 0; i1 < i; i1++) {
                cbu0.append("0");
            }

        }
        cbu0.append(cName);
        cbu0.insert(0, "C");
        String bundleBase = String.format("%s/%s/%s%s", bundlesDirIMG, l, rbu0.toString(), cbu0.toString());
        String bundlxFileName = bundleBase + ".bundlx";
   //     LogUtils.e("bundlxFileName" + bundlxFileName);
        String bundleFileName = bundleBase + ".bundle";
//        LogUtils.e("bundleFileName" + bundleFileName);
        int index = 128 * (col - cGroup) + (row - rGroup);
        FileInputStream isBundlx = new FileInputStream(bundlxFileName);
        isBundlx.skip(16 + 5 * index);
        byte[] buffer = new byte[5];
        isBundlx.read(buffer);
        long offset = (long) (buffer[0] & 0xff) + (long) (buffer[1] & 0xff)
                * 256 + (long) (buffer[2] & 0xff) * 65536
                + (long) (buffer[3] & 0xff) * 16777216
                + (long) (buffer[4] & 0xff) * 4294967296L;
        FileInputStream isBundle = new FileInputStream(bundleFileName);
        isBundle.skip(offset);
        byte[] lengthBytes = new byte[4];
        isBundle.read(lengthBytes);
        int length = (int) (lengthBytes[0] & 0xff)
                + (int) (lengthBytes[1] & 0xff) * 256
                + (int) (lengthBytes[2] & 0xff) * 65536
                + (int) (lengthBytes[3] & 0xff) * 16777216;
        result = new byte[length];
        int read = isBundle.read(result);
        return result;
    }
image.png

你可能感兴趣的:(在android中使用.bundlx .bundle格式地图数据)