Search in sources :

Example 1 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MapActions method initSearchLocationHandler.

private void initSearchLocationHandler(final boolean isStartP, final boolean fromFavourite) {
    int viewID = R.id.map_nav_settings_to_search;
    if (isStartP) {
        viewID = R.id.map_nav_settings_from_search;
    }
    if (fromFavourite) {
        viewID = R.id.map_nav_settings_to_favorite;
        if (isStartP) {
            viewID = R.id.map_nav_settings_from_favorite;
        }
    }
    final ViewGroup pointItem = (ViewGroup) activity.findViewById(viewID);
    pointItem.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    setBgColor(pointItem, R.color.my_primary_light);
                    return true;
                case MotionEvent.ACTION_UP:
                    setBgColor(pointItem, R.color.my_primary);
                    Intent intent = new Intent(activity, GeocodeActivity.class);
                    OnClickAddressListener callbackListener = new OnClickAddressListener() {

                        @Override
                        public void onClick(Address addr) {
                            GeoPoint newPos = new GeoPoint(addr.getLatitude(), addr.getLongitude());
                            if (isStartP) {
                                Destination.getDestination().setStartPoint(newPos);
                                fromLocalET.setText(Destination.getDestination().getStartPointToString());
                                addFromMarker(Destination.getDestination().getStartPoint());
                                navSettingsFromVP.setVisibility(View.INVISIBLE);
                            } else {
                                Destination.getDestination().setEndPoint(newPos);
                                toLocalET.setText(Destination.getDestination().getEndPointToString());
                                addToMarker(Destination.getDestination().getEndPoint());
                                navSettingsToVP.setVisibility(View.INVISIBLE);
                            }
                            boolean showingNavigator = activeNavigator();
                            if (!showingNavigator) {
                                navSettingsVP.setVisibility(View.VISIBLE);
                            }
                            MapHandler.getMapHandler().centerPointOnMap(newPos, 0, 0, 0);
                        }
                    };
                    GeoPoint[] points = null;
                    if (fromFavourite) {
                        points = new GeoPoint[3];
                        points[0] = Destination.getDestination().getStartPoint();
                        points[1] = Destination.getDestination().getEndPoint();
                        Location curLoc = MapActivity.getmCurrentLocation();
                        if (curLoc != null) {
                            points[2] = new GeoPoint(curLoc.getLatitude(), curLoc.getLongitude());
                        }
                    }
                    GeocodeActivity.setPre(callbackListener, points);
                    activity.startActivity(intent);
                    return true;
            }
            return false;
        }
    });
}
Also used : GeoPoint(org.oscim.core.GeoPoint) Address(android.location.Address) ViewGroup(android.view.ViewGroup) OnClickAddressListener(com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener) Intent(android.content.Intent) MapView(org.oscim.android.MapView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) GeoPoint(org.oscim.core.GeoPoint) MotionEvent(android.view.MotionEvent) Location(android.location.Location)

Example 2 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MapActions method searchBtnActions.

/**
 * perform actions when search btn is clicked
 * <p>
 * 1. check edit text and convert value to start point or end point
 */
private void searchBtnActions() {
    String fls = fromLocalET.getText().toString();
    String tls = toLocalET.getText().toString();
    GeoPoint fl = null, tl = null;
    if (fls.length() > 2) {
        fl = MyUtility.getLatLong(fls);
    }
    if (tls.length() > 2) {
        tl = MyUtility.getLatLong(tls);
    }
    if (fl != null && tl == null) {
        MapHandler.getMapHandler().centerPointOnMap(fl, 0, 0, 0);
        Destination.getDestination().setStartPoint(fl);
        addFromMarker(fl);
    }
    if (fl == null && tl != null) {
        MapHandler.getMapHandler().centerPointOnMap(tl, 0, 0, 0);
        Destination.getDestination().setEndPoint(tl);
        addToMarker(tl);
    }
    if (fl != null && tl != null) {
        addFromMarker(fl);
        addToMarker(tl);
        Destination.getDestination().setStartPoint(fl);
        Destination.getDestination().setEndPoint(tl);
        activeNavigator();
    }
    if (fl == null && tl == null) {
        Toast.makeText(activity, "Check your input (use coordinates)!\nExample:\nuse degrees: 63° 25′ 47″ N, 10° 23′ 36″ " + "E\nor use digital: 63.429722, 10.393333", Toast.LENGTH_LONG).show();
    }
}
Also used : GeoPoint(org.oscim.core.GeoPoint)

Example 3 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MapActivity method onStop.

@Override
protected void onStop() {
    super.onStop();
    if (mCurrentLocation != null) {
        GeoPoint geoPoint = mapView.map().getMapPosition().getGeoPoint();
        Variable.getVariable().setLastLocation(geoPoint);
    // log("last browsed location : "+mapView.getModel().mapViewPosition
    // .getMapPosition().latLong);
    }
    if (mapView != null)
        Variable.getVariable().setLastZoomLevel(mapView.map().getMapPosition().getZoomLevel());
    Variable.getVariable().saveVariables();
}
Also used : GeoPoint(org.oscim.core.GeoPoint)

Example 4 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MapHandler method setStartEndPoint.

/**
 * Set start or end Point-Marker.
 *  @param p The Point to set, or null.
 *  @param isStart True for startpoint false for endpoint.
 *  @param recalculate True to calculate path, when booth points are set.
 *  @return Whether the path will be recalculated. *
 */
public boolean setStartEndPoint(GeoPoint p, boolean isStart, boolean recalculate) {
    boolean result = false;
    int icon = R.drawable.ic_location_end_24dp;
    boolean refreshBooth = false;
    if (startMarker != null && endMarker != null && p != null) {
        refreshBooth = true;
    }
    if (isStart) {
        startMarker = p;
        icon = R.drawable.ic_location_start_24dp;
    } else {
        endMarker = p;
    }
    // remove routing layers
    if ((startMarker == null || endMarker == null) || refreshBooth) {
        if (pathLayer != null) {
            pathLayer.clearPath();
        }
        itemizedLayer.removeAllItems();
    }
    if (refreshBooth) {
        itemizedLayer.addItem(createMarkerItem(startMarker, R.drawable.ic_location_start_24dp, 0.5f, 1.0f));
        itemizedLayer.addItem(createMarkerItem(endMarker, R.drawable.ic_location_end_24dp, 0.5f, 1.0f));
    } else if (p != null) {
        itemizedLayer.addItem(createMarkerItem(p, icon, 0.5f, 1.0f));
    }
    if (startMarker != null && endMarker != null && recalculate) {
        recalcPath();
        result = true;
    }
    mapView.map().updateMap(true);
    return result;
}
Also used : GeoPoint(org.oscim.core.GeoPoint)

Example 5 with GeoPoint

use of org.oscim.core.GeoPoint in project PocketMaps by junjunguo.

the class MapHandler method updatePathLayer.

private PathLayer updatePathLayer(PathLayer ref, PointList pointList, int color, int strokeWidth) {
    if (ref == null) {
        ref = createPathLayer(color, strokeWidth);
        mapView.map().layers().add(ref);
    }
    List<GeoPoint> geoPoints = new ArrayList<>();
    // TODO: Search for a more efficient way
    for (int i = 0; i < pointList.getSize(); i++) geoPoints.add(new GeoPoint(pointList.getLatitude(i), pointList.getLongitude(i)));
    ref.setPoints(geoPoints);
    return ref;
}
Also used : GeoPoint(org.oscim.core.GeoPoint) ArrayList(java.util.ArrayList) 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