Line texture: JTS PathLayer support, #105
This commit is contained in:
@@ -20,23 +20,28 @@ package org.oscim.test;
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.GeoPoint;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.event.Event;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.PathLayer;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.layers.vector.PathLayer;
|
||||
import org.oscim.layers.vector.geometries.Style;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.bucket.TextureItem;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LineTexTest extends GdxMap {
|
||||
public class LineTexTest extends GdxMapApp {
|
||||
|
||||
TextureItem tex;
|
||||
private static final boolean ANIMATION = false;
|
||||
|
||||
private List<PathLayer> mPathLayers = new ArrayList<>();
|
||||
private TextureItem tex;
|
||||
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
public void createLayers() {
|
||||
BitmapTileLayer bitmapLayer = new BitmapTileLayer(mMap, DefaultSources.STAMEN_TONER.build());
|
||||
bitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
||||
mMap.setBaseMap(bitmapLayer);
|
||||
@@ -46,40 +51,22 @@ public class LineTexTest extends GdxMap {
|
||||
tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
|
||||
tex.mipmap = true;
|
||||
|
||||
// LineStyle style = LineStyle.builder()
|
||||
// .stippleColor(Color.BLACK)
|
||||
// .stipple(64)
|
||||
// .stippleWidth(1)
|
||||
// .strokeWidth(8)
|
||||
// .strokeColor(Color.RED)
|
||||
// .fixed(true)
|
||||
// .texture(tex)
|
||||
// .build();
|
||||
|
||||
//PathLayer pl = new PathLayer(mMap, style);
|
||||
//PathLayer pl = new PathLayer(mMap, Color.RED);
|
||||
|
||||
//pl.addGreatCircle(new GeoPoint(53.1, -85.), new GeoPoint(-40.0, 85.0));
|
||||
|
||||
//mMap.layers().add(pl);
|
||||
|
||||
createLayers(1, true);
|
||||
|
||||
/*mMap.events.bind(new Map.UpdateListener() {
|
||||
@Override
|
||||
public void onMapEvent(Event e, MapPosition mapPosition) {
|
||||
//if (e == Map.UPDATE_EVENT) {
|
||||
long t = System.currentTimeMillis();
|
||||
float pos = t % 20000 / 10000f - 1f;
|
||||
createLayers(pos, false);
|
||||
mMap.updateMap(true);
|
||||
//}
|
||||
}
|
||||
});*/
|
||||
if (ANIMATION)
|
||||
mMap.events.bind(new Map.UpdateListener() {
|
||||
@Override
|
||||
public void onMapEvent(Event e, MapPosition mapPosition) {
|
||||
//if (e == Map.UPDATE_EVENT) {
|
||||
long t = System.currentTimeMillis();
|
||||
float pos = t % 20000 / 10000f - 1f;
|
||||
createLayers(pos, false);
|
||||
mMap.updateMap(true);
|
||||
//}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ArrayList<PathLayer> mPathLayers = new ArrayList<>();
|
||||
|
||||
void createLayers(float pos, boolean init) {
|
||||
|
||||
int i = 0;
|
||||
@@ -89,11 +76,12 @@ public class LineTexTest extends GdxMap {
|
||||
|
||||
for (double lon = -180; lon <= 180; lon += 2) {
|
||||
//pts.add(new GeoPoint(lat, lon));
|
||||
double longitude = lon + (pos * 180);
|
||||
if (longitude < -180)
|
||||
longitude += 360;
|
||||
if (longitude > 180)
|
||||
longitude -= 360;
|
||||
// double longitude = lon + (pos * 180);
|
||||
// if (longitude < -180)
|
||||
// longitude += 360;
|
||||
// if (longitude > 180)
|
||||
// longitude -= 360;
|
||||
double longitude = lon;
|
||||
|
||||
double latitude = lat + (pos * 90);
|
||||
if (latitude < -90)
|
||||
@@ -107,9 +95,8 @@ public class LineTexTest extends GdxMap {
|
||||
}
|
||||
PathLayer pathLayer;
|
||||
if (init) {
|
||||
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.9f);
|
||||
|
||||
LineStyle style = LineStyle.builder()
|
||||
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);
|
||||
Style style = Style.builder()
|
||||
.stippleColor(c)
|
||||
.stipple(24)
|
||||
.stippleWidth(1)
|
||||
@@ -118,9 +105,7 @@ public class LineTexTest extends GdxMap {
|
||||
.fixed(true)
|
||||
.texture(tex)
|
||||
.build();
|
||||
|
||||
pathLayer = new PathLayer(mMap, style);
|
||||
|
||||
mMap.layers().add(pathLayer);
|
||||
mPathLayers.add(pathLayer);
|
||||
} else {
|
||||
@@ -132,71 +117,8 @@ public class LineTexTest extends GdxMap {
|
||||
|
||||
}
|
||||
|
||||
// mMap.layers().add(new GenericLayer(mMap, new BucketRenderer() {
|
||||
// boolean init;
|
||||
//
|
||||
// GeometryBuffer g = new GeometryBuffer(10, 1);
|
||||
//
|
||||
// LineBucket lb = buckets.addLineBucket(0,
|
||||
// new LineStyle(Color.fade(Color.CYAN, 0.5f), 2.5f));
|
||||
//
|
||||
// LineTexBucket ll;
|
||||
//
|
||||
// @Override
|
||||
// public boolean setup() {
|
||||
//
|
||||
// //lb.next = ll;
|
||||
// ll = buckets.getLineTexBucket(1);
|
||||
//
|
||||
// TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("patterns/dot.png"));
|
||||
// tex.mipmap = true;
|
||||
//
|
||||
// ll.line = LineStyle.builder()
|
||||
// .stippleColor(Color.BLACK)
|
||||
// .stipple(16)
|
||||
// .stippleWidth(1)
|
||||
// .strokeWidth(8)
|
||||
// .strokeColor(Color.RED)
|
||||
// .fixed(true)
|
||||
// .texture(tex)
|
||||
// .build();
|
||||
//
|
||||
// //ll.width = 8;
|
||||
//
|
||||
// return super.setup();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void update(GLViewport v) {
|
||||
// if (!init) {
|
||||
// mMapPosition.copy(v.pos);
|
||||
// init = true;
|
||||
// }
|
||||
//
|
||||
// buckets.clear();
|
||||
// buckets.set(lb);
|
||||
//GeometryBuffer.makeCircle(g, 0, 0, 600, 40);
|
||||
//
|
||||
// // g.clear();
|
||||
// // g.startLine();
|
||||
// // g.addPoint(-1, 0);
|
||||
// // g.addPoint(1, 0);
|
||||
// // g.addPoint(1, -1);
|
||||
// // g.addPoint(-1, -1);
|
||||
// // g.scale(100, 100);
|
||||
//
|
||||
// for (int i = 0; i < 15; i++) {
|
||||
// lb.addLine(g);
|
||||
// ll.addLine(g);
|
||||
// g.scale(0.8f, 0.8f);
|
||||
// }
|
||||
// compile();
|
||||
//
|
||||
// }
|
||||
// }));
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new LineTexTest(), null, 256);
|
||||
GdxMapApp.run(new LineTexTest(), null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,19 +19,22 @@ package org.oscim.test;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.TileGridLayer;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.layers.vector.VectorLayer;
|
||||
import org.oscim.layers.vector.geometries.PointDrawable;
|
||||
import org.oscim.layers.vector.geometries.Style;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||
import org.oscim.utils.ColorUtil;
|
||||
|
||||
public class VectorLayerTest extends GdxMapApp {
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
mMap.setBaseMap(new OSciMap4TileSource());
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
BitmapTileLayer bitmapLayer = new BitmapTileLayer(mMap, DefaultSources.STAMEN_TONER.build());
|
||||
bitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
||||
mMap.setBaseMap(bitmapLayer);
|
||||
|
||||
mMap.setMapPosition(0, 0, 1 << 2);
|
||||
|
||||
VectorLayer vectorLayer = new VectorLayer(mMap);
|
||||
|
||||
@@ -53,7 +56,7 @@ public class VectorLayerTest extends GdxMapApp {
|
||||
Style.Builder sb = Style.builder()
|
||||
.buffer(0.4)
|
||||
.fillColor(Color.RED)
|
||||
.fillAlpha(0.2);
|
||||
.fillAlpha(0.2f);
|
||||
|
||||
// int tileSize = 5;
|
||||
// for (int x = -180; x < 200; x += tileSize) {
|
||||
@@ -72,7 +75,7 @@ public class VectorLayerTest extends GdxMapApp {
|
||||
Style style = sb.buffer(Math.random() * 1)
|
||||
.fillColor(ColorUtil.setHue(Color.RED,
|
||||
Math.random()))
|
||||
.fillAlpha(0.5)
|
||||
.fillAlpha(0.5f)
|
||||
.build();
|
||||
|
||||
vectorLayer.add(new PointDrawable(Math.random() * 180 - 90,
|
||||
@@ -80,11 +83,10 @@ public class VectorLayerTest extends GdxMapApp {
|
||||
style));
|
||||
|
||||
}
|
||||
vectorLayer.update();
|
||||
|
||||
mMap.layers().add(vectorLayer);
|
||||
mMap.layers().add(new TileGridLayer(mMap, 0xff222222, 1.2f, 1));
|
||||
|
||||
mMap.setMapPosition(0, 0, 1 << 2);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Reference in New Issue
Block a user