Improve code / xml formatting, closes #54

This commit is contained in:
Emux
2016-07-09 19:45:22 +03:00
parent 7919d0ab9c
commit e793e8851b
458 changed files with 58405 additions and 63062 deletions

View File

@@ -3,10 +3,10 @@ package org.oscim.jeo;
import org.jeo.map.RGB;
public class JeoUtils {
public static int color(RGB rgb) {
return rgb.getAlpha() << 24
| rgb.getRed() << 16
| rgb.getGreen() << 8
| rgb.getBlue();
}
public static int color(RGB rgb) {
return rgb.getAlpha() << 24
| rgb.getRed() << 16
| rgb.getGreen() << 8
| rgb.getBlue();
}
}

View File

@@ -16,15 +16,8 @@
*/
package org.oscim.layers;
import static org.oscim.tiling.QueryResult.FAILED;
import static org.oscim.tiling.QueryResult.SUCCESS;
import static org.oscim.tiling.QueryResult.TILE_NOT_FOUND;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.jeo.tile.TileDataset;
import org.jeo.tile.Tile;
import org.jeo.tile.TileDataset;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.canvas.Bitmap;
import org.oscim.layers.tile.MapTile;
@@ -34,73 +27,80 @@ import org.oscim.tiling.TileSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import static org.oscim.tiling.QueryResult.FAILED;
import static org.oscim.tiling.QueryResult.SUCCESS;
import static org.oscim.tiling.QueryResult.TILE_NOT_FOUND;
public class JeoTileSource extends TileSource {
final static Logger log = LoggerFactory.getLogger(JeoTileSource.class);
final static Logger log = LoggerFactory.getLogger(JeoTileSource.class);
final TileDataset mTileDataset;
final TileDataset mTileDataset;
public JeoTileSource(TileDataset tileDataset) {
log.debug("load tileset {}", tileDataset.name());
mTileDataset = tileDataset;
//mTileDataset.pyramid().
mZoomMax = 1;
mZoomMin = 0;
}
public JeoTileSource(TileDataset tileDataset) {
log.debug("load tileset {}", tileDataset.name());
mTileDataset = tileDataset;
//mTileDataset.pyramid().
mZoomMax = 1;
mZoomMin = 0;
}
@Override
public ITileDataSource getDataSource() {
return new ITileDataSource() {
@Override
public ITileDataSource getDataSource() {
return new ITileDataSource() {
@Override
public void query(MapTile tile, ITileDataSink sink) {
log.debug("query {}", tile);
try {
Tile t = mTileDataset.read(tile.zoomLevel, tile.tileX,
// flip Y axis
(1 << tile.zoomLevel) - 1 - tile.tileY);
if (t == null) {
log.debug("not found {}", tile);
sink.completed(TILE_NOT_FOUND);
return;
}
Bitmap b = CanvasAdapter.decodeBitmap(new ByteArrayInputStream(t.data()));
sink.setTileImage(b);
log.debug("success {}", tile);
sink.completed(SUCCESS);
return;
@Override
public void query(MapTile tile, ITileDataSink sink) {
log.debug("query {}", tile);
try {
Tile t = mTileDataset.read(tile.zoomLevel, tile.tileX,
// flip Y axis
(1 << tile.zoomLevel) - 1 - tile.tileY);
if (t == null) {
log.debug("not found {}", tile);
sink.completed(TILE_NOT_FOUND);
return;
}
Bitmap b = CanvasAdapter.decodeBitmap(new ByteArrayInputStream(t.data()));
sink.setTileImage(b);
log.debug("success {}", tile);
sink.completed(SUCCESS);
return;
} catch (IOException e) {
e.printStackTrace();
}
log.debug("fail {}", tile);
sink.completed(FAILED);
}
} catch (IOException e) {
e.printStackTrace();
}
log.debug("fail {}", tile);
sink.completed(FAILED);
}
@Override
public void dispose() {
@Override
public void dispose() {
}
}
@Override
public void cancel() {
@Override
public void cancel() {
}
}
};
}
};
}
int mRefs;
int mRefs;
@Override
public OpenResult open() {
mRefs++;
return OpenResult.SUCCESS;
}
@Override
public OpenResult open() {
mRefs++;
return OpenResult.SUCCESS;
}
@Override
public void close() {
if (--mRefs == 0)
mTileDataset.close();
}
@Override
public void close() {
if (--mRefs == 0)
mTileDataset.close();
}
}

View File

