Search in sources :

Example 21 with GeoPoint

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();
}
Also used : LabelLayer(org.oscim.layers.tile.vector.labeling.LabelLayer) GeoPoint(org.oscim.core.GeoPoint) MarkerSymbol(org.oscim.layers.marker.MarkerSymbol) VectorTileLayer(org.oscim.layers.tile.vector.VectorTileLayer) ViewGroup(android.view.ViewGroup) BuildingLayer(org.oscim.layers.tile.buildings.BuildingLayer) File(java.io.File) MapFileTileSource(org.oscim.tiling.source.mapfile.MapFileTileSource)

Example 22 with GeoPoint

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);
}
Also used : GeoPoint(org.oscim.core.GeoPoint) Instruction(com.graphhopper.util.Instruction) GeoPoint(org.oscim.core.GeoPoint) Location(android.location.Location)

Example 23 with GeoPoint

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);
}
Also used : GeoPoint(org.oscim.core.GeoPoint) Handler(android.os.Handler) MapActivity(com.junjunguo.pocketmaps.activities.MapActivity)

Example 24 with GeoPoint

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);
}
Also used : GeoPoint(org.oscim.core.GeoPoint) Location(android.location.Location) UiThread(android.support.annotation.UiThread)

Example 25 with GeoPoint

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;
}
Also used : GeoPoint(org.oscim.core.GeoPoint)

Aggregations

GeoPoint (org.oscim.core.GeoPoint)25 File (java.io.File)5 RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)4 Location (android.location.Location)3 ViewGroup (android.view.ViewGroup)3 TextView (android.widget.TextView)3 Instruction (com.graphhopper.util.Instruction)3 ArrayList (java.util.ArrayList)3 MapView (org.oscim.android.MapView)3 MarkerSymbol (org.oscim.layers.marker.MarkerSymbol)3 Address (android.location.Address)2 MotionEvent (android.view.MotionEvent)2 IOException (java.io.IOException)2 BuildingLayer (org.oscim.layers.tile.buildings.BuildingLayer)2 VectorTileLayer (org.oscim.layers.tile.vector.VectorTileLayer)2 LabelLayer (org.oscim.layers.tile.vector.labeling.LabelLayer)2 MapFileTileSource (org.oscim.tiling.source.mapfile.MapFileTileSource)2 Intent (android.content.Intent)1