use of com.peterlaurence.trekadvisor.menu.mapview.components.MovableMarker in project TrekAdvisor by peterLaurence.
the class MarkerLayer method drawMarkers.
private void drawMarkers() {
mMarkers = mMap.getMarkers();
if (mMarkers == null)
return;
for (MarkerGson.Marker marker : mMarkers) {
MovableMarker movableMarker = new MovableMarker(mContext, true, marker);
if (mMap.getProjection() == null) {
movableMarker.setRelativeX(marker.lon);
movableMarker.setRelativeY(marker.lat);
} else {
movableMarker.setRelativeX(marker.proj_x);
movableMarker.setRelativeY(marker.proj_y);
}
movableMarker.initStatic();
mTileView.addMarker(movableMarker, movableMarker.getRelativeX(), movableMarker.getRelativeY(), -0.5f, -0.5f);
}
}
use of com.peterlaurence.trekadvisor.menu.mapview.components.MovableMarker in project TrekAdvisor by peterLaurence.
the class MarkerLayer method addNewMarker.
/**
* Add a {@link MovableMarker} to the center of the {@link TileView}.
*/
void addNewMarker() {
/* Calculate the relative coordinates of the center of the screen */
int x = mTileView.getScrollX() + mTileView.getWidth() / 2 - mTileView.getOffsetX();
int y = mTileView.getScrollY() + mTileView.getHeight() / 2 - mTileView.getOffsetY();
CoordinateTranslater coordinateTranslater = mTileView.getCoordinateTranslater();
final double relativeX = coordinateTranslater.translateAndScaleAbsoluteToRelativeX(x, mTileView.getScale());
final double relativeY = coordinateTranslater.translateAndScaleAbsoluteToRelativeY(y, mTileView.getScale());
final MovableMarker movableMarker;
/* Create a new marker and add it to the map */
MarkerGson.Marker newMarker = new MarkerGson.Marker();
if (mMap.getProjection() == null) {
newMarker.lat = relativeY;
newMarker.lon = relativeX;
} else {
newMarker.proj_x = relativeX;
newMarker.proj_y = relativeY;
double[] wgs84Coords;
wgs84Coords = mMap.getProjection().undoProjection(relativeX, relativeY);
if (wgs84Coords != null) {
newMarker.lon = wgs84Coords[0];
newMarker.lat = wgs84Coords[1];
}
}
/* Create the corresponding view */
movableMarker = new MovableMarker(mContext, false, newMarker);
movableMarker.setRelativeX(relativeX);
movableMarker.setRelativeY(relativeY);
movableMarker.initRounded();
if (mMap != null) {
mMap.addMarker(newMarker);
}
/* Easily move the marker */
attachMarkerGrab(movableMarker, mTileView, mMap, mContext);
mTileView.addMarker(movableMarker, relativeX, relativeY, -0.5f, -0.5f);
}
use of com.peterlaurence.trekadvisor.menu.mapview.components.MovableMarker in project TrekAdvisor by peterLaurence.
the class MarkerLayer method setTileView.
private void setTileView(final TileView tileView) {
mTileView = tileView;
mTileView.setMarkerTapListener(new MarkerLayout.MarkerTapListener() {
@Override
public void onMarkerTap(View view, int x, int y) {
if (view instanceof MovableMarker) {
MovableMarker movableMarker = (MovableMarker) view;
/* Prepare the callout */
MarkerCallout markerCallout = new MarkerCallout(mContext);
markerCallout.setMoveAction(new MorphMarkerRunnable(movableMarker, markerCallout, mTileView, mContext, mMap));
markerCallout.setEditAction(new EditMarkerRunnable(movableMarker, MarkerLayer.this, markerCallout, mTileView, mRequestManageMarkerListener));
markerCallout.setDeleteAction(new DeleteMarkerRunnable(mParentView, movableMarker, markerCallout, tileView, mMap));
MarkerGson.Marker marker = movableMarker.getMarker();
markerCallout.setTitle(marker.name);
markerCallout.setSubTitle(marker.lat, marker.lon);
mTileView.addCallout(markerCallout, movableMarker.getRelativeX(), movableMarker.getRelativeY(), -0.5f, -1.2f);
markerCallout.transitionIn();
}
}
});
}
Aggregations