Permalink
Browse files

#725 adding rotation to the polygon samples for testing purposes

  • Loading branch information...
spyhunter99 committed Oct 10, 2017
1 parent 0e63c3d commit 5cb4ee660f2843cc4b939af1ef6e8295cb60353a
@@ -2,14 +2,24 @@
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import org.osmdroid.R;
import org.osmdroid.api.IGeoPoint;
import org.osmdroid.api.IMapView;
import org.osmdroid.events.MapListener;
import org.osmdroid.events.ScrollEvent;
import org.osmdroid.events.ZoomEvent;
import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.gestures.RotationGestureOverlay;
import static org.osmdroid.samplefragments.events.SampleMapEventListener.df;
/**
* created on 8/26/2017.
@@ -18,9 +28,11 @@
*/
public class DrawPolygon extends BaseSampleFragment implements View.OnClickListener {
ImageButton painting,panning;
ImageButton painting, panning;
TextView textViewCurrentLocation;
CustomPaintingSurface paint;
ImageButton btnRotateLeft, btnRotateRight;
@Override
public String getSampleTitle() {
return "Draw a polygon on screen";
@@ -30,7 +42,33 @@ public String getSampleTitle() {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.layout_drawlines, null);
btnRotateLeft = (ImageButton) v.findViewById(R.id.btnRotateLeft);
btnRotateRight = (ImageButton) v.findViewById(R.id.btnRotateRight);
btnRotateRight.setOnClickListener(this);
btnRotateLeft.setOnClickListener(this);
textViewCurrentLocation = (TextView) v.findViewById(R.id.textViewCurrentLocation);
mMapView = (MapView) v.findViewById(org.osmdroid.R.id.mapview);
mMapView.setMapListener(new MapListener() {
@Override
public boolean onScroll(ScrollEvent event) {
Log.i(IMapView.LOGTAG, System.currentTimeMillis() + " onScroll " + event.getX() + "," + event.getY());
//Toast.makeText(getActivity(), "onScroll", Toast.LENGTH_SHORT).show();
updateInfo();
return true;
}
@Override
public boolean onZoom(ZoomEvent event) {
Log.i(IMapView.LOGTAG, System.currentTimeMillis() + " onZoom " + event.getZoomLevel());
updateInfo();
return true;
}
});
RotationGestureOverlay mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
mRotationGestureOverlay.setEnabled(true);
mMapView.setMultiTouchControls(true);
mMapView.getOverlayManager().add(mRotationGestureOverlay);
panning = (ImageButton) v.findViewById(R.id.enablePanning);
panning.setOnClickListener(this);
panning.setBackgroundColor(Color.BLACK);
@@ -43,6 +81,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
}
private void updateInfo() {
IGeoPoint mapCenter = mMapView.getMapCenter();
textViewCurrentLocation.setText(df.format(mapCenter.getLatitude()) + "," +
df.format(mapCenter.getLongitude())
+ ",zoom=" + mMapView.getZoomLevelDouble() + ",angle=" + mMapView.getMapOrientation());
}
@Override
public void onClick(View v) {
switch (v.getId()) {
@@ -56,6 +102,25 @@ public void onClick(View v) {
painting.setBackgroundColor(Color.BLACK);
panning.setBackgroundColor(Color.TRANSPARENT);
break;
case R.id.btnRotateLeft: {
float angle = mMapView.getMapOrientation() + 10;
if (angle > 360)
angle = 360 - angle;
mMapView.setMapOrientation(angle);
updateInfo();
}
break;
case R.id.btnRotateRight: {
float angle = mMapView.getMapOrientation() - 10;
if (angle < 0)
angle += 360f;
mMapView.setMapOrientation(angle);
updateInfo();
}
break;
}
}
}
@@ -2,14 +2,24 @@
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import org.osmdroid.R;
import org.osmdroid.api.IGeoPoint;
import org.osmdroid.api.IMapView;
import org.osmdroid.events.MapListener;
import org.osmdroid.events.ScrollEvent;
import org.osmdroid.events.ZoomEvent;
import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.gestures.RotationGestureOverlay;
import static org.osmdroid.samplefragments.events.SampleMapEventListener.df;
/**
* created on 8/26/2017.
@@ -20,6 +30,9 @@
public class DrawPolygonHoles extends BaseSampleFragment implements View.OnClickListener {
ImageButton painting,panning,holes;
TextView textViewCurrentLocation;
ImageButton btnRotateLeft, btnRotateRight;
CustomPaintingSurface paint;
@Override
public String getSampleTitle() {
@@ -31,6 +44,34 @@ public String getSampleTitle() {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.layout_drawpolyholes, null);
mMapView = (MapView) v.findViewById(R.id.mapview);
btnRotateLeft = (ImageButton) v.findViewById(R.id.btnRotateLeft);
btnRotateRight = (ImageButton) v.findViewById(R.id.btnRotateRight);
btnRotateRight.setOnClickListener(this);
btnRotateLeft.setOnClickListener(this);
textViewCurrentLocation = (TextView) v.findViewById(R.id.textViewCurrentLocation);
mMapView = (MapView) v.findViewById(org.osmdroid.R.id.mapview);
mMapView.setMapListener(new MapListener() {
@Override
public boolean onScroll(ScrollEvent event) {
Log.i(IMapView.LOGTAG, System.currentTimeMillis() + " onScroll " + event.getX() + "," + event.getY());
//Toast.makeText(getActivity(), "onScroll", Toast.LENGTH_SHORT).show();
updateInfo();
return true;
}
@Override
public boolean onZoom(ZoomEvent event) {
Log.i(IMapView.LOGTAG, System.currentTimeMillis() + " onZoom " + event.getZoomLevel());
updateInfo();
return true;
}
});
RotationGestureOverlay mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
mRotationGestureOverlay.setEnabled(true);
mMapView.setMultiTouchControls(true);
mMapView.getOverlayManager().add(mRotationGestureOverlay);
panning = (ImageButton) v.findViewById(R.id.enablePanning);
panning.setOnClickListener(this);
panning.setBackgroundColor(Color.BLACK);
@@ -70,6 +111,33 @@ public void onClick(View v) {
painting.setBackgroundColor(Color.TRANSPARENT);
panning.setBackgroundColor(Color.TRANSPARENT);
break;
case R.id.btnRotateLeft: {
float angle = mMapView.getMapOrientation() + 10;
if (angle > 360)
angle = 360 - angle;
mMapView.setMapOrientation(angle);
updateInfo();
}
break;
case R.id.btnRotateRight: {
float angle = mMapView.getMapOrientation() - 10;
if (angle < 0)
angle += 360f;
mMapView.setMapOrientation(angle);
updateInfo();
}
break;
}
}
private void updateInfo() {
IGeoPoint mapCenter = mMapView.getMapCenter();
textViewCurrentLocation.setText(df.format(mapCenter.getLatitude()) + "," +
df.format(mapCenter.getLongitude())
+ ",zoom=" + mMapView.getZoomLevelDouble() + ",angle=" + mMapView.getMapOrientation());
}
}
@@ -11,6 +11,7 @@
import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Polygon;
import org.osmdroid.views.overlay.gestures.RotationGestureOverlay;
/**
* created on 1/13/2017.
@@ -32,6 +33,10 @@ public String getSampleTitle() {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.layout_drawlines, null);
mMapView = (MapView) v.findViewById(org.osmdroid.R.id.mapview);
RotationGestureOverlay mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
mRotationGestureOverlay.setEnabled(true);
mMapView.setMultiTouchControls(true);
mMapView.getOverlayManager().add(mRotationGestureOverlay);
panning = (ImageButton) v.findViewById(R.id.enablePanning);
panning.setOnClickListener(this);
panning.setBackgroundColor(Color.BLACK);
@@ -9,7 +9,32 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tilesource="Mapnik" />
<TextView android:id="@+id/textViewCurrentLocation"
android:layout_width="fill_parent"
android:text="PLACEHOLDER"
android:textAlignment="center"
android:gravity="center"
android:textColor="@android:color/white"
android:background="#77000000"
android:layout_height="wrap_content"></TextView>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/zoom_in"
android:layout_below="@id/textViewCurrentLocation"
android:layout_alignParentLeft="true"
android:id="@+id/btnRotateLeft"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/zoom_out"
android:id="@+id/btnRotateRight"
android:layout_below="@+id/btnRotateLeft"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<org.osmdroid.samplefragments.drawing.CustomPaintingSurface
android:layout_width="fill_parent"
android:layout_height="fill_parent"
@@ -21,14 +46,14 @@
android:layout_height="wrap_content"
android:id="@+id/enablePanning"
android:src="@drawable/ic_menu_mylocation"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#00ffffff"
android:contentDescription="@string/bt_center_map_description"
android:cropToPadding="true" />
android:cropToPadding="true"
android:layout_below="@+id/textViewCurrentLocation"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="10dp"/>
<ImageButton
android:layout_width="wrap_content"
@@ -9,7 +9,32 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tilesource="Mapnik" />
<TextView android:id="@+id/textViewCurrentLocation"
android:layout_width="fill_parent"
android:text="PLACEHOLDER"
android:textAlignment="center"
android:gravity="center"
android:textColor="@android:color/white"
android:background="#77000000"
android:layout_height="wrap_content"></TextView>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/zoom_in"
android:layout_below="@id/textViewCurrentLocation"
android:layout_alignParentLeft="true"
android:id="@+id/btnRotateLeft"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/zoom_out"
android:id="@+id/btnRotateRight"
android:layout_below="@+id/btnRotateLeft"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<org.osmdroid.samplefragments.drawing.CustomPaintingSurface
android:layout_width="fill_parent"
android:layout_height="fill_parent"
@@ -21,14 +46,14 @@
android:layout_height="wrap_content"
android:id="@+id/enablePanning"
android:src="@drawable/ic_menu_mylocation"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginRight="13dp"
android:background="#00ffffff"
android:contentDescription="@string/bt_center_map_description"
android:cropToPadding="true" />
android:cropToPadding="true"
android:layout_below="@+id/textViewCurrentLocation"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="13dp"/>
<ImageButton
android:layout_width="wrap_content"

0 comments on commit 5cb4ee6

Please sign in to comment.