use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.
the class MapHandler method loadMap.
/**
* load map to mapView
*
* @param areaFolder
*/
public void loadMap(File areaFolder) {
logUser("loading map");
// Map events receiver
mapView.map().layers().add(new MapEventsReceiver(mapView.map()));
// Map file source
tileSource = new MapFileTileSource();
tileSource.setMapFile(new File(areaFolder, currentArea + ".map").getAbsolutePath());
VectorTileLayer l = mapView.map().setBaseMap(tileSource);
mapView.map().setTheme(VtmThemes.DEFAULT);
mapView.map().layers().add(new BuildingLayer(mapView.map(), l));
mapView.map().layers().add(new LabelLayer(mapView.map(), l));
// Markers layer
itemizedLayer = new ItemizedLayer<>(mapView.map(), (MarkerSymbol) null);
mapView.map().layers().add(itemizedLayer);
customLayer = new ItemizedLayer<>(mapView.map(), (MarkerSymbol) null);
mapView.map().layers().add(customLayer);
// Map position
GeoPoint mapCenter = tileSource.getMapInfo().boundingBox.getCenterPoint();
mapView.map().setMapPosition(mapCenter.getLatitude(), mapCenter.getLongitude(), 1 << 12);
// GuiMenu.getInstance().showMap(this);
// setContentView(mapView);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
activity.addContentView(mapView, params);
loadGraphStorage();
}
use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.
the class NaviDebugSimulator method startDebugSimulator.
/**
* The DEBUG_SIMULATOR will simulate first generated route on naviStart and trackingStart. *
*/
public void startDebugSimulator(final Activity activity, InstructionList instructions, boolean fromTracking) {
if (!DEBUG_SIMULATOR) {
return;
}
debug_simulator_from_tracking = fromTracking;
if (instructions == null) {
return;
}
if (debug_simulator_points == null) {
debug_simulator_points = new ArrayList<GeoPoint>();
for (Instruction ins : instructions) {
for (int i = 0; i < ins.getPoints().size(); i++) {
debug_simulator_points.add(new GeoPoint(ins.getPoints().getLat(i), ins.getPoints().getLon(i)));
}
}
}
final Location pLoc = new Location((String) null);
final Location lastLoc = new Location((String) null);
debug_simulator_run = true;
runDelayed(activity, pLoc, lastLoc, 0);
}
use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.
the class NaviDebugSimulator method runDelayed.
private void runDelayed(final Activity activity, final Location pLoc, final Location lastLoc, final int index) {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (debug_simulator_from_tracking && !Tracking.getTracking().isTracking()) {
debug_simulator_run = false;
}
if (!debug_simulator_run) {
return;
}
GeoPoint p = debug_simulator_points.get(index);
int newIndex = checkDistance(index, p);
p = checkP;
final MapActivity cur = ((MapActivity) activity);
pLoc.setLatitude(p.getLatitude());
pLoc.setLongitude(p.getLongitude());
float bearing = lastLoc.bearingTo(pLoc);
lastLoc.set(pLoc);
pLoc.setBearing(bearing);
pLoc.setSpeed(5.55f);
cur.onLocationChanged(pLoc);
log("Update position for Debug purpose! Lat=" + pLoc.getLatitude() + " Lon=" + pLoc.getLongitude());
if (debug_simulator_points.size() > newIndex) {
runDelayed(activity, pLoc, lastLoc, newIndex);
}
}
}, 2000);
}
use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.
the class NaviEngine method updatePosition.
@UiThread
public void updatePosition(Activity activity, Location pos) {
if (active == false) {
return;
}
if (uiJob == UiJob.RecalcPath) {
return;
}
if (this.pos == null) {
this.pos = new Location((String) null);
}
this.pos.set(pos);
GeoPoint curPos = new GeoPoint(pos.getLatitude(), pos.getLongitude());
GeoPoint newCenter = curPos.destinationPoint(70.0 * tiltMultPos, pos.getBearing());
MapHandler.getMapHandler().centerPointOnMap(newCenter, BEST_NAVI_ZOOM, 360.0f - pos.getBearing(), 45.0f * tiltMult);
calculatePositionAsync(curPos);
}
use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.
the class NaviEngine method getNearestPoint.
private static PointPosData getNearestPoint(Instruction instruction, int curPointPos, GeoPoint curPos) {
int nextPointPos = curPointPos;
int nearestPointPos = curPointPos;
double nearestDist = Double.MAX_VALUE;
while (instruction.getPoints().size() > nextPointPos) {
double lat = instruction.getPoints().getLatitude(nextPointPos);
double lon = instruction.getPoints().getLongitude(nextPointPos);
double dist = GeoMath.fastDistance(curPos.getLatitude(), curPos.getLongitude(), lat, lon);
if (dist < nearestDist) {
nearestDist = dist;
nearestPointPos = nextPointPos;
}
nextPointPos++;
}
PointPosData p = new PointPosData();
p.arrPos = nearestPointPos;
p.distance = nearestDist;
return p;
}
Aggregations