Search in sources :

Example 1 with LevelInfo

use of uk.me.parabola.mkgmap.general.LevelInfo in project mkgmap by openstreetmap.

the class PolishMapDataSource method overviewMapLevels.

@Override
public LevelInfo[] overviewMapLevels() {
    String levelSpec = getConfig().getProperty("overview-levels");
    if (levelSpec == null)
        return null;
    LevelInfo[] levels = LevelInfo.createFromString(levelSpec);
    for (int i = 0; i < levels.length; i++) levels[i] = new LevelInfo(levels.length - i - 1, levels[i].getBits());
    return levels;
}
Also used : LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 2 with LevelInfo

use of uk.me.parabola.mkgmap.general.LevelInfo in project mkgmap by openstreetmap.

the class TypeReaderTest method makeType.

private GType makeType(String in) {
    LevelInfo[] levels = LevelInfo.createFromString("0:24 1:20 2:18 3:16 4:14");
    TypeReader tr = new TypeReader(FeatureKind.POLYLINE, levels);
    TokenScanner ts = new TokenScanner("string", new StringReader(in));
    ts.setExtraWordChars("-:");
    return tr.readType(ts);
}
Also used : TokenScanner(uk.me.parabola.mkgmap.scan.TokenScanner) LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) StringReader(java.io.StringReader)

Example 3 with LevelInfo

use of uk.me.parabola.mkgmap.general.LevelInfo in project mkgmap by openstreetmap.

the class OverviewBuilder method calcLevels.

private void calcLevels() {
    List<MapShape> shapes = overviewSource.getShapes();
    // we can write a 0x4a polygon for planet in res 16
    int maxRes = 16;
    if (wantedLevels != null)
        maxRes = wantedLevels[wantedLevels.length - 1].getBits();
    int maxSize = 0xffff << (24 - maxRes);
    for (MapShape s : shapes) {
        if (s.getType() != 0x4a)
            continue;
        int maxDimPoly = s.getBounds().getMaxDimension();
        if (maxDimPoly > maxSize) {
            int oldMaxRes = maxRes;
            while (maxDimPoly > maxSize) {
                maxRes--;
                maxSize = 0xffff << (24 - maxRes);
            }
            String[] name = s.getName().split("\u001d");
            String msg = "Tile selection (0x4a) polygon for ";
            if (name != null && name.length == 2)
                msg += "tile " + name[1].trim();
            else
                msg += s.getBounds();
            log.error(msg, "cannot be written in level 0 resolution", oldMaxRes + ", using", maxRes, "instead");
        }
    }
    if (wantedLevels == null)
        setRes(maxRes);
    else {
        // make sure that the wanted levels for the overview map
        // can store the largest 0x4a polygon at level 0
        int n = wantedLevels.length - 1;
        while (n > 0 && wantedLevels[n].getBits() > maxRes) n--;
        if (n > 0) {
            int l = 0;
            while (n >= 0) {
                wantedLevels[n] = new LevelInfo(l++, wantedLevels[n].getBits());
                n--;
            }
            wantedLevels = Arrays.copyOfRange(wantedLevels, 0, l);
            overviewSource.setMapLevels(wantedLevels);
        } else
            setRes(maxRes);
    }
}
Also used : LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) MapShape(uk.me.parabola.mkgmap.general.MapShape) Point(uk.me.parabola.imgfmt.app.trergn.Point) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 4 with LevelInfo

use of uk.me.parabola.mkgmap.general.LevelInfo in project mkgmap by openstreetmap.

the class OverviewBuilder method setRes.

/**
 * Set the highest resolution
 * @param resolution
 */
private void setRes(int resolution) {
    LevelInfo[] mapLevels = new LevelInfo[1];
    mapLevels[0] = new LevelInfo(0, resolution);
    overviewSource.setMapLevels(mapLevels);
}
Also used : LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo)

Example 5 with LevelInfo

use of uk.me.parabola.mkgmap.general.LevelInfo in project mkgmap by openstreetmap.

the class MapBuilder method makeMapAreas.

/**
 * Drive the map generation by stepping through the levels, generating the
 * subdivisions for the level and filling in the map elements that should
 * go into the area.
 *
 * This is fairly complex: you need to divide into subdivisions depending on
 * their size and the number of elements that will be contained.
 *
 * @param map The map.
 * @param src The data for the map.
 */