@@ -16,17 +16,19 @@
*/
package org.oscim.layers;
import java.io.IOException;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import org.jeo.vector.VectorQuery;
import org.jeo.vector.VectorDataset;
import org.jeo.vector.Feature;
import org.jeo.geom.Geom;
import org.jeo.map.CartoCSS;
import org.jeo.map.RGB;
import org.jeo.map.Rule;
import org.jeo.map.RuleList;
import org.jeo.map.Style;
import org.jeo.vector.Feature;
import org.jeo.vector.VectorDataset;
import org.jeo.vector.VectorQuery;
import org.oscim.jeo.JeoUtils;
import org.oscim.map.Map;
import org.oscim.renderer.bucket.LineBucket;
@@ -36,133 +38,131 @@ import org.oscim.theme.styles.LineStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import java.io.IOException;
public class JeoVectorLayer extends JtsLayer {
public static final Logger log = LoggerFactory.getLogger(JeoVectorLayer.class);
static final boolean dbg = false;
public static final Logger log = LoggerFactory.getLogger(JeoVectorLayer.class);
static final boolean dbg = false;
private final VectorDataset mDataset;
private final RuleList mRules;
private final VectorDataset mDataset;
private final RuleList mRules;
protected double mDropPointDistance = 0.01;
private double mMinX;
private double mMinY;
protected double mDropPointDistance = 0.01;
private double mMinX;
private double mMinY;
public JeoVectorLayer(Map map, VectorDataset data, Style style) {
super(map);
mDataset = data;
public JeoVectorLayer(Map map, VectorDataset data, Style style) {
super(map);
mDataset = data;
mRules = style.getRules().selectById(data.name(), true).flatten();
//mRules = style.getRules().selectById("way", true).flatten();
log.debug(mRules.toString());
mRules = style.getRules().selectById(data.name(), true).flatten();
//mRules = style.getRules().selectById("way", true).flatten();
log.debug(mRules.toString());
mRenderer = new Renderer();
}
mRenderer = new Renderer();
}
@Override
protected void processFeatures(Task t, Envelope b) {
if (mDropPointDistance > 0) {
/* reduce lines points min distance */
mMinX = ((b.getMaxX() - b.getMinX()) / mMap.getWidth());
mMinY = ((b.getMaxY() - b.getMinY()) / mMap.getHeight());
mMinX *= mDropPointDistance;
mMinY *= mDropPointDistance;
}
@Override
protected void processFeatures(Task t, Envelope b) {
if (mDropPointDistance > 0) {
/* reduce lines points min distance */
mMinX = ((b.getMaxX() - b.getMinX()) / mMap.getWidth());
mMinY = ((b.getMaxY() - b.getMinY()) / mMap.getHeight());
mMinX *= mDropPointDistance;
mMinY *= mDropPointDistance;
}
try {
VectorQuery q = new VectorQuery().bounds(b);
if (dbg)
log.debug("query {}", b);
for (Feature f : mDataset.cursor(q)) {
if (dbg)
log.debug("feature {}", f);
try {
VectorQuery q = new VectorQuery().bounds(b);
if (dbg)
log.debug("query {}", b);
for (Feature f : mDataset.cursor(q)) {
if (dbg)
log.debug("feature {}", f);
RuleList rs = mRules.match(f);
if (rs.isEmpty())
continue;
RuleList rs = mRules.match(f);
if (rs.isEmpty())
continue;
Rule r = rs.collapse();
if (r == null)
continue;
Rule r = rs.collapse();
if (r == null)
continue;
Geometry g = f.geometry();
if (g == null)
continue;
Geometry g = f.geometry();
if (g == null)
continue;
switch (Geom.Type.from(g)) {
case POINT:
addPoint(t, f, r, g);
break;
case MULTIPOINT:
for (int i = 0, n = g.getNumGeometries(); i < n; i++)
addPoint(t, f, r, g.getGeometryN(i));
break;
case LINESTRING:
addLine(t, f, r, g);
break;
case MULTILINESTRING:
for (int i = 0, n = g.getNumGeometries(); i < n; i++)
addLine(t, f, r, g.getGeometryN(i));
break;
case POLYGON:
addPolygon(t, f, r, g);
break;
case MULTIPOLYGON:
for (int i = 0, n = g.getNumGeometries(); i < n; i++)
addPolygon(t, f, r, g.getGeometryN(i));
break;
default:
break;
}
}
} catch (IOException e) {
log.error("Error querying layer " + mDataset.name() + e);
}
}
switch (Geom.Type.from(g)) {
case POINT:
addPoint(t, f, r, g);
break;
case MULTIPOINT:
for (int i = 0, n = g.getNumGeometries(); i < n; i++)
addPoint(t, f, r, g.getGeometryN(i));
break;
case LINESTRING:
addLine(t, f, r, g);
break;
case MULTILINESTRING:
for (int i = 0, n = g.getNumGeometries(); i < n; i++)
addLine(t, f, r, g.getGeometryN(i));
break;
case POLYGON:
addPolygon(t, f, r, g);
break;
case MULTIPOLYGON:
for (int i = 0, n = g.getNumGeometries(); i < n; i++)
addPolygon(t, f, r, g.getGeometryN(i));
break;
default:
break;
}
}
} catch (IOException e) {
log.error("Error querying layer " + mDataset.name() + e);
}
}
protected void addLine(Task t, Feature f, Rule rule, Geometry g) {
protected void addLine(Task t, Feature f, Rule rule, Geometry g) {
if (((LineString) g).isClosed()) {
addPolygon(t, f, rule, g);
return;
}
if (((LineString) g).isClosed()) {
addPolygon(t, f, rule, g);
return;
}
LineBucket ll = t.buckets.getLineBucket(2);
if (ll.line == null) {
RGB color = rule.color(f, CartoCSS.LINE_COLOR, RGB.black);
float width = rule.number(f, CartoCSS.LINE_WIDTH, 1.2f);
ll.line = new LineStyle(0, JeoUtils.color(color), width);
ll.setDropDistance(0.5f);
}
LineBucket ll = t.buckets.getLineBucket(2);
if (ll.line == null) {
RGB color = rule.color(f, CartoCSS.LINE_COLOR, RGB.black);
float width = rule.number(f, CartoCSS.LINE_WIDTH, 1.2f);
ll.line = new LineStyle(0, JeoUtils.color(color), width);
ll.setDropDistance(0.5f);
}
addLine(t, g, ll);
}
addLine(t, g, ll);
}
protected void addPolygon(Task t, Feature f, Rule rule, Geometry g) {
protected void addPolygon(Task t, Feature f, Rule rule, Geometry g) {
LineBucket ll = t.buckets.getLineBucket(1);
LineBucket ll = t.buckets.getLineBucket(1);
if (ll.line == null) {
float width = rule.number(f, CartoCSS.LINE_WIDTH, 1.2f);
RGB color = rule.color(f, CartoCSS.LINE_COLOR, RGB.black);
ll.line = new LineStyle(0, JeoUtils.color(color), width);
ll.setDropDistance(0.5f);
}
if (ll.line == null) {
float width = rule.number(f, CartoCSS.LINE_WIDTH, 1.2f);
RGB color = rule.color(f, CartoCSS.LINE_COLOR, RGB.black);
ll.line = new LineStyle(0, JeoUtils.color(color), width);
ll.setDropDistance(0.5f);
}
MeshBucket mesh = t.buckets.getMeshBucket(0);
if (mesh.area == null) {
int color = JeoUtils.color(rule.color(f, CartoCSS.POLYGON_FILL, RGB.red));
mesh.area = new AreaStyle(color);
}
MeshBucket mesh = t.buckets.getMeshBucket(0);
if (mesh.area == null) {
int color = JeoUtils.color(rule.color(f, CartoCSS.POLYGON_FILL, RGB.red));
mesh.area = new AreaStyle(color);
}
addPolygon(t, g, mesh, ll);
}
addPolygon(t, g, mesh, ll);
}
protected void addPoint(Task t, Feature f, Rule rule, Geometry g) {
protected void addPoint(Task t, Feature f, Rule rule, Geometry g) {
}
}
}

