Improve code / xml formatting, closes #54
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user