Marker interface making marker handling more flexible
This commit is contained in:
@@ -26,8 +26,8 @@ import org.oscim.core.GeoPoint;
|
|||||||
import org.oscim.layers.TileGridLayer;
|
import org.oscim.layers.TileGridLayer;
|
||||||
import org.oscim.layers.marker.ItemizedLayer;
|
import org.oscim.layers.marker.ItemizedLayer;
|
||||||
import org.oscim.layers.marker.MarkerItem;
|
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;
|
||||||
|
import org.oscim.layers.marker.MarkerSymbol.HotspotPlace;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -76,8 +76,7 @@ public class MarkerOverlayActivity extends BitmapTileMapActivity
|
|||||||
|
|
||||||
for (double lat = -90; lat <= 90; lat += 5) {
|
for (double lat = -90; lat <= 90; lat += 5) {
|
||||||
for (double lon = -180; lon <= 180; lon += 5)
|
for (double lon = -180; lon <= 180; lon += 5)
|
||||||
pts.add(new MarkerItem(lat + "/" + lon, "",
|
pts.add(new MarkerItem(lat + "/" + lon, "", new GeoPoint(lat, lon)));
|
||||||
new GeoPoint(lat, lon)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
markerLayer.addItems(pts);
|
markerLayer.addItems(pts);
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ import org.oscim.backend.CanvasAdapter;
|
|||||||
import org.oscim.backend.canvas.Bitmap;
|
import org.oscim.backend.canvas.Bitmap;
|
||||||
import org.oscim.backend.canvas.Canvas;
|
import org.oscim.backend.canvas.Canvas;
|
||||||
import org.oscim.backend.canvas.Paint;
|
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;
|
||||||
|
import org.oscim.layers.marker.MarkerSymbol.HotspotPlace;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import android.widget.Toast;
|
|||||||
import org.oscim.android.canvas.AndroidGraphics;
|
import org.oscim.android.canvas.AndroidGraphics;
|
||||||
import org.oscim.core.BoundingBox;
|
import org.oscim.core.BoundingBox;
|
||||||
import org.oscim.core.GeoPoint;
|
import org.oscim.core.GeoPoint;
|
||||||
import org.oscim.layers.marker.MarkerItem.HotspotPlace;
|
|
||||||
import org.oscim.layers.marker.MarkerSymbol;
|
import org.oscim.layers.marker.MarkerSymbol;
|
||||||
|
import org.oscim.layers.marker.MarkerSymbol.HotspotPlace;
|
||||||
import org.oscim.map.Map;
|
import org.oscim.map.Map;
|
||||||
import org.osmdroid.location.FlickrPOIProvider;
|
import org.osmdroid.location.FlickrPOIProvider;
|
||||||
import org.osmdroid.location.FourSquareProvider;
|
import org.osmdroid.location.FourSquareProvider;
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import android.widget.TextView;
|
|||||||
import org.oscim.android.canvas.AndroidGraphics;
|
import org.oscim.android.canvas.AndroidGraphics;
|
||||||
import org.oscim.core.GeoPoint;
|
import org.oscim.core.GeoPoint;
|
||||||
import org.oscim.layers.PathLayer;
|
import org.oscim.layers.PathLayer;
|
||||||
import org.oscim.layers.marker.MarkerItem.HotspotPlace;
|
|
||||||
import org.oscim.layers.marker.MarkerSymbol;
|
import org.oscim.layers.marker.MarkerSymbol;
|
||||||
|
import org.oscim.layers.marker.MarkerSymbol.HotspotPlace;
|
||||||
import org.osmdroid.location.GeocoderNominatim;
|
import org.osmdroid.location.GeocoderNominatim;
|
||||||
import org.osmdroid.overlays.DefaultInfoWindow;
|
import org.osmdroid.overlays.DefaultInfoWindow;
|
||||||
import org.osmdroid.overlays.ExtendedMarkerItem;
|
import org.osmdroid.overlays.ExtendedMarkerItem;
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ import org.oscim.map.Map;
|
|||||||
* @see ItemizedOverlayWithBubble
|
* @see ItemizedOverlayWithBubble
|
||||||
*/
|
*/
|
||||||
public class ExtendedMarkerItem extends MarkerItem {
|
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
|
// a third field that can be displayed in
|
||||||
// the infowindow, on a third line
|
// the infowindow, on a third line
|
||||||
// that will be shown in the infowindow.
|
// that will be shown in the infowindow.
|
||||||
@@ -36,19 +32,17 @@ public class ExtendedMarkerItem extends MarkerItem {
|
|||||||
|
|
||||||
public ExtendedMarkerItem(String aTitle, String aDescription, GeoPoint aGeoPoint) {
|
public ExtendedMarkerItem(String aTitle, String aDescription, GeoPoint aGeoPoint) {
|
||||||
super(aTitle, aDescription, aGeoPoint);
|
super(aTitle, aDescription, aGeoPoint);
|
||||||
mTitle = aTitle;
|
|
||||||
mDescription = aDescription;
|
|
||||||
mSubDescription = null;
|
mSubDescription = null;
|
||||||
mImage = null;
|
mImage = null;
|
||||||
mRelatedObject = null;
|
mRelatedObject = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String aTitle) {
|
public void setTitle(String aTitle) {
|
||||||
mTitle = aTitle;
|
title = aTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String aDescription) {
|
public void setDescription(String aDescription) {
|
||||||
mDescription = aDescription;
|
description = aDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubDescription(String aSubDescription) {
|
public void setSubDescription(String aSubDescription) {
|
||||||
@@ -63,13 +57,8 @@ public class ExtendedMarkerItem extends MarkerItem {
|
|||||||
mRelatedObject = o;
|
mRelatedObject = o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTitle() {
|
|
||||||
return mTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return mDescription;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSubDescription() {
|
public String getSubDescription() {
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import org.oscim.tiling.source.bitmap.DefaultSources;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.oscim.layers.marker.MarkerSymbol.HotspotPlace;
|
||||||
|
|
||||||
public class MarkerLayerTest extends GdxMapApp implements ItemizedLayer.OnItemGestureListener<MarkerItem> {
|
public class MarkerLayerTest extends GdxMapApp implements ItemizedLayer.OnItemGestureListener<MarkerItem> {
|
||||||
|
|
||||||
private static final boolean BILLBOARDS = true;
|
private static final boolean BILLBOARDS = true;
|
||||||
@@ -44,15 +46,15 @@ public class MarkerLayerTest extends GdxMapApp implements ItemizedLayer.OnItemGe
|
|||||||
Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png"));
|
Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png"));
|
||||||
MarkerSymbol symbol;
|
MarkerSymbol symbol;
|
||||||
if (BILLBOARDS)
|
if (BILLBOARDS)
|
||||||
symbol = new MarkerSymbol(bitmapPoi, MarkerItem.HotspotPlace.BOTTOM_CENTER);
|
symbol = new MarkerSymbol(bitmapPoi, HotspotPlace.BOTTOM_CENTER);
|
||||||
else
|
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"));
|
Bitmap bitmapFocus = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_focus.png"));
|
||||||
if (BILLBOARDS)
|
if (BILLBOARDS)
|
||||||
mFocusMarker = new MarkerSymbol(bitmapFocus, MarkerItem.HotspotPlace.BOTTOM_CENTER);
|
mFocusMarker = new MarkerSymbol(bitmapFocus, HotspotPlace.BOTTOM_CENTER);
|
||||||
else
|
else
|
||||||
mFocusMarker = new MarkerSymbol(bitmapFocus, MarkerItem.HotspotPlace.CENTER, false);
|
mFocusMarker = new MarkerSymbol(bitmapFocus, HotspotPlace.CENTER, false);
|
||||||
|
|
||||||
ItemizedLayer<MarkerItem> markerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this);
|
ItemizedLayer<MarkerItem> markerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this);
|
||||||
mMap.layers().add(markerLayer);
|
mMap.layers().add(markerLayer);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ItemizedLayer<Item extends MarkerItem> extends MarkerLayer<Item>
|
public class ItemizedLayer<Item extends MarkerInterface> extends MarkerLayer<Item>
|
||||||
implements GestureListener {
|
implements GestureListener {
|
||||||
|
|
||||||
static final Logger log = LoggerFactory.getLogger(ItemizedLayer.class);
|
static final Logger log = LoggerFactory.getLogger(ItemizedLayer.class);
|
||||||
@@ -267,12 +267,4 @@ public class ItemizedLayer<Item extends MarkerItem> extends MarkerLayer<Item>
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item getByUid(Object uid) {
|
|
||||||
for (Item it : mItemList)
|
|
||||||
if (it.getUid() == uid)
|
|
||||||
return it;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
23
vtm/src/org/oscim/layers/marker/MarkerInterface.java
Normal file
23
vtm/src/org/oscim/layers/marker/MarkerInterface.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.oscim.layers.marker;
|
||||||
|
|
||||||
|
import org.oscim.core.GeoPoint;
|
||||||
|
|
||||||
|
public interface MarkerInterface {
|
||||||
|
MarkerSymbol getMarker();
|
||||||
|
|
||||||
|
GeoPoint getPoint();
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2014 Hannes Janetzek
|
* Copyright 2014 Hannes Janetzek
|
||||||
* Copyright 2016 devemux86
|
* Copyright 2016 devemux86
|
||||||
|
* Copyright 2016 Erik Duisters
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@@ -27,24 +28,7 @@ import org.oscim.core.GeoPoint;
|
|||||||
/**
|
/**
|
||||||
* Immutable class describing a GeoPoint with a Title and a Description.
|
* Immutable class describing a GeoPoint with a Title and a Description.
|
||||||
*/
|
*/
|
||||||
public class MarkerItem {
|
public class MarkerItem implements MarkerInterface {
|
||||||
|
|
||||||
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 final Object uid;
|
public final Object uid;
|
||||||
public String title;
|
public String title;
|
||||||
public String description;
|
public String description;
|
||||||
@@ -78,10 +62,12 @@ public class MarkerItem {
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public GeoPoint getPoint() {
|
public GeoPoint getPoint() {
|
||||||
return geoPoint;
|
return geoPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public MarkerSymbol getMarker() {
|
public MarkerSymbol getMarker() {
|
||||||
return mMarker;
|
return mMarker;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import org.oscim.map.Map;
|
|||||||
* gets checked for onTap first. This class is generic, because you then you get
|
* gets checked for onTap first. This class is generic, because you then you get
|
||||||
* your custom item-class passed back in onTap(). << TODO
|
* your custom item-class passed back in onTap(). << TODO
|
||||||
*/
|
*/
|
||||||
public abstract class MarkerLayer<Item extends MarkerItem> extends Layer {
|
public abstract class MarkerLayer<Item extends MarkerInterface> extends Layer {
|
||||||
|
|
||||||
protected final MarkerRenderer mMarkerRenderer;
|
protected final MarkerRenderer mMarkerRenderer;
|
||||||
protected Item mFocusedItem;
|
protected Item mFocusedItem;
|
||||||
|
|||||||
@@ -19,9 +19,20 @@ package org.oscim.layers.marker;
|
|||||||
|
|
||||||
import org.oscim.backend.canvas.Bitmap;
|
import org.oscim.backend.canvas.Bitmap;
|
||||||
import org.oscim.core.PointF;
|
import org.oscim.core.PointF;
|
||||||
import org.oscim.layers.marker.MarkerItem.HotspotPlace;
|
|
||||||
|
|
||||||
public class MarkerSymbol {
|
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;
|
final Bitmap mBitmap;
|
||||||
/**
|
/**
|
||||||
* Hotspot offset
|
* Hotspot offset
|
||||||
|
|||||||
Reference in New Issue
Block a user