View File

@@ -16,6 +16,10 @@
*/
package org.oscim.layers;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import org.jeo.geom.CoordinatePath;
import org.oscim.core.Box;
import org.oscim.core.GeometryBuffer;
@@ -29,92 +33,89 @@ import org.oscim.renderer.bucket.MeshBucket;
import org.oscim.utils.geom.SimplifyDP;
import org.oscim.utils.geom.SimplifyVW;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
public abstract class JtsLayer extends AbstractVectorLayer<Geometry> {
private double mMinX;
private double mMinY;
private double mMinX;
private double mMinY;
public JtsLayer(Map map) {
super(map);
}
public JtsLayer(Map map) {
super(map);
}
@Override
protected void processFeatures(Task t, Box bbox) {
processFeatures(t, new Envelope(bbox.xmin, bbox.ymin, bbox.xmax, bbox.ymax));
@Override
protected void processFeatures(Task t, Box bbox) {
processFeatures(t, new Envelope(bbox.xmin, bbox.ymin, bbox.xmax, bbox.ymax));
}
}
protected abstract void processFeatures(Task t, Envelope e);
protected abstract void processFeatures(Task t, Envelope e);
protected int transformPath(MapPosition pos, GeometryBuffer g, CoordinatePath path) {
protected int transformPath(MapPosition pos, GeometryBuffer g, CoordinatePath path) {
double scale = pos.scale * Tile.SIZE / UNSCALE_COORD;
int cnt = 0;
O: while (path.hasNext()) {
Coordinate c = path.next();
float x = (float) ((MercatorProjection.longitudeToX(c.x) - pos.x) * scale);
float y = (float) ((MercatorProjection.latitudeToY(c.y) - pos.y) * scale);
double scale = pos.scale * Tile.SIZE / UNSCALE_COORD;
int cnt = 0;
O:
while (path.hasNext()) {
Coordinate c = path.next();
float x = (float) ((MercatorProjection.longitudeToX(c.x) - pos.x) * scale);
float y = (float) ((MercatorProjection.latitudeToY(c.y) - pos.y) * scale);
switch (path.step()) {
case MOVE_TO:
if (g.isPoly())
g.startPolygon();
else if (g.isLine())
g.startLine();
switch (path.step()) {
case MOVE_TO:
if (g.isPoly())
g.startPolygon();
else if (g.isLine())
g.startLine();
cnt++;
g.addPoint(x, y);
break;
case LINE_TO:
cnt++;
g.addPoint(x, y);
break;
case CLOSE:
//g.addPoint(x, y);
//if (g.type == GeometryType.POLY)
break;
case STOP:
break O;
}
}
return cnt;
}
cnt++;
g.addPoint(x, y);
break;
case LINE_TO:
cnt++;
g.addPoint(x, y);
break;
case CLOSE:
//g.addPoint(x, y);
//if (g.type == GeometryType.POLY)
break;
case STOP:
break O;
}
}
return cnt;
}
SimplifyDP mSimpDP = new SimplifyDP();
SimplifyVW mSimpVW = new SimplifyVW();
SimplifyDP mSimpDP = new SimplifyDP();
SimplifyVW mSimpVW = new SimplifyVW();
protected void addPolygon(Task t, Geometry g, MeshBucket ml, LineBucket ll) {
mGeom.clear();
mGeom.startPolygon();
protected void addPolygon(Task t, Geometry g, MeshBucket ml, LineBucket ll) {
mGeom.clear();
mGeom.startPolygon();
CoordinatePath p = CoordinatePath.create(g);
if (mMinX > 0 || mMinY > 0)
p.generalize(mMinX, mMinY);
CoordinatePath p = CoordinatePath.create(g);
if (mMinX > 0 || mMinY > 0)
p.generalize(mMinX, mMinY);
if (transformPath(t.position, mGeom, p) < 3)
return;
if (transformPath(t.position, mGeom, p) < 3)
return;
if (!mClipper.clip(mGeom))
return;
if (!mClipper.clip(mGeom))
return;
mSimpVW.simplify(mGeom, 0.1f);
mSimpDP.simplify(mGeom, 0.5f);
mSimpVW.simplify(mGeom, 0.1f);
mSimpDP.simplify(mGeom, 0.5f);
ll.addLine(mGeom);
ml.addMesh(mGeom);
}
ll.addLine(mGeom);
ml.addMesh(mGeom);
}
protected void addLine(Task t, Geometry g, LineBucket ll) {
mGeom.clear();
mGeom.startLine();
protected void addLine(Task t, Geometry g, LineBucket ll) {
mGeom.clear();
mGeom.startLine();
CoordinatePath p = CoordinatePath.create(g);
transformPath(t.position, mGeom, p);
CoordinatePath p = CoordinatePath.create(g);
transformPath(t.position, mGeom, p);
ll.addLine(mGeom);
}
ll.addLine(mGeom);
}
}

View File