private void makeMapAreas(Map map, LoadableMapDataSource src) {
    // The top level has to cover the whole map without subdividing, so
    // do a special check to make sure.
    LevelInfo[] levels = null;
    if (src instanceof OverviewMapDataSource) {
        mergeLines = true;
        prepShapesForMerge(src.getShapes());
        mergeShapes = true;
        levels = src.mapLevels();
    } else {
        if (OverviewBuilder.isOverviewImg(map.getFilename())) {
            levels = src.overviewMapLevels();
        } else {
            levels = src.mapLevels();
        }
    }
    if (levels == null) {
        throw new ExitException("no info about levels available.");
    }
    LevelInfo levelInfo = levels[0];
    // If there is already a top level zoom, then we shouldn't add our own
    Subdivision topdiv;
    if (levelInfo.isTop()) {
        // There is already a top level definition.  So use the values from it and
        // then remove it from the levels definition.
        levels = Arrays.copyOfRange(levels, 1, levels.length);
        Zoom zoom = map.createZoom(levelInfo.getLevel(), levelInfo.getBits());
        topdiv = makeTopArea(src, map, zoom);
    } else {
        // We have to automatically create the definition for the top zoom level.
        int maxBits = getMaxBits(src);
        // decrease it so that it is less.
        if (levelInfo.getBits() <= maxBits)
            maxBits = levelInfo.getBits() - 1;
        // Create the empty top level
        Zoom zoom = map.createZoom(levelInfo.getLevel() + 1, maxBits);
        topdiv = makeTopArea(src, map, zoom);
    }
    // We start with one map data source.
    List<SourceSubdiv> srcList = Collections.singletonList(new SourceSubdiv(src, topdiv));
    // Now the levels filled with features.
    for (LevelInfo linfo : levels) {
        List<SourceSubdiv> nextList = new ArrayList<>();
        Zoom zoom = map.createZoom(linfo.getLevel(), linfo.getBits());
        for (SourceSubdiv srcDivPair : srcList) {
            MapSplitter splitter = new MapSplitter(srcDivPair.getSource(), zoom);
            MapArea[] areas = splitter.split(orderByDecreasingArea);
            log.info("Map region", srcDivPair.getSource().getBounds(), "split into", areas.length, "areas at resolution", zoom.getResolution());
            for (MapArea area : areas) {
                Subdivision parent = srcDivPair.getSubdiv();
                Subdivision div = makeSubdivision(map, parent, area, zoom);
                if (log.isDebugEnabled())
                    log.debug("ADD parent-subdiv", parent, srcDivPair.getSource(), ", z=", zoom, " new=", div);
                nextList.add(new SourceSubdiv(area, div));
            }
            if (nextList.size() > 0) {
                Subdivision lastdiv = nextList.get(nextList.size() - 1).getSubdiv();
                lastdiv.setLast(true);
            }
        }
        srcList = nextList;
    }
}
Also used : LevelInfo(uk.me.parabola.mkgmap.general.LevelInfo) ArrayList(java.util.ArrayList) Subdivision(uk.me.parabola.imgfmt.app.trergn.Subdivision) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) Zoom(uk.me.parabola.imgfmt.app.trergn.Zoom) ExitException(uk.me.parabola.imgfmt.ExitException) OverviewMapDataSource(uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource)

Aggregations

LevelInfo (uk.me.parabola.mkgmap.general.LevelInfo)8 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)6 Point (uk.me.parabola.imgfmt.app.trergn.Point)3 ExitException (uk.me.parabola.imgfmt.ExitException)2 Zoom (uk.me.parabola.imgfmt.app.trergn.Zoom)2 FileNotFoundException (java.io.FileNotFoundException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 MapReader (uk.me.parabola.imgfmt.app.map.MapReader)1 Subdivision (uk.me.parabola.imgfmt.app.trergn.Subdivision)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapShape (uk.me.parabola.mkgmap.general.MapShape)1 OverviewMapDataSource (uk.me.parabola.mkgmap.reader.overview.OverviewMapDataSource)1 TokenScanner (uk.me.parabola.mkgmap.scan.TokenScanner)1