vtm-jts: PathLayer improvements, #53

This commit is contained in:
Emux
2016-08-02 20:10:29 +03:00
parent 5eae87e892
commit 4a663f949e
3 changed files with 23 additions and 23 deletions

View File

@@ -22,7 +22,7 @@ import android.os.Bundle;
import org.oscim.backend.canvas.Color; import org.oscim.backend.canvas.Color;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.event.Event; import org.oscim.event.Event;
import org.oscim.layers.JtsPathLayer; import org.oscim.layers.vector.PathLayer;
import org.oscim.map.Map.UpdateListener; import org.oscim.map.Map.UpdateListener;
import java.util.ArrayList; import java.util.ArrayList;
@@ -47,7 +47,7 @@ public class PathOverlayActivity extends BitmapTileMapActivity {
mMap.setMapPosition(0, 0, 1 << 2); mMap.setMapPosition(0, 0, 1 << 2);
for (double lat = -90; lat <= 90; lat += 5) { for (double lat = -90; lat <= 90; lat += 5) {
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f); int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);
JtsPathLayer pathLayer = new JtsPathLayer(mMap, c, 6); PathLayer pathLayer = new PathLayer(mMap, c, 6);
mMap.layers().add(pathLayer); mMap.layers().add(pathLayer);
mPathLayers.add(pathLayer); mPathLayers.add(pathLayer);
} }
@@ -74,7 +74,7 @@ public class PathOverlayActivity extends BitmapTileMapActivity {
mMap.setMapPosition(0, 0, 1 << 2); mMap.setMapPosition(0, 0, 1 << 2);
} }
ArrayList<JtsPathLayer> mPathLayers = new ArrayList<JtsPathLayer>(); ArrayList<PathLayer> mPathLayers = new ArrayList<>();
void createLayers(float pos) { void createLayers(float pos) {

View File

@@ -1,6 +1,7 @@
/* /*
* Copyright 2012 osmdroid authors: Viesturs Zarins, Martin Pearman * Copyright 2012 osmdroid authors: Viesturs Zarins, Martin Pearman
* Copyright 2012 Hannes Janetzek * Copyright 2012 Hannes Janetzek
* Copyright 2016 devemux86
* *
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
* *
@@ -15,13 +16,11 @@
* You should have received a copy of the GNU Lesser General Public License along with * 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/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.oscim.layers.vector;
package org.oscim.layers;
import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LineString;
import org.oscim.core.GeoPoint; import org.oscim.core.GeoPoint;
import org.oscim.layers.vector.VectorLayer;
import org.oscim.layers.vector.geometries.LineDrawable; import org.oscim.layers.vector.geometries.LineDrawable;
import org.oscim.layers.vector.geometries.Style; import org.oscim.layers.vector.geometries.Style;
import org.oscim.map.Map; import org.oscim.map.Map;
@@ -33,32 +32,33 @@ import java.util.List;
/** /**
* This class draws a path line in given color. * This class draws a path line in given color.
*/ */
public class JtsPathLayer extends VectorLayer { public class PathLayer extends VectorLayer {
protected final ArrayList<GeoPoint> mPoints; protected final ArrayList<GeoPoint> mPoints;
protected Style mStyle; protected Style mStyle;
protected LineDrawable mDrawable; protected LineDrawable mDrawable;
public JtsPathLayer(Map map, int lineColor, float lineWidth) { public PathLayer(Map map, Style style) {
super(map); super(map);
mStyle = Style.builder() mStyle = style;
.strokeColor(lineColor)
.strokeWidth(lineWidth)
.build();
mPoints = new ArrayList<GeoPoint>(); mPoints = new ArrayList<>();
} }
public JtsPathLayer(Map map, int lineColor) { public PathLayer(Map map, int lineColor, float lineWidth) {
this(map, Style.builder()
.strokeColor(lineColor)
.strokeWidth(lineWidth)
.build());
}
public PathLayer(Map map, int lineColor) {
this(map, lineColor, 2); this(map, lineColor, 2);
} }
public void setStyle(int lineColor, float lineWidth) { public void setStyle(Style style) {
mStyle = Style.builder() mStyle = style;
.strokeColor(lineColor)
.strokeWidth(lineWidth)
.build();
} }
public void clearPath() { public void clearPath() {

View File

@@ -21,8 +21,8 @@ import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.event.Event; import org.oscim.event.Event;
import org.oscim.gdx.GdxMapApp; import org.oscim.gdx.GdxMapApp;
import org.oscim.layers.JtsPathLayer;
import org.oscim.layers.tile.bitmap.BitmapTileLayer; import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.layers.vector.PathLayer;
import org.oscim.map.Map.UpdateListener; import org.oscim.map.Map.UpdateListener;
import org.oscim.tiling.source.bitmap.DefaultSources; import org.oscim.tiling.source.bitmap.DefaultSources;
@@ -52,7 +52,7 @@ public class PathLayerTest extends GdxMapApp {
}); });
} }
ArrayList<JtsPathLayer> mPathLayers = new ArrayList<>(); ArrayList<PathLayer> mPathLayers = new ArrayList<>();
void createLayers(float pos, boolean init) { void createLayers(float pos, boolean init) {
@@ -80,10 +80,10 @@ public class PathLayerTest extends GdxMapApp {
pts.add(new GeoPoint(latitude, longitude)); pts.add(new GeoPoint(latitude, longitude));
} }
JtsPathLayer pathLayer; PathLayer pathLayer;
if (init) { if (init) {
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f); int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);
pathLayer = new JtsPathLayer(mMap, c, 6); pathLayer = new PathLayer(mMap, c, 6);
mMap.layers().add(pathLayer); mMap.layers().add(pathLayer);
mPathLayers.add(pathLayer); mPathLayers.add(pathLayer);
} else { } else {