Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol rotation #294

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions vtm-android-example/build.gradle
@@ -1,6 +1,7 @@
apply plugin: 'com.android.application'

dependencies {
compile project(':vtm')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need that as have already the vtm-android being a transitive dependency.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it with me, because my Gradle complained!

Copy link
Collaborator

@devemux86 devemux86 Feb 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange..
VTM on Android Studio / Gradle releases should work 'as is' or else we should fix it.
Also Travis has not complained so far about dependencies.
Have you modified or disabled transitive in your Gradle properties somehow?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My Gradle properties are empty!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try with a fresh VTM clone and a clean Gradle cache to test if it's a local Gradle build problem.

compile project(':vtm-android')
compile project(':vtm-extras')
compile project(':vtm-http')
Expand Down
Expand Up @@ -36,6 +36,9 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;

import static org.oscim.android.canvas.AndroidGraphics.drawableToBitmap;
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
Expand All @@ -45,6 +48,7 @@ public class MarkerOverlayActivity extends BitmapTileMapActivity

protected static final boolean BILLBOARDS = true;
protected MarkerSymbol mFocusMarker;
private ItemizedLayer<MarkerItem> markerLayer;

public MarkerOverlayActivity() {
super(STAMEN_TONER.build());
Expand Down Expand Up @@ -74,7 +78,7 @@ public void onCreate(Bundle savedInstanceState) {
else
mFocusMarker = new MarkerSymbol(drawableToBitmap(d), HotspotPlace.CENTER, false);

ItemizedLayer<MarkerItem> markerLayer =
markerLayer =
new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(),
symbol, this);

Expand All @@ -100,23 +104,63 @@ protected void onResume() {
mMap.setMapPosition(0, 0, 1 << 2);
}

Timer timer;
int markerCount = 0;

@Override
public boolean onItemSingleTapUp(int index, MarkerItem item) {
if (item.getMarker() == null)
public boolean onItemSingleTapUp(int index,final MarkerItem item) {
if (item.getMarker() == null) {
item.setMarker(mFocusMarker);
else
markerCount++;
final AtomicInteger rotValue = new AtomicInteger(0);
if(timer != null) timer.cancel();
timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
float value = (float)(rotValue.incrementAndGet() * 10);
item.setRotation(value);
if(rotValue.get()>36) rotValue.set(0);
markerLayer.update();
mMap.updateMap(true);
}
};
timer.schedule(timerTask,1000,1000);

}else {
item.setMarker(null);
markerCount--;
if(timer != null && markerCount == 0) timer.cancel();
}

Toast.makeText(this, "Marker tap\n" + item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}

@Override
public boolean onItemLongPress(int index, MarkerItem item) {
if (item.getMarker() == null)
public boolean onItemLongPress(int index,final MarkerItem item) {
if (item.getMarker() == null) {
item.setMarker(mFocusMarker);
else
markerCount++;
final AtomicInteger rotValue = new AtomicInteger(0);
if(timer != null) timer.cancel();
timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
float value = (float)(rotValue.incrementAndGet() * 10);
item.setRotation(value);
if(rotValue.get()>36) rotValue.set(0);
markerLayer.update();
mMap.updateMap(true);
}
};
timer.schedule(timerTask,300,300);
}else{
item.setMarker(null);
markerCount--;
if(timer != null && markerCount == 0) timer.cancel();
}

Toast.makeText(this, "Marker long press\n" + item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
Expand Down
60 changes: 51 additions & 9 deletions vtm-playground/src/org/oscim/test/MarkerLayerTest.java
@@ -1,5 +1,6 @@
/*
* Copyright 2016 devemux86
* Copyright 2017 Longri
*
* 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
Expand Down Expand Up @@ -30,15 +31,16 @@
import org.oscim.map.Map;
import org.oscim.tiling.source.bitmap.DefaultSources;

import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

import static org.oscim.layers.marker.MarkerSymbol.HotspotPlace;

public class MarkerLayerTest extends GdxMapApp implements ItemizedLayer.OnItemGestureListener<MarkerItem> {

protected static final boolean BILLBOARDS = true;
protected MarkerSymbol mFocusMarker;
private ItemizedLayer<MarkerItem> markerLayer;

@Override
public void createLayers() {
Expand All @@ -64,7 +66,7 @@ public void createLayers() {
else
mFocusMarker = new MarkerSymbol(bitmapFocus, HotspotPlace.CENTER, false);

ItemizedLayer<MarkerItem> markerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this);
markerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this);
mMap.layers().add(markerLayer);

List<MarkerItem> pts = new ArrayList<>();
Expand All @@ -77,23 +79,63 @@ public void createLayers() {
mMap.layers().add(new TileGridLayer(mMap));
}

Timer timer;
int markerCount = 0;

@Override
public boolean onItemSingleTapUp(int index, MarkerItem item) {
if (item.getMarker() == null)
public boolean onItemSingleTapUp(int index,final MarkerItem item) {
if (item.getMarker() == null) {
item.setMarker(mFocusMarker);
else
markerCount++;
final AtomicInteger rotValue = new AtomicInteger(0);
if(timer != null) timer.cancel();
timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
float value = (float)(rotValue.incrementAndGet() * 10);
item.setRotation(value);
if(rotValue.get()>36) rotValue.set(0);
markerLayer.update();
mMap.updateMap(true);
}
};
timer.schedule(timerTask,1000,1000);

}else {
item.setMarker(null);
markerCount--;
if(timer != null && markerCount == 0) timer.cancel();
}

System.out.println("Marker tap " + item.getTitle());
return true;
}

@Override
public boolean onItemLongPress(int index, MarkerItem item) {
if (item.getMarker() == null)
public boolean onItemLongPress(int index,final MarkerItem item) {
if (item.getMarker() == null) {
item.setMarker(mFocusMarker);
else
markerCount++;
final AtomicInteger rotValue = new AtomicInteger(0);
if(timer != null) timer.cancel();
timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
float value = (float)(rotValue.incrementAndGet() * 10);
item.setRotation(value);
if(rotValue.get()>36) rotValue.set(0);
markerLayer.update();
mMap.updateMap(true);
}
};
timer.schedule(timerTask,300,300);
}else{
item.setMarker(null);
markerCount--;
if(timer != null && markerCount == 0) timer.cancel();
}

System.out.println("Marker long press " + item.getTitle());
return true;
Expand Down
5 changes: 5 additions & 0 deletions vtm/src/org/oscim/layers/marker/MarkerItem.java
Expand Up @@ -7,6 +7,7 @@
* Copyright 2014 Hannes Janetzek
* Copyright 2016 devemux86
* Copyright 2016 Erik Duisters
* Copyright 2017 Longri
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand Down Expand Up @@ -75,4 +76,8 @@ public MarkerSymbol getMarker() {
public void setMarker(MarkerSymbol marker) {
mMarker = marker;
}

public void setRotation(float rotation) {
if(mMarker != null) mMarker.setRotation(rotation);
}
}
5 changes: 5 additions & 0 deletions vtm/src/org/oscim/layers/marker/MarkerLayer.java
Expand Up @@ -7,6 +7,7 @@
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Stephan Leuschner
* Copyright 2016 devemux86
* Copyright 2017 Longri
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand Down Expand Up @@ -96,6 +97,10 @@ public Item getFocus() {
return mFocusedItem;
}

public void update() {
mMarkerRenderer.update();
}

/**
* TODO
* Interface definition for overlays that contain items that can be snapped
Expand Down
5 changes: 3 additions & 2 deletions vtm/src/org/oscim/layers/marker/MarkerRenderer.java
@@ -1,6 +1,7 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 Izumi Kawashima
* Copyright 2017 Longri
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand Down Expand Up @@ -163,9 +164,9 @@ else if (it.x < -flip)

SymbolItem s = SymbolItem.pool.get();
if (marker.isBitmap()) {
s.set(it.x, it.y, marker.getBitmap(), true);
s.set(it.x, it.y, marker.getBitmap(), marker.rotation, true);
} else {
s.set(it.x, it.y, marker.getTextureRegion(), true);
s.set(it.x, it.y, marker.getTextureRegion(), marker.rotation,true);
}
s.offset = marker.getHotspot();
s.billboard = marker.isBillboard();
Expand Down
11 changes: 11 additions & 0 deletions vtm/src/org/oscim/layers/marker/MarkerSymbol.java
Expand Up @@ -2,6 +2,7 @@
* Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
* Copyright 2016 Izumi Kawashima
* Copyright 2017 Longri
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
Expand Down Expand Up @@ -44,6 +45,8 @@ public enum HotspotPlace {
final PointF mOffset;
final boolean mBillboard;

float rotation = 0;

public MarkerSymbol(TextureRegion textureRegion, float relX, float relY) {
this(textureRegion, relX, relY, true);
}
Expand Down Expand Up @@ -180,4 +183,12 @@ public boolean isInside(float dx, float dy) {

return dx >= ox && dy >= oy && dx <= ox + w && dy <= oy + h;
}

public void setRotation(float rotation){
this.rotation = rotation;
}

public float getRotation(){
return this.rotation;
}
}