From 7cdeacd1c29103fbd46cc39c3de53112042dd0c0 Mon Sep 17 00:00:00 2001 From: Erik Duisters Date: Fri, 16 Sep 2016 20:43:06 +0200 Subject: [PATCH] Marker interface making marker handling more flexible --- .../android/test/MarkerOverlayActivity.java | 5 ++-- .../oscim/android/canvas/AndroidGraphics.java | 2 +- vtm-app/src/org/oscim/app/POISearch.java | 2 +- vtm-app/src/org/oscim/app/RouteSearch.java | 2 +- .../osmdroid/overlays/ExtendedMarkerItem.java | 17 +++----------- .../src/org/oscim/test/MarkerLayerTest.java | 10 ++++---- .../oscim/layers/marker/ItemizedLayer.java | 10 +------- .../oscim/layers/marker/MarkerInterface.java | 23 +++++++++++++++++++ .../org/oscim/layers/marker/MarkerItem.java | 22 ++++-------------- .../org/oscim/layers/marker/MarkerLayer.java | 2 +- .../org/oscim/layers/marker/MarkerSymbol.java | 13 ++++++++++- 11 files changed, 55 insertions(+), 53 deletions(-) create mode 100644 vtm/src/org/oscim/layers/marker/MarkerInterface.java diff --git a/vtm-android-example/src/org/oscim/android/test/MarkerOverlayActivity.java b/vtm-android-example/src/org/oscim/android/test/MarkerOverlayActivity.java index 015f67e1b..ecb20a91a 100644 --- a/vtm-android-example/src/org/oscim/android/test/MarkerOverlayActivity.java +++ b/vtm-android-example/src/org/oscim/android/test/MarkerOverlayActivity.java @@ -26,8 +26,8 @@ import org.oscim.layers.TileGridLayer; import org.oscim.layers.marker.ItemizedLayer; import org.oscim.layers.marker.MarkerItem; -import org.oscim.layers.marker.MarkerItem.HotspotPlace; import org.oscim.layers.marker.MarkerSymbol; +import org.oscim.layers.marker.MarkerSymbol.HotspotPlace; import java.util.ArrayList; import java.util.List; @@ -76,8 +76,7 @@ public void onCreate(Bundle savedInstanceState) { for (double lat = -90; lat <= 90; lat += 5) { for (double lon = -180; lon <= 180; lon += 5) - pts.add(new MarkerItem(lat + "/" + lon, "", - new GeoPoint(lat, lon))); + pts.add(new MarkerItem(lat + "/" + lon, "", new GeoPoint(lat, lon))); } markerLayer.addItems(pts); diff --git a/vtm-android/src/org/oscim/android/canvas/AndroidGraphics.java b/vtm-android/src/org/oscim/android/canvas/AndroidGraphics.java index 5165e7a84..642adf985 100644 --- a/vtm-android/src/org/oscim/android/canvas/AndroidGraphics.java +++ b/vtm-android/src/org/oscim/android/canvas/AndroidGraphics.java @@ -26,8 +26,8 @@ import org.oscim.backend.canvas.Bitmap; import org.oscim.backend.canvas.Canvas; import org.oscim.backend.canvas.Paint; -import org.oscim.layers.marker.MarkerItem.HotspotPlace; import org.oscim.layers.marker.MarkerSymbol; +import org.oscim.layers.marker.MarkerSymbol.HotspotPlace; import java.io.IOException; import java.io.InputStream; diff --git a/vtm-app/src/org/oscim/app/POISearch.java b/vtm-app/src/org/oscim/app/POISearch.java index b79c4750e..a1b9517a1 100644 --- a/vtm-app/src/org/oscim/app/POISearch.java +++ b/vtm-app/src/org/oscim/app/POISearch.java @@ -27,8 +27,8 @@ import org.oscim.android.canvas.AndroidGraphics; import org.oscim.core.BoundingBox; import org.oscim.core.GeoPoint; -import org.oscim.layers.marker.MarkerItem.HotspotPlace; import org.oscim.layers.marker.MarkerSymbol; +import org.oscim.layers.marker.MarkerSymbol.HotspotPlace; import org.oscim.map.Map; import org.osmdroid.location.FlickrPOIProvider; import org.osmdroid.location.FourSquareProvider; diff --git a/vtm-app/src/org/oscim/app/RouteSearch.java b/vtm-app/src/org/oscim/app/RouteSearch.java index 667f9e4d4..3a1a4f969 100644 --- a/vtm-app/src/org/oscim/app/RouteSearch.java +++ b/vtm-app/src/org/oscim/app/RouteSearch.java @@ -28,8 +28,8 @@ import org.oscim.android.canvas.AndroidGraphics; import org.oscim.core.GeoPoint; import org.oscim.layers.PathLayer; -import org.oscim.layers.marker.MarkerItem.HotspotPlace; import org.oscim.layers.marker.MarkerSymbol; +import org.oscim.layers.marker.MarkerSymbol.HotspotPlace; import org.osmdroid.location.GeocoderNominatim; import org.osmdroid.overlays.DefaultInfoWindow; import org.osmdroid.overlays.ExtendedMarkerItem; diff --git a/vtm-app/src/org/osmdroid/overlays/ExtendedMarkerItem.java b/vtm-app/src/org/osmdroid/overlays/ExtendedMarkerItem.java index fcde01413..852218164 100644 --- a/vtm-app/src/org/osmdroid/overlays/ExtendedMarkerItem.java +++ b/vtm-app/src/org/osmdroid/overlays/ExtendedMarkerItem.java @@ -21,10 +21,6 @@ * @see ItemizedOverlayWithBubble */ public class ExtendedMarkerItem extends MarkerItem { - - // now, they are modifiable - private String mTitle, mDescription; - // now, they are modifiable // a third field that can be displayed in // the infowindow, on a third line // that will be shown in the infowindow. @@ -36,19 +32,17 @@ public class ExtendedMarkerItem extends MarkerItem { public ExtendedMarkerItem(String aTitle, String aDescription, GeoPoint aGeoPoint) { super(aTitle, aDescription, aGeoPoint); - mTitle = aTitle; - mDescription = aDescription; mSubDescription = null; mImage = null; mRelatedObject = null; } public void setTitle(String aTitle) { - mTitle = aTitle; + title = aTitle; } public void setDescription(String aDescription) { - mDescription = aDescription; + description = aDescription; } public void setSubDescription(String aSubDescription) { @@ -63,13 +57,8 @@ public void setRelatedObject(Object o) { mRelatedObject = o; } - @Override - public String getTitle() { - return mTitle; - } - public String getDescription() { - return mDescription; + return description; } public String getSubDescription() { diff --git a/vtm-playground/src/org/oscim/test/MarkerLayerTest.java b/vtm-playground/src/org/oscim/test/MarkerLayerTest.java index 124ecda0c..0860dc5d1 100644 --- a/vtm-playground/src/org/oscim/test/MarkerLayerTest.java +++ b/vtm-playground/src/org/oscim/test/MarkerLayerTest.java @@ -28,6 +28,8 @@ import java.util.ArrayList; import java.util.List; +import static org.oscim.layers.marker.MarkerSymbol.HotspotPlace; + public class MarkerLayerTest extends GdxMapApp implements ItemizedLayer.OnItemGestureListener { private static final boolean BILLBOARDS = true; @@ -44,15 +46,15 @@ public void createLayers() { Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png")); MarkerSymbol symbol; if (BILLBOARDS) - symbol = new MarkerSymbol(bitmapPoi, MarkerItem.HotspotPlace.BOTTOM_CENTER); + symbol = new MarkerSymbol(bitmapPoi, HotspotPlace.BOTTOM_CENTER); else - symbol = new MarkerSymbol(bitmapPoi, MarkerItem.HotspotPlace.CENTER, false); + symbol = new MarkerSymbol(bitmapPoi, HotspotPlace.CENTER, false); Bitmap bitmapFocus = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_focus.png")); if (BILLBOARDS) - mFocusMarker = new MarkerSymbol(bitmapFocus, MarkerItem.HotspotPlace.BOTTOM_CENTER); + mFocusMarker = new MarkerSymbol(bitmapFocus, HotspotPlace.BOTTOM_CENTER); else - mFocusMarker = new MarkerSymbol(bitmapFocus, MarkerItem.HotspotPlace.CENTER, false); + mFocusMarker = new MarkerSymbol(bitmapFocus, HotspotPlace.CENTER, false); ItemizedLayer markerLayer = new ItemizedLayer<>(mMap, new ArrayList(), symbol, this); mMap.layers().add(markerLayer); diff --git a/vtm/src/org/oscim/layers/marker/ItemizedLayer.java b/vtm/src/org/oscim/layers/marker/ItemizedLayer.java index 9a9594e68..de3ad17fa 100644 --- a/vtm/src/org/oscim/layers/marker/ItemizedLayer.java +++ b/vtm/src/org/oscim/layers/marker/ItemizedLayer.java @@ -33,7 +33,7 @@ import java.util.ArrayList; import java.util.List; -public class ItemizedLayer extends MarkerLayer +public class ItemizedLayer extends MarkerLayer implements GestureListener { static final Logger log = LoggerFactory.getLogger(ItemizedLayer.class); @@ -267,12 +267,4 @@ public boolean onGesture(Gesture g, MotionEvent e) { return false; } - - public Item getByUid(Object uid) { - for (Item it : mItemList) - if (it.getUid() == uid) - return it; - - return null; - } } diff --git a/vtm/src/org/oscim/layers/marker/MarkerInterface.java b/vtm/src/org/oscim/layers/marker/MarkerInterface.java new file mode 100644 index 000000000..9d5f546f5 --- /dev/null +++ b/vtm/src/org/oscim/layers/marker/MarkerInterface.java @@ -0,0 +1,23 @@ +/* + * Copyright 2016 Erik Duisters + * + * 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 . + */ +package org.oscim.layers.marker; + +import org.oscim.core.GeoPoint; + +public interface MarkerInterface { + MarkerSymbol getMarker(); + + GeoPoint getPoint(); +} diff --git a/vtm/src/org/oscim/layers/marker/MarkerItem.java b/vtm/src/org/oscim/layers/marker/MarkerItem.java index 0b735f96f..584d5a08d 100644 --- a/vtm/src/org/oscim/layers/marker/MarkerItem.java +++ b/vtm/src/org/oscim/layers/marker/MarkerItem.java @@ -6,6 +6,7 @@ * * Copyright 2014 Hannes Janetzek * Copyright 2016 devemux86 + * Copyright 2016 Erik Duisters * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -27,24 +28,7 @@ /** * Immutable class describing a GeoPoint with a Title and a Description. */ -public class MarkerItem { - - public static final int ITEM_STATE_FOCUSED_MASK = 4; - public static final int ITEM_STATE_PRESSED_MASK = 1; - public static final int ITEM_STATE_SELECTED_MASK = 2; - - /** - * Indicates a hotspot for an area. This is where the origin (0,0) of a - * point will be located relative to the area. In otherwords this acts as an - * offset. NONE indicates that no adjustment should be made. - */ - public enum HotspotPlace { - NONE, CENTER, BOTTOM_CENTER, - TOP_CENTER, RIGHT_CENTER, LEFT_CENTER, - UPPER_RIGHT_CORNER, LOWER_RIGHT_CORNER, - UPPER_LEFT_CORNER, LOWER_LEFT_CORNER - } - +public class MarkerItem implements MarkerInterface { public final Object uid; public String title; public String description; @@ -78,10 +62,12 @@ public String getSnippet() { return description; } + @Override public GeoPoint getPoint() { return geoPoint; } + @Override public MarkerSymbol getMarker() { return mMarker; } diff --git a/vtm/src/org/oscim/layers/marker/MarkerLayer.java b/vtm/src/org/oscim/layers/marker/MarkerLayer.java index f763136f3..c09d91751 100644 --- a/vtm/src/org/oscim/layers/marker/MarkerLayer.java +++ b/vtm/src/org/oscim/layers/marker/MarkerLayer.java @@ -33,7 +33,7 @@ * gets checked for onTap first. This class is generic, because you then you get * your custom item-class passed back in onTap(). << TODO */ -public abstract class MarkerLayer extends Layer { +public abstract class MarkerLayer extends Layer { protected final MarkerRenderer mMarkerRenderer; protected Item mFocusedItem; diff --git a/vtm/src/org/oscim/layers/marker/MarkerSymbol.java b/vtm/src/org/oscim/layers/marker/MarkerSymbol.java index 0e6b112e9..56cc198f2 100644 --- a/vtm/src/org/oscim/layers/marker/MarkerSymbol.java +++ b/vtm/src/org/oscim/layers/marker/MarkerSymbol.java @@ -19,9 +19,20 @@ import org.oscim.backend.canvas.Bitmap; import org.oscim.core.PointF; -import org.oscim.layers.marker.MarkerItem.HotspotPlace; public class MarkerSymbol { + /** + * Indicates a hotspot for an area. This is where the origin (0,0) of a + * point will be located relative to the area. In otherwords this acts as an + * offset. NONE indicates that no adjustment should be made. + */ + public enum HotspotPlace { + NONE, CENTER, BOTTOM_CENTER, + TOP_CENTER, RIGHT_CENTER, LEFT_CENTER, + UPPER_RIGHT_CORNER, LOWER_RIGHT_CORNER, + UPPER_LEFT_CORNER, LOWER_LEFT_CORNER + } + final Bitmap mBitmap; /** * Hotspot offset