Skip to content

Commit

Permalink
Line texture: stipple implementation, PathLayer support, #105
Browse files Browse the repository at this point in the history
  • Loading branch information
devemux86 committed Aug 7, 2016
1 parent 4a663f9 commit 8861125
Show file tree
Hide file tree
Showing 26 changed files with 736 additions and 254 deletions.
12 changes: 7 additions & 5 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

## New for 0.6.0

- Render themes SVG resources [#60](https://github.com/mapsforge/vtm/issues/60)
**Revive of VTM vector map library.**

- Render theme SVG resources [#60](https://github.com/mapsforge/vtm/issues/60)
- Mapsforge multilingual maps [#34](https://github.com/mapsforge/vtm/issues/34)
- vtm-ios update module [#29](https://github.com/mapsforge/vtm/issues/29)
- Native libraries for all platforms [#14](https://github.com/mapsforge/vtm/issues/14)
- Line stipple and texture rendering
- Layer groups [#99](https://github.com/mapsforge/vtm/issues/99) [#103](https://github.com/mapsforge/vtm/issues/103)
- Map scale bar multi-platform implementation [#84](https://github.com/mapsforge/vtm/issues/84)
- Render themes area tessellation option [#37](https://github.com/mapsforge/vtm/issues/37)
- Map scale bar multi-platform [#84](https://github.com/mapsforge/vtm/issues/84)
- Render theme area tessellation option [#37](https://github.com/mapsforge/vtm/issues/37)
- Graphics API platform enhancements [#92](https://github.com/mapsforge/vtm/issues/92)
- vtm-jts create module [#53](https://github.com/mapsforge/vtm/issues/53)
- vtm-jts module [#53](https://github.com/mapsforge/vtm/issues/53)
- Internal render themes various enhancements
- Revive VTM library
- Many other minor improvements and bug fixes
- [Solved issues](https://github.com/mapsforge/vtm/issues?q=is%3Aissue+is%3Aclosed+milestone%3A0.6.0)
3 changes: 3 additions & 0 deletions vtm-android-example/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<activity
android:name=".LayerGroupActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".LineTexActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MapsforgeMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
Expand Down
139 changes: 139 additions & 0 deletions vtm-android-example/src/org/oscim/android/test/LineTexActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright 2014 Hannes Janetzek
* 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.android.test;

import android.os.Bundle;
import android.os.SystemClock;

import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.canvas.Color;
import org.oscim.core.GeoPoint;
import org.oscim.layers.PathLayer;
import org.oscim.renderer.bucket.TextureItem;
import org.oscim.theme.styles.LineStyle;

import java.util.ArrayList;
import java.util.List;

import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;

/**
* This is a very INEFFICIENT and somewhat less useful example for how to use
* PathLayers!
*/
public class LineTexActivity extends BitmapTileMapActivity {

public LineTexActivity() {
super(STAMEN_TONER.build());
}

TextureItem tex;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBitmapLayer.tileRenderer().setBitmapAlpha(0.5f);

tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
tex.mipmap = true;

createLayers(1, true);

//looooop();
}

@Override
protected void onResume() {
super.onResume();

/* ignore saved position */
mMap.setMapPosition(0, 0, 1 << 2);
}

void looooop() {
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;

for (double lat = -90; lat <= 90; lat += 5) {
List<GeoPoint> pts = new ArrayList<>();

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 latitude = lat + (pos * 90);
if (latitude < -90)
latitude += 180;
if (latitude > 90)
latitude -= 180;

latitude += Math.sin((Math.abs(pos) * (lon / Math.PI)));

pts.add(new GeoPoint(latitude, longitude));
}
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);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public MarkerOverlayActivity() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBitmapLayer.tileRenderer().setBitmapAlpha(0.5f);

/* directly load bitmap from resources */
Bitmap bitmap = drawableToBitmap(getResources(), R.drawable.marker_poi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,50 @@
import org.oscim.map.Map.UpdateListener;

import java.util.ArrayList;
import java.util.List;

import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;

/**
* This is a very INEFFICIENT and somewhat less usefull example for how to use
* This is a very INEFFICIENT and somewhat less useful example for how to use
* PathLayers!
*/
public class PathOverlayActivity extends BitmapTileMapActivity {

private static final boolean ANIMATION = true;

private List<PathLayer> mPathLayers = new ArrayList<>();

public PathOverlayActivity() {
super(STAMEN_TONER.build());
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//mBitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
mBitmapLayer.tileRenderer().setBitmapAlpha(0.5f);

mMap.setMapPosition(0, 0, 1 << 2);
for (double lat = -90; lat <= 90; lat += 5) {
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);
PathLayer pathLayer = new PathLayer(mMap, c, 6);
mMap.layers().add(pathLayer);
mPathLayers.add(pathLayer);
}

mMap.events.bind(new 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);
//}
}
});
if (ANIMATION)
mMap.events.bind(new 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
Expand All @@ -74,14 +80,12 @@ protected void onResume() {
mMap.setMapPosition(0, 0, 1 << 2);
}

ArrayList<PathLayer> mPathLayers = new ArrayList<>();

void createLayers(float pos) {

int i = 0;
for (double lat = -90; lat <= 90; lat += 5) {
double[] packedCoordinates = new double[360 + 2];
//List<GeoPoint> pts = new ArrayList<GeoPoint>();
//List<GeoPoint> pts = new ArrayList<>();
int c = 0;
for (double lon = -180; lon <= 180; lon += 2) {
//pts.add(new GeoPoint(lat, lon));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected void onCreate(Bundle savedInstanceState) {
linearLayout.addView(createButton(MapsforgeMapActivity.class));
linearLayout.addView(createButton(MarkerOverlayActivity.class));
linearLayout.addView(createButton(PathOverlayActivity.class));
linearLayout.addView(createButton(LineTexActivity.class));
linearLayout.addView(createButton(LayerGroupActivity.class));
linearLayout.addView(createButton(ThemeStylerActivity.class));
linearLayout.addView(createButton(S3DBMapActivity.class));
Expand Down
41 changes: 19 additions & 22 deletions vtm-playground/src/org/oscim/test/LineRenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.badlogic.gdx.Input;

import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.canvas.Color;
import org.oscim.backend.canvas.Paint.Cap;
import org.oscim.core.GeometryBuffer;
Expand All @@ -29,6 +30,7 @@
import org.oscim.renderer.MapRenderer;
import org.oscim.renderer.bucket.LineBucket;
import org.oscim.renderer.bucket.LineTexBucket;
import org.oscim.renderer.bucket.TextureItem;
import org.oscim.theme.styles.LineStyle;

public class LineRenderTest extends GdxMap {
Expand Down Expand Up @@ -68,28 +70,27 @@ void addLines(LineTest l, int layer, boolean addOutline, boolean fixed) {
if (fixed) {
line1 = new LineStyle(Color.RED, 0.5f);
line2 = new LineStyle(Color.GREEN, 1);
line3 = new LineStyle(Color.BLUE, 2);
line4 = new LineStyle(Color.LTGRAY, 3);

} else {
line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f,
Cap.BUTT, false, 0, 0, 0, 0, 1f, false);

line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, true, 0, 0,
0, 0, 1f, false);

line3 = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 4,
Color.CYAN, 1, 0, 0, false);

line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0,
0, 0, 0, 1f, false);
line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null);
line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, false, 0, 0, 0, 0, 1f, false, null);
line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, false, null);
}

LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0,
0, 0, 0, 1f, true);

LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0,
0, 0, 0, 0, true);
TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/dot.png"));
tex.mipmap = true;
line3 = LineStyle.builder()
.stippleColor(Color.CYAN)
.stipple(8)
.stippleWidth(0.6f)
.strokeWidth(4)
.strokeColor(Color.BLUE)
.fixed(fixed)
.texture(tex)
.build();

LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, true, null);
LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 0, true, null);

LineBucket ol = l.buckets.addLineBucket(0, outline);
LineBucket ol2 = l.buckets.addLineBucket(5, outline2);
Expand All @@ -112,14 +113,10 @@ void addLines(LineTest l, int layer, boolean addOutline, boolean fixed) {

LineTexBucket lt = l.buckets.getLineTexBucket(30);
lt.line = line3;
lt.width = line3.width;
lt.addLine(g.translate(0, 10.5f));
lt.addLine(g.translate(0, 10.5f));
addCircle(200, 200, 100, lt);

// if (addOutline)
// ol2.addOutline(ll);

ll = l.buckets.addLineBucket(40, line4);
ll.addLine(g.translate(0, 10.5f));
ll.addLine(g.translate(0, 10.5f));
Expand Down
Loading

0 comments on commit 8861125

Please sign in to comment.