@@ -16,14 +16,16 @@
*/
package org.oscim.layers;
import java.util.HashMap;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import org.jeo.vector.VectorDataset;
import org.jeo.vector.Feature;
import org.jeo.map.CartoCSS;
import org.jeo.map.RGB;
import org.jeo.map.Rule;
import org.jeo.map.Style;
import org.jeo.vector.Feature;
import org.jeo.vector.VectorDataset;
import org.oscim.backend.canvas.Color;
import org.oscim.jeo.JeoUtils;
import org.oscim.map.Map;
@@ -35,132 +37,130 @@ import org.oscim.theme.styles.AreaStyle;
import org.oscim.theme.styles.LineStyle;
import org.oscim.theme.styles.TextStyle;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import java.util.HashMap;
public class OSMIndoorLayer extends JeoVectorLayer {
protected TextBucket mTextLayer;
protected TextStyle mText = TextStyle.builder()
.fontSize(16).color(Color.BLACK)
.strokeWidth(2.2f).strokeColor(Color.WHITE)
.build();
protected TextBucket mTextLayer;
protected TextStyle mText = TextStyle.builder()
.fontSize(16).color(Color.BLACK)
.strokeWidth(2.2f).strokeColor(Color.WHITE)
.build();
public OSMIndoorLayer(Map map, VectorDataset data, Style style) {
super(map, data, style);
}
public OSMIndoorLayer(Map map, VectorDataset data, Style style) {
super(map, data, style);
}
public boolean[] activeLevels = new boolean[10];
public boolean[] activeLevels = new boolean[10];
@Override
protected void processFeatures(Task t, Envelope b) {
mTextLayer = new TextBucket();
@Override
protected void processFeatures(Task t, Envelope b) {
mTextLayer = new TextBucket();
t.buckets.set(mTextLayer);
t.buckets.set(mTextLayer);
super.processFeatures(t, b);
super.processFeatures(t, b);
//render TextItems to a bitmap and prepare vertex buffer data.
mTextLayer.prepare();
mTextLayer.clearLabels();
}
//render TextItems to a bitmap and prepare vertex buffer data.
mTextLayer.prepare();
mTextLayer.clearLabels();
}
protected void addLine(Task t, Feature f, Rule rule, Geometry g) {
protected void addLine(Task t, Feature f, Rule rule, Geometry g) {
if (((LineString) g).isClosed()) {
addPolygon(t, f, rule, g);
return;
}
if (((LineString) g).isClosed()) {
addPolygon(t, f, rule, g);
return;
}
int level = getLevel(f);
int level = getLevel(f);
LineBucket ll = t.buckets.getLineBucket(level * 3 + 2);
if (ll.line == null) {
RGB color = rule.color(f, CartoCSS.LINE_COLOR, RGB.black);
float width = rule.number(f, CartoCSS.LINE_WIDTH, 1.2f);
ll.line = new LineStyle(0, JeoUtils.color(color), width);
ll.heightOffset = level * 4;
ll.setDropDistance(0);
}
LineBucket ll = t.buckets.getLineBucket(level * 3 + 2);
if (ll.line == null) {
RGB color = rule.color(f, CartoCSS.LINE_COLOR, RGB.black);
float width = rule.number(f, CartoCSS.LINE_WIDTH, 1.2f);
ll.line = new LineStyle(0, JeoUtils.color(color), width);
ll.heightOffset = level * 4;
ll.setDropDistance(0);
}
addLine(t, g, ll);
}
addLine(t, g, ll);
}
protected void addPolygon(Task t, Feature f, Rule rule, Geometry g) {
int level = getLevel(f);
protected void addPolygon(Task t, Feature f, Rule rule, Geometry g) {
int level = getLevel(f);
LineBucket ll = t.buckets.getLineBucket(level * 3 + 1);
LineBucket ll = t.buckets.getLineBucket(level * 3 + 1);
boolean active = activeLevels[level + 1];
boolean active = activeLevels[level + 1];
if (ll.line == null) {
float width = rule.number(f, CartoCSS.LINE_WIDTH, 1.2f);
int color = Color.rainbow((level + 1) / 10f);
if (ll.line == null) {
float width = rule.number(f, CartoCSS.LINE_WIDTH, 1.2f);
int color = Color.rainbow((level + 1) / 10f);
if (level > -2 && !active)
color = Color.fade(color, 0.1f);
if (level > -2 && !active)
color = Color.fade(color, 0.1f);
ll.line = new LineStyle(0, color, width);
ll.heightOffset = level * 4;
ll.setDropDistance(0);
}
ll.line = new LineStyle(0, color, width);
ll.heightOffset = level * 4;
ll.setDropDistance(0);
}
MeshBucket mesh = t.buckets.getMeshBucket(level * 3);
if (mesh.area == null) {
int color = JeoUtils.color(rule.color(f, CartoCSS.POLYGON_FILL, RGB.red));
if (level > -2 && !active)
color = Color.fade(color, 0.1f);
MeshBucket mesh = t.buckets.getMeshBucket(level * 3);
if (mesh.area == null) {
int color = JeoUtils.color(rule.color(f, CartoCSS.POLYGON_FILL, RGB.red));
if (level > -2 && !active)
color = Color.fade(color, 0.1f);
mesh.area = new AreaStyle(color);
//mesh.area = new Area(Color.fade(Color.DKGRAY, 0.1f));
mesh.heightOffset = level * 4f;
}
mesh.area = new AreaStyle(color);
//mesh.area = new Area(Color.fade(Color.DKGRAY, 0.1f));
mesh.heightOffset = level * 4f;
}
addPolygon(t, g, mesh, ll);
addPolygon(t, g, mesh, ll);
if (active) {
Object o = f.get("name");
if (o instanceof String) {
float x = 0;
float y = 0;
int n = mGeom.index[0];
for (int i = 0; i < n;) {
x += mGeom.points[i++];
y += mGeom.points[i++];
}
if (active) {
Object o = f.get("name");
if (o instanceof String) {
float x = 0;
float y = 0;
int n = mGeom.index[0];
for (int i = 0; i < n; ) {
x += mGeom.points[i++];
y += mGeom.points[i++];
}
TextItem ti = TextItem.pool.get();
ti.set(x / (n / 2) / 8, y / (n / 2) / 8, (String) o, mText);
TextItem ti = TextItem.pool.get();
ti.set(x / (n / 2) / 8, y / (n / 2) / 8, (String) o, mText);
mTextLayer.addText(ti);
}
}
}
mTextLayer.addText(ti);
}
}
}
@Override
protected void addPoint(Task t, Feature f, Rule rule, Geometry g) {
@Override
protected void addPoint(Task t, Feature f, Rule rule, Geometry g) {
}
}
private int getLevel(Feature f) {
/* not sure if one could match these geojson properties with cartocss */
Object o = f.get("@relations");
if (o instanceof HashMap) {
@SuppressWarnings("unchecked")
HashMap<String, Object> tags = (HashMap<String, Object>) o;
@SuppressWarnings("unchecked")
HashMap<String, Object> reltags = (HashMap<String, Object>) tags.get("reltags");
private int getLevel(Feature f) {
/* not sure if one could match these geojson properties with cartocss */
Object o = f.get("@relations");
if (o instanceof HashMap) {
@SuppressWarnings("unchecked")
HashMap<String, Object> tags = (HashMap<String, Object>) o;
@SuppressWarnings("unchecked")
HashMap<String, Object> reltags = (HashMap<String, Object>) tags.get("reltags");
if (reltags != null) {
o = reltags.get("level");
if (o instanceof String) {
//log.debug("got level {}", o);
return Integer.parseInt((String) o);
}
}
}
return 0;
}
if (reltags != null) {
o = reltags.get("level");
if (o instanceof String) {
//log.debug("got level {}", o);
return Integer.parseInt((String) o);
}
}
}
return 0;
}
}

