Skip to content

Commit

Permalink
Update Maps API
Browse files Browse the repository at this point in the history
  • Loading branch information
mar-v-in committed Aug 6, 2015
1 parent 39a07ff commit 44f4bdc
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class BackendMap implements ItemizedLayer.OnItemGestureListener<MarkerIte

private final Context context;
private final MapView mapView;
private final LabelLayer labels;
private final BuildingLayer buildings;
private final VectorTileLayer baseLayer;
private final OSciMap4TileSource tileSource;
Expand All @@ -67,10 +68,10 @@ public BackendMap(Context context) {
tileSource.setCache(cache);
baseLayer = mapView.map().setBaseMap(tileSource);
Layers layers = mapView.map().layers();
layers.add(buildings = new BuildingLayer(mapView.map(), baseLayer));
layers.add(new LabelLayer(mapView.map(), baseLayer));
layers.add(labels = new LabelLayer(mapView.map(), baseLayer));
layers.add(items = new ItemizedLayer<MarkerItem>(mapView.map(), new MarkerSymbol(new AndroidBitmap(BitmapFactory
.decodeResource(ResourcesContainer.get(), R.drawable.nop)), 0.5F, 1)));
layers.add(buildings = new BuildingLayer(mapView.map(), baseLayer));
items.setOnItemGestureListener(this);
mapView.map().setTheme(VtmThemes.DEFAULT);
}
Expand Down Expand Up @@ -145,22 +146,30 @@ public void stopAnimation() {
}

public synchronized <T extends Markup> T add(T markup) {
switch (markup.getType()) {
case MARKER:
markupMap.put(markup.getId(), markup);
items.addItem(markup.getMarkerItem(context));
redraw();
break;
case LAYER:
Layers layers = mapView.map().layers();
layers.add(markup.getLayer(context, mapView.map()));
layers.remove(items);
layers.add(items);
redraw();
break;
default:
Log.d(TAG, "Unknown markup: " + markup);
}
if (markup != null && markup.getType() != null)
switch (markup.getType()) {
case MARKER:
markupMap.put(markup.getId(), markup);
items.addItem(markup.getMarkerItem(context));
redraw();
break;
case LAYER:
Layers layers = mapView.map().layers();
// TODO: better sorting code
layers.add(markup.getLayer(context, mapView.map()));
if (hasBuilding()) {
layers.remove(buildings);
layers.add(buildings);
}
layers.remove(items);
layers.add(items);
layers.remove(labels);
layers.add(labels);
redraw();
break;
default:
Log.d(TAG, "Unknown markup: " + markup);
}
return markup;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;

import org.oscim.core.BoundingBox;
import org.oscim.core.Box;
import org.oscim.core.GeoPoint;
import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection;

public class GmsMapsTypeHelper {
public static android.graphics.Point toPoint(org.oscim.core.Point in) {
Expand All @@ -36,9 +39,12 @@ public static LatLng toLatLng(GeoPoint geoPoint) {
return new LatLng(geoPoint.getLatitude(), geoPoint.getLongitude());
}

public static LatLngBounds toLatLngBounds(BoundingBox box) {
return new LatLngBounds(new LatLng(box.getMinLatitude(), box.getMinLongitude()),
new LatLng(box.getMaxLatitude(), box.getMaxLongitude()));
public static LatLngBounds toLatLngBounds(Box box) {
double minLon = MercatorProjection.toLongitude(box.xmin);
double maxLon = MercatorProjection.toLongitude(box.xmax);
double minLat = MercatorProjection.toLatitude(box.ymax);
double maxLat = MercatorProjection.toLatitude(box.ymin);
return new LatLngBounds(new LatLng(minLat, minLon), new LatLng(maxLat, maxLon));
}

public static org.oscim.core.Point fromPoint(android.graphics.Point point) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public class GoogleMapImpl extends IGoogleMapDelegate.Stub

private int markerCounter = 0;
private int circleCounter = 0;
private int polylineCounter = 0;
private int polygonCounter = 0;

private IOnMarkerClickListener onMarkerClickListener;

public GoogleMapImpl(LayoutInflater inflater, GoogleMapOptions options) {
Expand Down Expand Up @@ -115,6 +118,14 @@ private String getNextMarkerId() {
private String getNextCircleId() {
return "c" + circleCounter++;
}

private String getNextPolylineId() {
return "l" + polylineCounter++;
}

private String getNextPolygonId() {
return "p" + polygonCounter++;
}

/*
Camera
Expand Down Expand Up @@ -182,14 +193,13 @@ public ICircleDelegate addCircle(CircleOptions options) throws RemoteException {

@Override
public IPolylineDelegate addPolyline(PolylineOptions options) throws RemoteException {
Log.d(TAG, "not yet usable: addPolyline");
return new PolylineImpl(options); // TODO
Log.d(TAG, "addPolyline");
return backendMap.add(new PolylineImpl(getNextPolylineId(), options, this));
}

@Override
public IPolygonDelegate addPolygon(PolygonOptions options) throws RemoteException {
Log.d(TAG, "not yet usable: addPolygon");
return new PolygonImpl(options); // TODO
return backendMap.add(new PolygonImpl(getNextPolygonId(), options, this));
}

@Override
Expand Down Expand Up @@ -218,8 +228,10 @@ public void setInfoWindowAdapter(IInfoWindowAdapter adapter) throws RemoteExcept
@Override
public void clear() throws RemoteException {
backendMap.clear();
circleCounter = 0;
markerCounter = 0;
circleCounter = 0;
polylineCounter = 0;
polygonCounter = 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.microg.gms.maps;

import android.os.RemoteException;

import com.google.android.gms.dynamic.IObjectWrapper;
import com.google.android.gms.dynamic.ObjectWrapper;
import com.google.android.gms.maps.internal.IProjectionDelegate;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.VisibleRegion;

import org.oscim.core.Point;
import org.oscim.map.Viewport;

Expand Down Expand Up @@ -49,6 +51,6 @@ public IObjectWrapper toScreenLocation(LatLng latLng) throws RemoteException {

@Override
public VisibleRegion getVisibleRegion() throws RemoteException {
return new VisibleRegion(GmsMapsTypeHelper.toLatLngBounds(viewport.getBBox()));
return new VisibleRegion(GmsMapsTypeHelper.toLatLngBounds(viewport.getBBox(null, 0)));
}
}
Loading

0 comments on commit 44f4bdc

Please sign in to comment.