Line texture: JTS PathLayer support, #105
This commit is contained in:
@@ -18,14 +18,15 @@
|
|||||||
package org.oscim.android.test;
|
package org.oscim.android.test;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
|
||||||
|
|
||||||
import org.oscim.backend.CanvasAdapter;
|
import org.oscim.backend.CanvasAdapter;
|
||||||
import org.oscim.backend.canvas.Color;
|
import org.oscim.backend.canvas.Color;
|
||||||
import org.oscim.core.GeoPoint;
|
import org.oscim.core.MapPosition;
|
||||||
import org.oscim.layers.PathLayer;
|
import org.oscim.event.Event;
|
||||||
|
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.renderer.bucket.TextureItem;
|
||||||
import org.oscim.theme.styles.LineStyle;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -38,23 +39,52 @@ import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
|
|||||||
*/
|
*/
|
||||||
public class LineTexActivity extends BitmapTileMapActivity {
|
public class LineTexActivity extends BitmapTileMapActivity {
|
||||||
|
|
||||||
|
private static final boolean ANIMATION = false;
|
||||||
|
|
||||||
|
private List<PathLayer> mPathLayers = new ArrayList<>();
|
||||||
|
|
||||||
public LineTexActivity() {
|
public LineTexActivity() {
|
||||||
super(STAMEN_TONER.build());
|
super(STAMEN_TONER.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureItem tex;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mBitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
mBitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
||||||
|
|
||||||
tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
|
TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
|
||||||
tex.mipmap = true;
|
tex.mipmap = true;
|
||||||
|
|
||||||
createLayers(1, true);
|
for (double lat = -90; lat <= 90; lat += 5) {
|
||||||
|
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);
|
||||||
|
Style style = Style.builder()
|
||||||
|
.stippleColor(c)
|
||||||
|
.stipple(24)
|
||||||
|
.stippleWidth(1)
|
||||||
|
.strokeWidth(12)
|
||||||
|
.strokeColor(c)
|
||||||
|
.fixed(true)
|
||||||
|
.texture(tex)
|
||||||
|
.build();
|
||||||
|
PathLayer pathLayer = new PathLayer(mMap, style);
|
||||||
|
mMap.layers().add(pathLayer);
|
||||||
|
mPathLayers.add(pathLayer);
|
||||||
|
}
|
||||||
|
|
||||||
//looooop();
|
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);
|
||||||
|
mMap.updateMap(true);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
else
|
||||||
|
createLayers(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,40 +95,16 @@ public class LineTexActivity extends BitmapTileMapActivity {
|
|||||||
mMap.setMapPosition(0, 0, 1 << 2);
|
mMap.setMapPosition(0, 0, 1 << 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void looooop() {
|
void createLayers(float pos) {
|
||||||
mMap.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
long t = SystemClock.uptimeMillis();
|
|
||||||
float pos = t % 20000 / 10000f - 1f;
|
|
||||||
createLayers(pos, false);
|
|
||||||
//Samples.log.debug("update took" + (SystemClock.uptimeMillis() - t) + " " + pos);
|
|
||||||
looooop();
|
|
||||||
redraw();
|
|
||||||
}
|
|
||||||
}, 50);
|
|
||||||
}
|
|
||||||
|
|
||||||
void redraw() {
|
|
||||||
mMap.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<PathLayer> mPathLayers = new ArrayList<>();
|
|
||||||
|
|
||||||
void createLayers(float pos, boolean init) {
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (double lat = -90; lat <= 90; lat += 5) {
|
for (double lat = -90; lat <= 90; lat += 5) {
|
||||||
List<GeoPoint> pts = new ArrayList<>();
|
double[] packedCoordinates = new double[360 + 2];
|
||||||
|
//List<GeoPoint> pts = new ArrayList<>();
|
||||||
|
int c = 0;
|
||||||
for (double lon = -180; lon <= 180; lon += 2) {
|
for (double lon = -180; lon <= 180; lon += 2) {
|
||||||
//pts.add(new GeoPoint(lat, lon));
|
//pts.add(new GeoPoint(lat, lon));
|
||||||
double longitude = lon + (pos * 180);
|
double longitude = lon;
|
||||||
if (longitude < -180)
|
|
||||||
longitude += 360;
|
|
||||||
if (longitude > 180)
|
|
||||||
longitude -= 360;
|
|
||||||
|
|
||||||
double latitude = lat + (pos * 90);
|
double latitude = lat + (pos * 90);
|
||||||
if (latitude < -90)
|
if (latitude < -90)
|
||||||
@@ -108,32 +114,15 @@ public class LineTexActivity extends BitmapTileMapActivity {
|
|||||||
|
|
||||||
latitude += Math.sin((Math.abs(pos) * (lon / Math.PI)));
|
latitude += Math.sin((Math.abs(pos) * (lon / Math.PI)));
|
||||||
|
|
||||||
pts.add(new GeoPoint(latitude, longitude));
|
packedCoordinates[c++] = longitude;
|
||||||
}
|
packedCoordinates[c++] = latitude;
|
||||||
PathLayer pathLayer;
|
|
||||||
if (init) {
|
|
||||||
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.9f);
|
|
||||||
|
|
||||||
LineStyle style = LineStyle.builder()
|
|
||||||
.stippleColor(c)
|
|
||||||
.stipple(24)
|
|
||||||
.stippleWidth(1)
|
|
||||||
.strokeWidth(12)
|
|
||||||
.strokeColor(c)
|
|
||||||
.fixed(true)
|
|
||||||
.texture(tex)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
pathLayer = new PathLayer(mMap, style);
|
|
||||||
|
|
||||||
mMap.layers().add(pathLayer);
|
|
||||||
mPathLayers.add(pathLayer);
|
|
||||||
} else {
|
|
||||||
pathLayer = mPathLayers.get(i++);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pathLayer.setPoints(pts);
|
//LineString line = new LineString(factory.create(packedCoordinates, 2), geomFactory);
|
||||||
|
//mPathLayers.get(i++).setLineString(line);
|
||||||
|
|
||||||
|
mPathLayers.get(i++).setLineString(packedCoordinates);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,16 +24,20 @@ import org.oscim.layers.TileGridLayer;
|
|||||||
import org.oscim.layers.vector.VectorLayer;
|
import org.oscim.layers.vector.VectorLayer;
|
||||||
import org.oscim.layers.vector.geometries.PointDrawable;
|
import org.oscim.layers.vector.geometries.PointDrawable;
|
||||||
import org.oscim.layers.vector.geometries.Style;
|
import org.oscim.layers.vector.geometries.Style;
|
||||||
import org.oscim.theme.VtmThemes;
|
|
||||||
import org.oscim.utils.ColorUtil;
|
import org.oscim.utils.ColorUtil;
|
||||||
|
|
||||||
public class VectorLayerMapActivity extends BaseMapActivity {
|
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
|
||||||
|
|
||||||
|
public class VectorLayerMapActivity extends BitmapTileMapActivity {
|
||||||
|
|
||||||
|
public VectorLayerMapActivity() {
|
||||||
|
super(STAMEN_TONER.build());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
mBitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
||||||
mMap.setTheme(VtmThemes.DEFAULT);
|
|
||||||
|
|
||||||
VectorLayer vectorLayer = new VectorLayer(mMap);
|
VectorLayer vectorLayer = new VectorLayer(mMap);
|
||||||
|
|
||||||
@@ -74,13 +78,13 @@ public class VectorLayerMapActivity extends BaseMapActivity {
|
|||||||
Style.Builder sb = Style.builder()
|
Style.Builder sb = Style.builder()
|
||||||
.buffer(0.5)
|
.buffer(0.5)
|
||||||
.fillColor(Color.RED)
|
.fillColor(Color.RED)
|
||||||
.fillAlpha(0.2);
|
.fillAlpha(0.2f);
|
||||||
|
|
||||||
for (int i = 0; i < 2000; i++) {
|
for (int i = 0; i < 2000; i++) {
|
||||||
Style style = sb.buffer(Math.random() + 0.2)
|
Style style = sb.buffer(Math.random() + 0.2)
|
||||||
.fillColor(ColorUtil.setHue(Color.RED,
|
.fillColor(ColorUtil.setHue(Color.RED,
|
||||||
(int) (Math.random() * 50) / 50.0))
|
(int) (Math.random() * 50) / 50.0))
|
||||||
.fillAlpha(0.5)
|
.fillAlpha(0.5f)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
vectorLayer.add(new PointDrawable(Math.random() * 180 - 90,
|
vectorLayer.add(new PointDrawable(Math.random() * 180 - 90,
|
||||||
@@ -88,10 +92,17 @@ public class VectorLayerMapActivity extends BaseMapActivity {
|
|||||||
style));
|
style));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
vectorLayer.update();
|
||||||
|
|
||||||
mMap.layers().add(vectorLayer);
|
mMap.layers().add(vectorLayer);
|
||||||
mMap.layers().add(new TileGridLayer(mMap, 0xff222222, 1.2f, 1));
|
mMap.layers().add(new TileGridLayer(mMap, 0xff222222, 1.2f, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
/* ignore saved position */
|
||||||
mMap.setMapPosition(0, 0, 1 << 2);
|
mMap.setMapPosition(0, 0, 1 << 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class draws a path line in given color.
|
* This class draws a path line in given color or texture.
|
||||||
*/
|
*/
|
||||||
public class PathLayer extends VectorLayer {
|
public class PathLayer extends VectorLayer {
|
||||||
|
|
||||||
@@ -136,8 +136,7 @@ public class PathLayer extends VectorLayer {
|
|||||||
public void addGreatCircle(GeoPoint startPoint, GeoPoint endPoint,
|
public void addGreatCircle(GeoPoint startPoint, GeoPoint endPoint,
|
||||||
final int numberOfPoints) {
|
final int numberOfPoints) {
|
||||||
/* adapted from page
|
/* adapted from page
|
||||||
* http://compastic.blogspot.co.uk/2011/07/how-to-draw-great-circle-on-map
|
* http://compastic.blogspot.co.uk/2011/07/how-to-draw-great-circle-on-map-in.html
|
||||||
* -in.html
|
|
||||||
* which was adapted from page http://maps.forum.nu/gm_flight_path.html */
|
* which was adapted from page http://maps.forum.nu/gm_flight_path.html */
|
||||||
|
|
||||||
GeomBuilder gb = new GeomBuilder();
|
GeomBuilder gb = new GeomBuilder();
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 devemux86
|
||||||
|
*
|
||||||
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
|
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package org.oscim.layers.vector;
|
package org.oscim.layers.vector;
|
||||||
|
|
||||||
import com.vividsolutions.jts.geom.Envelope;
|
import com.vividsolutions.jts.geom.Envelope;
|
||||||
@@ -234,9 +250,26 @@ public class VectorLayer extends AbstractVectorLayer<Drawable> {
|
|||||||
|
|
||||||
protected void drawLine(Task t, int level, Geometry line, Style style) {
|
protected void drawLine(Task t, int level, Geometry line, Style style) {
|
||||||
|
|
||||||
LineBucket ll = t.buckets.getLineBucket(level);
|
LineBucket ll;
|
||||||
|
if (style.stipple == 0 && style.texture == null)
|
||||||
|
ll = t.buckets.getLineBucket(level);
|
||||||
|
else
|
||||||
|
ll = t.buckets.getLineTexBucket(level);
|
||||||
if (ll.line == null) {
|
if (ll.line == null) {
|
||||||
ll.line = new LineStyle(0, style.strokeColor, style.strokeWidth);
|
if (style.stipple == 0 && style.texture == null)
|
||||||
|
ll.line = new LineStyle(style.strokeColor, style.strokeWidth, style.cap);
|
||||||
|
else
|
||||||
|
ll.line = LineStyle.builder()
|
||||||
|
.cap(style.cap)
|
||||||
|
.color(style.strokeColor)
|
||||||
|
.fixed(style.fixed)
|
||||||
|
.level(0)
|
||||||
|
.stipple(style.stipple)
|
||||||
|
.stippleColor(style.stippleColor)
|
||||||
|
.stippleWidth(style.stippleWidth)
|
||||||
|
.strokeWidth(style.strokeWidth)
|
||||||
|
.texture(style.texture)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style.generalization != Style.GENERALIZATION_NONE) {
|
if (style.generalization != Style.GENERALIZATION_NONE) {
|
||||||
|
|||||||
@@ -1,6 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 devemux86
|
||||||
|
*
|
||||||
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
|
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License along with
|
||||||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package org.oscim.layers.vector.geometries;
|
package org.oscim.layers.vector.geometries;
|
||||||
|
|
||||||
import org.oscim.backend.canvas.Color;
|
import org.oscim.backend.canvas.Color;
|
||||||
|
import org.oscim.backend.canvas.Paint;
|
||||||
|
import org.oscim.renderer.bucket.TextureItem;
|
||||||
|
|
||||||
|
import static org.oscim.backend.canvas.Color.parseColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class encapsulating style information for drawing geometries on the map.
|
* Class encapsulating style information for drawing geometries on the map.
|
||||||
@@ -23,6 +43,13 @@ public class Style {
|
|||||||
|
|
||||||
public final int generalization;
|
public final int generalization;
|
||||||
|
|
||||||
|
public final Paint.Cap cap;
|
||||||
|
public final boolean fixed;
|
||||||
|
public final int stipple;
|
||||||
|
public final int stippleColor;
|
||||||
|
public final float stippleWidth;
|
||||||
|
public final TextureItem texture;
|
||||||
|
|
||||||
private Style(Builder builder) {
|
private Style(Builder builder) {
|
||||||
strokeWidth = builder.strokeWidth;
|
strokeWidth = builder.strokeWidth;
|
||||||
strokeColor = builder.strokeColor;
|
strokeColor = builder.strokeColor;
|
||||||
@@ -34,6 +61,13 @@ public class Style {
|
|||||||
scalingZoomLevel = builder.scalingZoomLevel;
|
scalingZoomLevel = builder.scalingZoomLevel;
|
||||||
|
|
||||||
generalization = builder.generalization;
|
generalization = builder.generalization;
|
||||||
|
|
||||||
|
cap = builder.cap;
|
||||||
|
fixed = builder.fixed;
|
||||||
|
stipple = builder.stipple;
|
||||||
|
stippleColor = builder.stippleColor;
|
||||||
|
stippleWidth = builder.stippleWidth;
|
||||||
|
texture = builder.texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,14 +92,18 @@ public class Style {
|
|||||||
|
|
||||||
private int generalization = GENERALIZATION_NONE;
|
private int generalization = GENERALIZATION_NONE;
|
||||||
|
|
||||||
protected Builder() {
|
public Paint.Cap cap = Paint.Cap.ROUND;
|
||||||
|
public boolean fixed = false;
|
||||||
|
public int stipple = 0;
|
||||||
|
public int stippleColor = Color.GRAY;
|
||||||
|
public float stippleWidth = 1;
|
||||||
|
public TextureItem texture = null;
|
||||||
|
|
||||||
|
protected Builder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the GeometryStyle from the specified parameters.
|
* Builds the GeometryStyle from the specified parameters.
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public Style build() {
|
public Style build() {
|
||||||
return new Style(this);
|
return new Style(this);
|
||||||
@@ -73,9 +111,6 @@ public class Style {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the line width for the geometry's line or outline.
|
* Sets the line width for the geometry's line or outline.
|
||||||
*
|
|
||||||
* @param lineWidth
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public Builder strokeWidth(float lineWidth) {
|
public Builder strokeWidth(float lineWidth) {
|
||||||
this.strokeWidth = lineWidth;
|
this.strokeWidth = lineWidth;
|
||||||
@@ -84,20 +119,22 @@ public class Style {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the color for the geometry's line or outline.
|
* Sets the color for the geometry's line or outline.
|
||||||
*
|
|
||||||
* @param stokeColor
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public Builder strokeColor(int stokeColor) {
|
public Builder strokeColor(int strokeColor) {
|
||||||
this.strokeColor = stokeColor;
|
this.strokeColor = strokeColor;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the color for the geometry's line or outline.
|
||||||
|
*/
|
||||||
|
public Builder strokeColor(String strokeColor) {
|
||||||
|
this.strokeColor = parseColor(strokeColor);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the color for the geometry's area.
|
* Sets the color for the geometry's area.
|
||||||
*
|
|
||||||
* @param fillColor
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public Builder fillColor(int fillColor) {
|
public Builder fillColor(int fillColor) {
|
||||||
this.fillColor = fillColor;
|
this.fillColor = fillColor;
|
||||||
@@ -105,13 +142,18 @@ public class Style {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets alpha channel value for the geometry's area.
|
* Sets the color for the geometry's area.
|
||||||
*
|
|
||||||
* @param fillAlpha
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public Builder fillAlpha(double fillAlpha) {
|
public Builder fillColor(String fillColor) {
|
||||||
this.fillAlpha = (float) fillAlpha;
|
this.fillColor = parseColor(fillColor);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets alpha channel value for the geometry's area.
|
||||||
|
*/
|
||||||
|
public Builder fillAlpha(float fillAlpha) {
|
||||||
|
this.fillAlpha = fillAlpha;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,9 +161,6 @@ public class Style {
|
|||||||
* This function has effect only on Points:
|
* This function has effect only on Points:
|
||||||
* use it to control the size on the circle that
|
* use it to control the size on the circle that
|
||||||
* will be built from a buffer around the point.
|
* will be built from a buffer around the point.
|
||||||
*
|
|
||||||
* @param buffer
|
|
||||||
* @return itself
|
|
||||||
*/
|
*/
|
||||||
public Builder buffer(double buffer) {
|
public Builder buffer(double buffer) {
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
@@ -132,8 +171,6 @@ public class Style {
|
|||||||
* This function has effect only on Points:
|
* This function has effect only on Points:
|
||||||
* use it to specify from which zoom level the point
|
* use it to specify from which zoom level the point
|
||||||
* should stop decreasing in size and "stick to the map".
|
* should stop decreasing in size and "stick to the map".
|
||||||
*
|
|
||||||
* @param zoomlvl
|
|
||||||
*/
|
*/
|
||||||
public Builder scaleZoomLevel(int zoomlvl) {
|
public Builder scaleZoomLevel(int zoomlvl) {
|
||||||
this.scalingZoomLevel = zoomlvl;
|
this.scalingZoomLevel = zoomlvl;
|
||||||
@@ -144,42 +181,46 @@ public class Style {
|
|||||||
* Sets generalization factor for the geometry.
|
* Sets generalization factor for the geometry.
|
||||||
* Use predefined GeometryStyle.GENERALIZATION_HIGH,
|
* Use predefined GeometryStyle.GENERALIZATION_HIGH,
|
||||||
* GENERALIZATION_MEDIUM or GENERALIZATION_SMALL
|
* GENERALIZATION_MEDIUM or GENERALIZATION_SMALL
|
||||||
*
|
|
||||||
* @param generalization
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public Builder generalization(int generalization) {
|
public Builder generalization(int generalization) {
|
||||||
this.generalization = generalization;
|
this.generalization = generalization;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public float getStrokeWidth() {
|
public Builder cap(Paint.Cap cap) {
|
||||||
return strokeWidth;
|
this.cap = cap;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStrokeColor() {
|
public Builder fixed(boolean b) {
|
||||||
return strokeColor;
|
this.fixed = b;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public int getFillColor() {
|
public Builder stipple(int width) {
|
||||||
return fillColor;
|
this.stipple = width;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public float getFillAlpha() {
|
public Builder stippleColor(int color) {
|
||||||
return fillAlpha;
|
this.stippleColor = color;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public int getGeneralization() {
|
public Builder stippleColor(String color) {
|
||||||
return generalization;
|
this.stippleColor = parseColor(color);
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public double getBuffer() {
|
public Builder stippleWidth(float width) {
|
||||||
return buffer;
|
this.stippleWidth = width;
|
||||||
}
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public int getScalingZoomLevel() {
|
public Builder texture(TextureItem texture) {
|
||||||
return scalingZoomLevel;
|
this.texture = texture;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static final Style DEFAULT_STYLE = new Builder()
|
static final Style DEFAULT_STYLE = new Builder()
|
||||||
@@ -194,5 +235,4 @@ public class Style {
|
|||||||
public static Style.Builder builder() {
|
public static Style.Builder builder() {
|
||||||
return new Style.Builder();
|
return new Style.Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,23 +20,28 @@ package org.oscim.test;
|
|||||||
import org.oscim.backend.CanvasAdapter;
|
import org.oscim.backend.CanvasAdapter;
|
||||||
import org.oscim.backend.canvas.Color;
|
import org.oscim.backend.canvas.Color;
|
||||||
import org.oscim.core.GeoPoint;
|
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.gdx.GdxMapApp;
|
||||||
import org.oscim.layers.PathLayer;
|
|
||||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
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.renderer.bucket.TextureItem;
|
||||||
import org.oscim.theme.styles.LineStyle;
|
|
||||||
import org.oscim.tiling.source.bitmap.DefaultSources;
|
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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
|
@Override
|
||||||
protected void createLayers() {
|
public void createLayers() {
|
||||||
BitmapTileLayer bitmapLayer = new BitmapTileLayer(mMap, DefaultSources.STAMEN_TONER.build());
|
BitmapTileLayer bitmapLayer = new BitmapTileLayer(mMap, DefaultSources.STAMEN_TONER.build());
|
||||||
bitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
bitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
||||||
mMap.setBaseMap(bitmapLayer);
|
mMap.setBaseMap(bitmapLayer);
|
||||||
@@ -46,40 +51,22 @@ public class LineTexTest extends GdxMap {
|
|||||||
tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
|
tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
|
||||||
tex.mipmap = true;
|
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);
|
createLayers(1, true);
|
||||||
|
|
||||||
/*mMap.events.bind(new Map.UpdateListener() {
|
if (ANIMATION)
|
||||||
@Override
|
mMap.events.bind(new Map.UpdateListener() {
|
||||||
public void onMapEvent(Event e, MapPosition mapPosition) {
|
@Override
|
||||||
//if (e == Map.UPDATE_EVENT) {
|
public void onMapEvent(Event e, MapPosition mapPosition) {
|
||||||
long t = System.currentTimeMillis();
|
//if (e == Map.UPDATE_EVENT) {
|
||||||
float pos = t % 20000 / 10000f - 1f;
|
long t = System.currentTimeMillis();
|
||||||
createLayers(pos, false);
|
float pos = t % 20000 / 10000f - 1f;
|
||||||
mMap.updateMap(true);
|
createLayers(pos, false);
|
||||||
//}
|
mMap.updateMap(true);
|
||||||
}
|
//}
|
||||||
});*/
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<PathLayer> mPathLayers = new ArrayList<>();
|
|
||||||
|
|
||||||
void createLayers(float pos, boolean init) {
|
void createLayers(float pos, boolean init) {
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -89,11 +76,12 @@ public class LineTexTest extends GdxMap {
|
|||||||
|
|
||||||
for (double lon = -180; lon <= 180; lon += 2) {
|
for (double lon = -180; lon <= 180; lon += 2) {
|
||||||
//pts.add(new GeoPoint(lat, lon));
|
//pts.add(new GeoPoint(lat, lon));
|
||||||
double longitude = lon + (pos * 180);
|
// double longitude = lon + (pos * 180);
|
||||||
if (longitude < -180)
|
// if (longitude < -180)
|
||||||
longitude += 360;
|
// longitude += 360;
|
||||||
if (longitude > 180)
|
// if (longitude > 180)
|
||||||
longitude -= 360;
|
// longitude -= 360;
|
||||||
|
double longitude = lon;
|
||||||
|
|
||||||
double latitude = lat + (pos * 90);
|
double latitude = lat + (pos * 90);
|
||||||
if (latitude < -90)
|
if (latitude < -90)
|
||||||
@@ -107,9 +95,8 @@ public class LineTexTest extends GdxMap {
|
|||||||
}
|
}
|
||||||
PathLayer pathLayer;
|
PathLayer pathLayer;
|
||||||
if (init) {
|
if (init) {
|
||||||
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.9f);
|
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);
|
||||||
|
Style style = Style.builder()
|
||||||
LineStyle style = LineStyle.builder()
|
|
||||||
.stippleColor(c)
|
.stippleColor(c)
|
||||||
.stipple(24)
|
.stipple(24)
|
||||||
.stippleWidth(1)
|
.stippleWidth(1)
|
||||||
@@ -118,9 +105,7 @@ public class LineTexTest extends GdxMap {
|
|||||||
.fixed(true)
|
.fixed(true)
|
||||||
.texture(tex)
|
.texture(tex)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
pathLayer = new PathLayer(mMap, style);
|
pathLayer = new PathLayer(mMap, style);
|
||||||
|
|
||||||
mMap.layers().add(pathLayer);
|
mMap.layers().add(pathLayer);
|
||||||
mPathLayers.add(pathLayer);
|
mPathLayers.add(pathLayer);
|
||||||
} else {
|
} 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) {
|
public static void main(String[] args) {
|
||||||
GdxMapApp.init();
|
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.backend.canvas.Color;
|
||||||
import org.oscim.gdx.GdxMapApp;
|
import org.oscim.gdx.GdxMapApp;
|
||||||
import org.oscim.layers.TileGridLayer;
|
import org.oscim.layers.TileGridLayer;
|
||||||
|
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||||
import org.oscim.layers.vector.VectorLayer;
|
import org.oscim.layers.vector.VectorLayer;
|
||||||
import org.oscim.layers.vector.geometries.PointDrawable;
|
import org.oscim.layers.vector.geometries.PointDrawable;
|
||||||
import org.oscim.layers.vector.geometries.Style;
|
import org.oscim.layers.vector.geometries.Style;
|
||||||
import org.oscim.theme.VtmThemes;
|
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
|
||||||
import org.oscim.utils.ColorUtil;
|
import org.oscim.utils.ColorUtil;
|
||||||
|
|
||||||
public class VectorLayerTest extends GdxMapApp {
|
public class VectorLayerTest extends GdxMapApp {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createLayers() {
|
public void createLayers() {
|
||||||
mMap.setBaseMap(new OSciMap4TileSource());
|
BitmapTileLayer bitmapLayer = new BitmapTileLayer(mMap, DefaultSources.STAMEN_TONER.build());
|
||||||
mMap.setTheme(VtmThemes.DEFAULT);
|
bitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
||||||
|
mMap.setBaseMap(bitmapLayer);
|
||||||
|
|
||||||
|
mMap.setMapPosition(0, 0, 1 << 2);
|
||||||
|
|
||||||
VectorLayer vectorLayer = new VectorLayer(mMap);
|
VectorLayer vectorLayer = new VectorLayer(mMap);
|
||||||
|
|
||||||
@@ -53,7 +56,7 @@ public class VectorLayerTest extends GdxMapApp {
|
|||||||
Style.Builder sb = Style.builder()
|
Style.Builder sb = Style.builder()
|
||||||
.buffer(0.4)
|
.buffer(0.4)
|
||||||
.fillColor(Color.RED)
|
.fillColor(Color.RED)
|
||||||
.fillAlpha(0.2);
|
.fillAlpha(0.2f);
|
||||||
|
|
||||||
// int tileSize = 5;
|
// int tileSize = 5;
|
||||||
// for (int x = -180; x < 200; x += tileSize) {
|
// for (int x = -180; x < 200; x += tileSize) {
|
||||||
@@ -72,7 +75,7 @@ public class VectorLayerTest extends GdxMapApp {
|
|||||||
Style style = sb.buffer(Math.random() * 1)
|
Style style = sb.buffer(Math.random() * 1)
|
||||||
.fillColor(ColorUtil.setHue(Color.RED,
|
.fillColor(ColorUtil.setHue(Color.RED,
|
||||||
Math.random()))
|
Math.random()))
|
||||||
.fillAlpha(0.5)
|
.fillAlpha(0.5f)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
vectorLayer.add(new PointDrawable(Math.random() * 180 - 90,
|
vectorLayer.add(new PointDrawable(Math.random() * 180 - 90,
|
||||||
@@ -80,11 +83,10 @@ public class VectorLayerTest extends GdxMapApp {
|
|||||||
style));
|
style));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
vectorLayer.update();
|
||||||
|
|
||||||
mMap.layers().add(vectorLayer);
|
mMap.layers().add(vectorLayer);
|
||||||
mMap.layers().add(new TileGridLayer(mMap, 0xff222222, 1.2f, 1));
|
mMap.layers().add(new TileGridLayer(mMap, 0xff222222, 1.2f, 1));
|
||||||
|
|
||||||
mMap.setMapPosition(0, 0, 1 << 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
Reference in New Issue
Block a user