Marker interface making marker handling more flexible
This commit is contained in:
parent
3703cf7e00
commit
7cdeacd1c2
@ -26,8 +26,8 @@ import org.oscim.core.GeoPoint;
|
||||
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 class MarkerOverlayActivity extends BitmapTileMapActivity
|
||||
|
||||
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);
|
||||
|
@ -26,8 +26,8 @@ import org.oscim.backend.CanvasAdapter;
|
||||
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;
|
||||
|
@ -27,8 +27,8 @@ import android.widget.Toast;
|
||||
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;
|
||||
|
@ -28,8 +28,8 @@ import android.widget.TextView;
|
||||
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;
|
||||
|
@ -21,10 +21,6 @@ import org.oscim.map.Map;
|
||||
* @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 class ExtendedMarkerItem extends MarkerItem {
|
||||
mRelatedObject = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return mDescription;
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getSubDescription() {
|
||||
|
@ -28,6 +28,8 @@ import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.oscim.layers.marker.MarkerSymbol.HotspotPlace;
|
||||
|
||||
public class MarkerLayerTest extends GdxMapApp implements ItemizedLayer.OnItemGestureListener<MarkerItem> {
|
||||
|
||||
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"));
|
||||
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<MarkerItem> markerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this);
|
||||
mMap.layers().add(markerLayer);
|
||||
|
@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemizedLayer<Item extends MarkerItem> extends MarkerLayer<Item>
|
||||
public class ItemizedLayer<Item extends MarkerInterface> extends MarkerLayer<Item>
|
||||
implements GestureListener {
|
||||
|
||||
static final Logger log = LoggerFactory.getLogger(ItemizedLayer.class);
|
||||
@ -267,12 +267,4 @@ public class ItemizedLayer<Item extends MarkerItem> extends MarkerLayer<Item>
|
||||
|
||||
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 2016 devemux86
|
||||
* Copyright 2016 Erik Duisters
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
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 class MarkerItem {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeoPoint getPoint() {
|
||||
return geoPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkerSymbol getMarker() {
|
||||
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
|
||||
* 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 Item mFocusedItem;
|
||||
|
@ -19,9 +19,20 @@ package org.oscim.layers.marker;
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user