View File

@@ -16,26 +16,22 @@
*/
package org.oscim.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import com.vividsolutions.jts.geom.Geometry;
import org.jeo.carto.Carto;
import org.jeo.data.Dataset;
import org.jeo.vector.VectorQuery;
import org.jeo.vector.VectorDataset;
import org.jeo.data.mem.MemVector;
import org.jeo.data.mem.MemWorkspace;
import org.jeo.vector.Feature;
import org.jeo.vector.Features;
import org.jeo.vector.Schema;
import org.jeo.vector.SchemaBuilder;
import org.jeo.geojson.GeoJSONDataset;
import org.jeo.geojson.GeoJSONReader;
import org.jeo.geom.GeomBuilder;
import org.jeo.map.Style;
import org.jeo.vector.Feature;
import org.jeo.vector.Features;
import org.jeo.vector.Schema;
import org.jeo.vector.SchemaBuilder;
import org.jeo.vector.VectorDataset;
import org.jeo.vector.VectorQuery;
import org.oscim.layers.OSMIndoorLayer;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
@@ -43,157 +39,161 @@ import org.oscim.map.Map;
import org.oscim.renderer.MapRenderer;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import com.vividsolutions.jts.geom.Geometry;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public class JeoTest {
public static void indoorSketch(Map map, String file) {
MapRenderer.setBackgroundColor(0xff909090);
VectorTileLayer baseLayer = map.setBaseMap(new OSciMap4TileSource());
map.layers().add(new BuildingLayer(map, baseLayer));
public static void indoorSketch(Map map, String file) {
MapRenderer.setBackgroundColor(0xff909090);
VectorTileLayer baseLayer = map.setBaseMap(new OSciMap4TileSource());
map.layers().add(new BuildingLayer(map, baseLayer));
VectorDataset data = null;
try {
data = JeoTest.readGeoJson(new FileInputStream(new File(file)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
VectorDataset data = null;
try {
data = JeoTest.readGeoJson(new FileInputStream(new File(file)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Style style = JeoTest.getStyle();
map.layers().add(new OSMIndoorLayer(map, data, style));
}
Style style = JeoTest.getStyle();
map.layers().add(new OSMIndoorLayer(map, data, style));
}
public static Style getStyle() {
Style style = null;
public static Style getStyle() {
Style style = null;
try {
style = Carto.parse("" +
"#way {" +
" line-width: 2;" +
" line-color: #c80;" +
" polygon-fill: #44111111;" +
" " +
"}" +
"#states {" +
" line-width: 2.2;" +
" line-color: #c80;" +
" polygon-fill: #44111111;" +
" " +
"}"
);
try {
style = Carto.parse("" +
"#way {" +
" line-width: 2;" +
" line-color: #c80;" +
" polygon-fill: #44111111;" +
" " +
"}" +
"#states {" +
" line-width: 2.2;" +
" line-color: #c80;" +
" polygon-fill: #44111111;" +
" " +
"}"
);
return style;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
return style;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static VectorDataset readGeoJson(InputStream is) {
GeoJSONReader r = new GeoJSONReader();
public static VectorDataset readGeoJson(InputStream is) {
GeoJSONReader r = new GeoJSONReader();
@SuppressWarnings("resource")
MemWorkspace mem = new MemWorkspace();
@SuppressWarnings("resource")
MemWorkspace mem = new MemWorkspace();
//mem.put("layer", data);
try {
Schema s = new SchemaBuilder("way").schema();
//mem.put("layer", data);
try {
Schema s = new SchemaBuilder("way").schema();
MemVector memData = mem.create(s);
MemVector memData = mem.create(s);
for (Feature f : r.features(is)) {
//System.out.println("loaded: " + f);
memData.add(f);
}
return memData;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
for (Feature f : r.features(is)) {
//System.out.println("loaded: " + f);
memData.add(f);
}
return memData;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static Dataset getJsonData(String file, boolean memory) {
GeoJSONDataset data = null;
public static Dataset getJsonData(String file, boolean memory) {
GeoJSONDataset data = null;
try {
data = new GeoJSONDataset(new File(file));
} catch (UnsupportedOperationException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
try {
data = new GeoJSONDataset(new File(file));
} catch (UnsupportedOperationException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
if (memory) {
@SuppressWarnings("resource")
MemWorkspace mem = new MemWorkspace();
if (memory) {
@SuppressWarnings("resource")
MemWorkspace mem = new MemWorkspace();
//mem.put("layer", data);
try {
//mem.put("layer", data);
try {
Schema s = data.schema();
VectorQuery q = new VectorQuery();
Schema s = data.schema();
VectorQuery q = new VectorQuery();
MemVector memData = mem.create(s);
MemVector memData = mem.create(s);
for (Feature f : data.cursor(q)) {
memData.add(f);
}
for (Feature f : data.cursor(q)) {
memData.add(f);
}
//return mem.get("layer");
return memData;
} catch (IOException e) {
e.printStackTrace();
}
}
return data;
}
//return mem.get("layer");
return memData;
} catch (IOException e) {
e.printStackTrace();
}
}
return data;
}
public static Dataset getMemWorkspace(String layer) {
GeomBuilder gb = new GeomBuilder(4326);
public static Dataset getMemWorkspace(String layer) {
GeomBuilder gb = new GeomBuilder(4326);
@SuppressWarnings("resource")
MemWorkspace mem = new MemWorkspace();
Schema schema = new SchemaBuilder(layer)
.field("geometry", Geometry.class)
.field("id", Integer.class)
.field("name", String.class)
.field("cost", Double.class).schema();
@SuppressWarnings("resource")
MemWorkspace mem = new MemWorkspace();
Schema schema = new SchemaBuilder(layer)
.field("geometry", Geometry.class)
.field("id", Integer.class)
.field("name", String.class)
.field("cost", Double.class).schema();
MemVector data;
try {
data = mem.create(schema);
} catch (UnsupportedOperationException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
MemVector data;
try {
data = mem.create(schema);
} catch (UnsupportedOperationException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
Geometry g = gb.point(0, 0).toPoint();
//g.setSRID(4326);
Geometry g = gb.point(0, 0).toPoint();
//g.setSRID(4326);
data.add(Features.create(null, data.schema(),
g, 1, "anvil",
10.99));
data.add(Features.create(null, data.schema(),
g, 1, "anvil",
10.99));
data.add(Features.create(null, data.schema(),
gb.points(10, 10, 20, 20).toLineString(),
2, "bomb", 11.99));
data.add(Features.create(null, data.schema(),
gb.points(10, 10, 20, 20).toLineString(),
2, "bomb", 11.99));
data.add(Features.create(null, data.schema(),
gb.point(100, 10).toPoint().buffer(10),
3, "dynamite", 12.99));
data.add(Features.create(null, data.schema(),
gb.point(100, 10).toPoint().buffer(10),
3, "dynamite", 12.99));
//Dataset jsonData = new GeoJSONDataset(new File("states.json"));
//mem.put("states", jsonData);
//Dataset jsonData = new GeoJSONDataset(new File("states.json"));
//mem.put("states", jsonData);
try {
return mem.get(layer);
} catch (IOException e) {
e.printStackTrace();
}
try {
return mem.get(layer);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
return null;
}
}

View File

@@ -16,75 +16,75 @@
*/
package org.oscim.theme.carto;
import static java.lang.System.out;
import java.util.List;
import java.util.Map;
import org.jeo.vector.BasicFeature;
import org.oscim.core.Tag;
import org.oscim.core.TagSet;
import java.util.List;
import java.util.Map;
import static java.lang.System.out;
//imitate Feature behaviour for tags and zoom-level
class MatcherFeature extends BasicFeature {
TagSet mTags;
Integer mZoom;
TagSet mTags;
Integer mZoom;
void setTags(TagSet tags) {
mTags = tags;
}
void setTags(TagSet tags) {
mTags = tags;
}
void setZoom(int zoom) {
mZoom = Integer.valueOf(zoom);
}
void setZoom(int zoom) {
mZoom = Integer.valueOf(zoom);
}
protected MatcherFeature() {
super("");
}
protected MatcherFeature() {
super("");
}
@Override
public Object get(String key) {
//out.println("get(" + key + ")");
@Override
public Object get(String key) {
//out.println("get(" + key + ")");
if (key.equals("zoom"))
return mZoom;
if (key.equals("zoom"))
return mZoom;
Tag t = mTags.get(key.intern());
if (t == null)
return null;
Tag t = mTags.get(key.intern());
if (t == null)
return null;
//out.println("value: " + t.value);
//out.println("value: " + t.value);
return t.value;
}
return t.value;
}
@Override
public BasicFeature put(String key, Object val) {
out.println("EEEK put()");
return null;
}
@Override
public BasicFeature put(String key, Object val) {
out.println("EEEK put()");
return null;
}
@Override
public List<Object> list() {
out.println("EEEK list()");
return null;
}
@Override
public List<Object> list() {
out.println("EEEK list()");
return null;
}
@Override
public Map<String, Object> map() {
out.println("EEEK map()");
return null;
}
@Override
public Map<String, Object> map() {
out.println("EEEK map()");
return null;
}
@Override
public Object get(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public Object get(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public BasicFeature set(int arg0, Object arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public BasicFeature set(int arg0, Object arg1) {
// TODO Auto-generated method stub
return null;
}
}

View File

@@ -1,13 +1,5 @@
package org.oscim.theme.carto;
import static java.lang.System.out;
import static org.jeo.map.CartoCSS.BACKGROUND_COLOR;
import static org.jeo.map.CartoCSS.OPACITY;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.jeo.carto.Carto;
import org.jeo.map.CartoCSS;
import org.jeo.map.RGB;
@@ -23,244 +15,252 @@ import org.oscim.theme.styles.AreaStyle;
import org.oscim.theme.styles.LineStyle;
import org.oscim.theme.styles.RenderStyle;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static java.lang.System.out;
import static org.jeo.map.CartoCSS.BACKGROUND_COLOR;
import static org.jeo.map.CartoCSS.OPACITY;
public class RenderTheme implements IRenderTheme {
final String STYLE = "" +
final String STYLE = "" +
"[building = 'yes'] {" +
" z: 1;" +
" polygon-fill: #eee;" +
" [zoom >= 16] {" +
" polygon-fill: #c00;" +
" }" +
"}" +
"[building = 'yes'] {" +
" z: 1;" +
" polygon-fill: #eee;" +
" [zoom >= 16] {" +
" polygon-fill: #c00;" +
" }" +
"}" +
"[admin_level = '2'] {" +
" line-color: #000;" +
" line-width: 1;" +
" z: 1;" +
"}" +
"[admin_level = '2'] {" +
" line-color: #000;" +
" line-width: 1;" +
" z: 1;" +
"}" +
"[admin_level = '2'] {" +
" line-color: #000;" +
" line-width: 1;" +
" z: 1;" +
"}" +
"[admin_level = '2'] {" +
" line-color: #000;" +
" line-width: 1;" +
" z: 1;" +
"}" +
"[admin_level = '4'] {" +
" line-color: #aaa;" +
" line-width: 1;" +
" z: 2;" +
"}" +
"[admin_level = '4'] {" +
" line-color: #aaa;" +
" line-width: 1;" +
" z: 2;" +
"}" +
"[highway = 'motorway'] {" +
" line-color: #a00;" +
" z: 10;" +
"}" +
"[highway = 'motorway'] {" +
" line-color: #a00;" +
" z: 10;" +
"}" +
"[highway = 'primary'] {" +
" line-color: #aa0;" +
" z: 11;" +
"}" +
"[highway = 'primary'] {" +
" line-color: #aa0;" +
" z: 11;" +
"}" +
"[highway = 'residential'],[highway = 'road'],[highway = 'secondary'] {" +
" line-color: #fff;" +
" z: 12;" +
"}" +
"[highway = 'residential'],[highway = 'road'],[highway = 'secondary'] {" +
" line-color: #fff;" +
" z: 12;" +
"}" +
" [landuse = 'forest'] {" +
" polygon-fill: #0a0;" +
" z: 2;" +
"}" +
" [landuse = 'forest'] {" +
" polygon-fill: #0a0;" +
" z: 2;" +
"}" +
"[natural = 'water'] {" +
" polygon-fill: #00a;" +
" z: 3;" +
"}";
"[natural = 'water'] {" +
" polygon-fill: #00a;" +
" z: 3;" +
"}";
private Style mStyle;
private RuleList mRules;
private Style mStyle;
private RuleList mRules;
MatcherFeature mMatchFeature = new MatcherFeature();
private int mBackground;
MatcherFeature mMatchFeature = new MatcherFeature();
private int mBackground;
public RenderTheme() {
public RenderTheme() {
try {
mStyle = loadStyle();
} catch (IOException e) {
e.printStackTrace();
}
try {
mStyle = loadStyle();
} catch (IOException e) {
e.printStackTrace();
}
// get map background
RuleList rules = mStyle.getRules().selectByName("Map", false, false);
if (!rules.isEmpty()) {
Rule rule = rules.collapse();
RGB bgColor = rule.color(null, BACKGROUND_COLOR, null);
if (bgColor != null) {
bgColor = bgColor.alpha(rule.number(null, OPACITY, 1f));
mBackground = color(bgColor);
}
}
// get map background
RuleList rules = mStyle.getRules().selectByName("Map", false, false);
if (!rules.isEmpty()) {
Rule rule = rules.collapse();
RGB bgColor = rule.color(null, BACKGROUND_COLOR, null);
if (bgColor != null) {
bgColor = bgColor.alpha(rule.number(null, OPACITY, 1f));
mBackground = color(bgColor);
}
}
mRules = mStyle.getRules();
mRules = mStyle.getRules();
//out.println(mRules);
//out.println();
if (mRules.get(1).equals(mRules.get(2)))
out.println("ok");
//out.println(mRules);
//out.println();
if (mRules.get(1).equals(mRules.get(2)))
out.println("ok");
for (Rule r : mRules)
out.println(formatRule(r, 0));
}
for (Rule r : mRules)
out.println(formatRule(r, 0));
}
class StyleSet {
int level;
RenderStyle[] ri = new RenderStyle[2];
}
class StyleSet {
int level;
RenderStyle[] ri = new RenderStyle[2];
}
Map<Rule, StyleSet> mStyleSets = new HashMap<Rule, StyleSet>();
int mCurLevel = 0;
Map<Rule, StyleSet> mStyleSets = new HashMap<Rule, StyleSet>();
int mCurLevel = 0;
public String formatRule(Rule r, int indent) {
StringBuilder sb = new StringBuilder();
public String formatRule(Rule r, int indent) {
StringBuilder sb = new StringBuilder();
String pad = "";
for (int i = 0; i < indent; i++)
pad += " ";
String pad = "";
for (int i = 0; i < indent; i++)
pad += " ";
sb.append(pad);
sb.append(pad);
if (sb.length() > 0)
sb.setLength(sb.length() - 1);
if (sb.length() > 0)
sb.setLength(sb.length() - 1);
sb.append(pad).append(" {").append("\n");
sb.append(pad).append(" {").append("\n");
StyleSet s = new StyleSet();
RGB l = null;
RGB p = null;
if (r.properties().containsKey(CartoCSS.LINE_COLOR)) {
l = r.color(null, CartoCSS.LINE_COLOR, RGB.black);
}
if (r.properties().containsKey(CartoCSS.POLYGON_FILL)) {
p = r.color(null, CartoCSS.POLYGON_FILL, RGB.black);
}
StyleSet s = new StyleSet();
RGB l = null;
RGB p = null;
if (r.properties().containsKey(CartoCSS.LINE_COLOR)) {
l = r.color(null, CartoCSS.LINE_COLOR, RGB.black);
}
if (r.properties().containsKey(CartoCSS.POLYGON_FILL)) {
p = r.color(null, CartoCSS.POLYGON_FILL, RGB.black);
}
if (p != null) {
s.ri[0] = new AreaStyle(mCurLevel++, color(p));
}
if (p != null) {
s.ri[0] = new AreaStyle(mCurLevel++, color(p));
}
if (l != null) {
s.ri[1] = new LineStyle(mCurLevel++, color(l), 1);
}
if (l != null) {
s.ri[1] = new LineStyle(mCurLevel++, color(l), 1);
}
if (p != null || l != null) {
mStyleSets.put(r, s);
out.println("put " + s.ri[0] + s.ri[1]);
}
if (p != null || l != null) {
mStyleSets.put(r, s);
out.println("put " + s.ri[0] + s.ri[1]);
}
for (Map.Entry<String, Object> e : r.properties().entrySet()) {
sb.append(pad).append(" ").append(e.getKey()).append(": ").append(e.getValue())
.append(";\n");
}
for (Map.Entry<String, Object> e : r.properties().entrySet()) {
sb.append(pad).append(" ").append(e.getKey()).append(": ").append(e.getValue())
.append(";\n");
}
for (Rule nested : r.nested()) {
sb.append(formatRule(nested, indent + 2)).append("\n");
}
for (Rule nested : r.nested()) {
sb.append(formatRule(nested, indent + 2)).append("\n");
}
sb.append(pad).append("}");
return sb.toString();
}
sb.append(pad).append("}");
return sb.toString();
}
Style loadStyle() throws IOException {
return Carto.parse(STYLE);
}
Style loadStyle() throws IOException {
return Carto.parse(STYLE);
}
@Override
public synchronized RenderStyle[] matchElement(GeometryType type, TagSet tags,
int zoomLevel) {
MatcherFeature f = mMatchFeature;
@Override
public synchronized RenderStyle[] matchElement(GeometryType type, TagSet tags,
int zoomLevel) {
MatcherFeature f = mMatchFeature;
f.setTags(tags);
f.setZoom(zoomLevel);
f.setTags(tags);
f.setZoom(zoomLevel);
RuleList rules = mRules.match(f);
RuleList rules = mRules.match(f);
Rule r = rules.collapse();
Rule r = rules.collapse();
//out.println(r);
if (rules.isEmpty())
return null;
//out.println(r);
if (rules.isEmpty())
return null;
int z = r.number(f, "z", 0f).intValue();
int z = r.number(f, "z", 0f).intValue();
if (type == GeometryType.POLY) {
RGB c = r.color(f, CartoCSS.POLYGON_FILL, RGB.black);
out.println(z + " " + c);
return new RenderStyle[] {
new AreaStyle(z, color(c))
};
if (type == GeometryType.POLY) {
RGB c = r.color(f, CartoCSS.POLYGON_FILL, RGB.black);
out.println(z + " " + c);
return new RenderStyle[]{
new AreaStyle(z, color(c))
};
} else if (type == GeometryType.LINE) {
RGB c = r.color(f, CartoCSS.LINE_COLOR, RGB.black);
float width = r.number(f, CartoCSS.LINE_WIDTH, 2f);
//out.println(z + " " + c);
} else if (type == GeometryType.LINE) {
RGB c = r.color(f, CartoCSS.LINE_COLOR, RGB.black);
float width = r.number(f, CartoCSS.LINE_WIDTH, 2f);
//out.println(z + " " + c);
return new RenderStyle[] {
new LineStyle(100 + z, color(c), width)
};
return new RenderStyle[]{
new LineStyle(100 + z, color(c), width)
};
} else if (type == GeometryType.POINT) {
//RGB c = r.color(f, CartoCSS.MARKER_FILL, RGB.black);
//out.println(c);
//return new RenderInstruction[] {
// new Caption(color(c), width)
//};
}
} else if (type == GeometryType.POINT) {
//RGB c = r.color(f, CartoCSS.MARKER_FILL, RGB.black);
//out.println(c);
//return new RenderInstruction[] {
// new Caption(color(c), width)
//};
}
return null;
}
return null;
}
public static int color(RGB rgb) {
return rgb.getAlpha() << 24
| rgb.getRed() << 16
| rgb.getGreen() << 8
| rgb.getBlue();
}
public static int color(RGB rgb) {
return rgb.getAlpha() << 24
| rgb.getRed() << 16
| rgb.getGreen() << 8
| rgb.getBlue();
}
@Override
public void dispose() {
}
@Override
public void dispose() {
}
@Override
public int getLevels() {
return 1;
}
@Override
public int getLevels() {
return 1;
}
@Override
public int getMapBackground() {
return mBackground;
}
@Override
public int getMapBackground() {
return mBackground;
}
@Override
public void scaleTextSize(float scaleFactor) {
}
@Override
public void scaleTextSize(float scaleFactor) {
}
public static void main(String[] args) {
RenderTheme t = new RenderTheme();
public static void main(String[] args) {
RenderTheme t = new RenderTheme();
MapElement e = new MapElement();
e.startPolygon();
e.tags.add(new Tag("building", "yes"));
MapElement e = new MapElement();
e.startPolygon();
e.tags.add(new Tag("building", "yes"));
t.matchElement(GeometryType.POLY, e.tags, 16);
t.matchElement(GeometryType.POLY, e.tags, 15);
}
t.matchElement(GeometryType.POLY, e.tags, 16);
t.matchElement(GeometryType.POLY, e.tags, 15);
}
@Override
public void updateStyles() {
// TODO Auto-generated method stub
@Override
public void updateStyles() {
// TODO Auto-generated method stub
}
}
}