From dea77fbd5bfeebd7f95cb39055cdc13136798c40 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Fri, 28 Jun 2013 04:11:41 +0200 Subject: [PATCH] bring back TestTileSource --- .../oscim/tilesource/test/TestTileSource.java | 290 +++++++++--------- 1 file changed, 147 insertions(+), 143 deletions(-) diff --git a/vtm/src/org/oscim/tilesource/test/TestTileSource.java b/vtm/src/org/oscim/tilesource/test/TestTileSource.java index 0306f4d0..82c79a20 100644 --- a/vtm/src/org/oscim/tilesource/test/TestTileSource.java +++ b/vtm/src/org/oscim/tilesource/test/TestTileSource.java @@ -22,173 +22,177 @@ import org.oscim.layers.tile.MapTile; import org.oscim.tilesource.ITileDataSink; import org.oscim.tilesource.ITileDataSource; import org.oscim.tilesource.MapInfo; +import org.oscim.tilesource.TileSource; -/** - * - * - */ -public class TestTileSource implements ITileDataSource { - - private final Tag[] mTags = { - new Tag("natural", "water") - }; - private final Tag[] mTagsWay = { - new Tag("highway", "primary"), - new Tag("name", "Highway Rd") - }; - private final Tag[] mTagsBoundary = { - new Tag("boundary", "administrative"), - new Tag("admin_level", "2") - }; - private final Tag[] mTagsPlace = { - new Tag("place", "city"), - null - }; +public class TestTileSource extends TileSource { private final MapInfo mMapInfo = - new MapInfo(new BoundingBox(-180, -90, 180, 90), - new Byte((byte) 5), null, null, 0, 0, 0, - "", "", "", null); + new MapInfo(new BoundingBox(-180, -90, 180, 90), + new Byte((byte) 5), null, null, 0, 0, 0, + "", "", "", null); - private final boolean mOpenFile = false; - - private final MapElement mElem; - - public TestTileSource() { - mElem = new MapElement(); - } - - private final boolean renderWays = false; - private final boolean renderBoundary = false; - private final boolean renderPlace = false; + // private boolean mOpenFile = false; @Override - public QueryResult executeQuery(MapTile tile, - ITileDataSink mapDataSink) { + public ITileDataSource getDataSource() { + return new TileDataSource(); + } - int size = Tile.SIZE; - MapElement e = mElem; + @Override + public OpenResult open() { + // mOpenFile =true; + return OpenResult.SUCCESS; + } - float x1 = -1; - float y1 = -1; - float x2 = size + 1; - float y2 = size + 1; + @Override + public void close() { + // mOpenFile = false; + } - // always clear geometry before starting - // a different type. - e.clear(); - e.startPolygon(); - e.addPoint(x1, y1); - e.addPoint(x2, y1); - e.addPoint(x2, y2); - e.addPoint(x1, y2); + @Override + public MapInfo getMapInfo() { + return mMapInfo; + } - y1 = 5; - y2 = size - 5; - x1 = 5; - x2 = size - 5; + static class TileDataSource implements ITileDataSource { - e.startHole(); - e.addPoint(x1, y1); - e.addPoint(x2, y1); - e.addPoint(x2, y2); - e.addPoint(x1, y2); + private static final Tag[] mTags = { + new Tag("natural", "water") + }; + private static final Tag[] mTagsWay = { + new Tag("highway", "primary"), + new Tag("name", "Highway Rd") + }; + private static final Tag[] mTagsBoundary = { + new Tag("boundary", "administrative"), + new Tag("admin_level", "2") + }; - //// FIXME e.setLayer(mTags, 0); - mapDataSink.process(e); + private static final Tag[] mTagsPlace = { + new Tag("place", "city"), + null + }; - if (renderWays) { - e.clear(); + private final MapElement mElem; - // middle horizontal - e.startLine(); - e.addPoint(0, size / 2); - e.addPoint(size, size / 2); - - // center up - e.startLine(); - e.addPoint(size / 2, -size / 2); - e.addPoint(size / 2, size / 2); - - // center down - e.startLine(); - e.addPoint(size / 2, size / 2); - e.addPoint(size / 2, size / 2 + size); - - ////e.setLayer(mTagsWay, 0); - mapDataSink.process(e); - - e.clear(); - // left-top to center - e.startLine(); - e.addPoint(size / 2, size / 2); - e.addPoint(10, 10); - - e.startLine(); - e.addPoint(0, 10); - e.addPoint(size, 10); - - e.startLine(); - e.addPoint(10, 0); - e.addPoint(10, size); - - //// --e.setLayer(mTagsWay, 1); - mapDataSink.process(e); + public TileDataSource() { + mElem = new MapElement(); } - if (renderBoundary) { + private final boolean renderWays = true; + private final boolean renderBoundary = false; + private final boolean renderPlace = false; + + @Override + public QueryResult executeQuery(MapTile tile, + ITileDataSink mapDataSink) { + + int size = Tile.SIZE; + MapElement e = mElem; + + float x1 = -1; + float y1 = -1; + float x2 = size + 1; + float y2 = size + 1; + + // always clear geometry before starting + // a different type. e.clear(); e.startPolygon(); - float r = size / 2; + e.addPoint(x1, y1); + e.addPoint(x2, y1); + e.addPoint(x2, y2); + e.addPoint(x1, y2); - for (int i = 0; i < 360; i += 4) { - double d = Math.toRadians(i); - e.addPoint(r + (float) Math.cos(d) * (r - 40), - r + (float) Math.sin(d) * (r - 40)); + y1 = 5; + y2 = size - 5; + x1 = 5; + x2 = size - 5; + + e.startHole(); + e.addPoint(x1, y1); + e.addPoint(x2, y1); + e.addPoint(x2, y2); + e.addPoint(x1, y2); + + e.setLayer(0); + e.tags.set(mTags); + mapDataSink.process(e); + + if (renderWays) { + e.clear(); + + // middle horizontal + e.startLine(); + e.addPoint(0, size / 2); + e.addPoint(size, size / 2); + + // center up + e.startLine(); + e.addPoint(size / 2, -size / 2); + e.addPoint(size / 2, size / 2); + + // center down + e.startLine(); + e.addPoint(size / 2, size / 2); + e.addPoint(size / 2, size / 2 + size); + + // //e.setLayer(mTagsWay, 0); + mapDataSink.process(e); + + e.clear(); + // left-top to center + e.startLine(); + e.addPoint(size / 2, size / 2); + e.addPoint(10, 10); + + e.startLine(); + e.addPoint(0, 10); + e.addPoint(size, 10); + + e.startLine(); + e.addPoint(10, 0); + e.addPoint(10, size); + + e.setLayer(1); + e.tags.set(mTagsWay); + mapDataSink.process(e); } - //// e.setLayer(mTagsBoundary, 1); - mapDataSink.process(e); + if (renderBoundary) { + e.clear(); + e.startPolygon(); + float r = size / 2; + + for (int i = 0; i < 360; i += 4) { + double d = Math.toRadians(i); + e.addPoint(r + (float) Math.cos(d) * (r - 40), + r + (float) Math.sin(d) * (r - 40)); + } + + e.setLayer(1); + e.tags.set(mTagsWay); + mapDataSink.process(e); + } + + if (renderPlace) { + e.clear(); + e.startPoints(); + e.addPoint(size / 2, size / 2); + + mTagsPlace[1] = new Tag("name", tile.toString()); + e.tags.set(mTagsPlace); + mapDataSink.process(e); + } + + mapDataSink.completed(true); + + return QueryResult.SUCCESS; } - if (renderPlace) { - e.clear(); - e.startPoints(); - e.addPoint(size / 2, size / 2); - - mTagsPlace[1] = new Tag("name", tile.toString()); - //// e.setLayer(mTagsPlace, 0); - mapDataSink.process(e); + @Override + public void destroy() { } - return QueryResult.SUCCESS; - } - - -// @Override -// public boolean isOpen() { -// return mOpenFile; -// } -// -// @Override -// public OpenResult open(MapOptions options) { -// mOpenFile = true; -// return OpenResult.SUCCESS; -// } -// -// @Override -// public void close() { -// mOpenFile = false; -// } -// -// @Override -// public void cancel() { -// } - - - @Override - public void destroy() { - // TODO Auto-generated method stub - } }