Java Code Examples for org.osmdroid.bonuspack.overlays.Polyline

The following are top voted examples for showing how to use org.osmdroid.bonuspack.overlays.Polyline. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: OPFMaps   File: ConvertUtils.java View source code 8 votes vote down vote up
@NonNull
public static Polyline convertPolylineOptions(@NonNull final Context context,
                                              @NonNull final OPFPolylineOptions options) {
    final Polyline polyline = new Polyline(context);
    polyline.setColor(options.getColor());
    polyline.setGeodesic(options.isGeodesic());
    polyline.setVisible(options.isVisible());
    polyline.setWidth(options.getWidth());

    final List<OPFLatLng> opfPoints = options.getPoints();
    if (!opfPoints.isEmpty()) {
        final List<GeoPoint> points = new ArrayList<>(opfPoints.size());
        for (OPFLatLng opfPoint : opfPoints) {
            points.add(new GeoPoint(opfPoint.getLat(), opfPoint.getLng()));
        }
        polyline.setPoints(points);
    }

    return polyline;
}
 
Example 2
Project: OPFMaps   File: OsmdroidMapDelegate.java View source code 6 votes vote down vote up
@NonNull
@Override
public OPFPolyline addPolyline(@NonNull final OPFPolylineOptions options) {
    final Polyline polyline = ConvertUtils.convertPolylineOptions(map.getContext(), options);
    map.getOverlays().add(polyline);
    map.invalidate();
    return new OPFPolyline(new OsmdroidPolylineDelegate(map, polyline));
}
 
Example 3
Project: OPFMaps   File: OsmdroidMapDelegate.java View source code 6 votes vote down vote up
@Override
public void clear() {
    final List<Overlay> overlays = map.getOverlays();

    for (Iterator<Overlay> it = overlays.iterator(); it.hasNext();) {
        final Overlay overlay = it.next();
        if (overlay instanceof Marker
                || overlay instanceof Polygon
                || overlay instanceof GroundOverlay
                || overlay instanceof Polyline) {
            it.remove();
        }
    }
    map.invalidate();
}
 
Example 4
Project: SmartNavi   File: KmlFolder.java View source code 6 votes vote down vote up
/** 
 * Converts the overlay to a KmlFeature and add it inside this. 
 * Conversion from Overlay subclasses to KML Features is as follow: <br>
 *   FolderOverlay, MarkerClusterer => Folder<br>
 *   Marker => Point<br>
 *   Polygon => Polygon<br>
 *   Polyline => LineString<br>
 *   GroundOverlay => GroundOverlay<br>
 *   Else, add nothing. 
 * @param overlay to convert and add
 * @param kmlDoc for style handling. 
 * @return true if OK, false if the overlay has not been added. 
 */
public boolean addOverlay(Overlay overlay, KmlDocument kmlDoc){
	if (overlay == null)
		return false;
	KmlFeature kmlItem;
	if (overlay instanceof GroundOverlay){
		kmlItem = new KmlGroundOverlay((GroundOverlay)overlay);
	} else if (overlay instanceof FolderOverlay){
		kmlItem = new KmlFolder((FolderOverlay)overlay, kmlDoc);
	} else if (overlay instanceof MarkerClusterer){
		kmlItem = new KmlFolder((MarkerClusterer)overlay, kmlDoc);
	} else if (overlay instanceof Marker){
		Marker marker = (Marker)overlay;
		kmlItem = new KmlPlacemark(marker);
	} else if (overlay instanceof Polygon){
		Polygon polygon = (Polygon)overlay;
		kmlItem = new KmlPlacemark(polygon, kmlDoc);
	} else if (overlay instanceof Polyline){
		Polyline polyline = (Polyline)overlay;
		kmlItem = new KmlPlacemark(polyline, kmlDoc);
	} else {
		return false;
	}
	mItems.add(kmlItem);
	return true;
}
 
Example 5
Project: SmartNavi   File: KmlLineString.java View source code 6 votes vote down vote up
public void applyDefaultStyling(Polyline lineStringOverlay, Style defaultStyle, KmlPlacemark kmlPlacemark,
		KmlDocument kmlDocument){
	Style style = kmlDocument.getStyle(kmlPlacemark.mStyle);
	if (style != null){
		lineStringOverlay.setPaint(style.getOutlinePaint());
	} else if (defaultStyle!=null && defaultStyle.mLineStyle!=null){ 
		lineStringOverlay.setPaint(defaultStyle.getOutlinePaint());
	}
	lineStringOverlay.setEnabled(kmlPlacemark.mVisibility);
}
 
Example 6
Project: SmartNavi   File: KmlLineString.java View source code 6 votes vote down vote up
/** Build the corresponding Polyline overlay */	
@Override public Overlay buildOverlay(MapView map, Style defaultStyle, Styler styler, KmlPlacemark kmlPlacemark, 
		KmlDocument kmlDocument){
	Context context = map.getContext();
	Polyline lineStringOverlay = new Polyline(context);
	lineStringOverlay.setPoints(mCoordinates);
	if (styler != null)
		styler.onLineString(lineStringOverlay, kmlPlacemark, this);
	else {
		applyDefaultStyling(lineStringOverlay, defaultStyle, kmlPlacemark, kmlDocument);
	}
	return lineStringOverlay;
}
 
Example 7
Project: SmartNavi   File: KmlPlacemark.java View source code 6 votes vote down vote up
/** constructs a Placemark from a Polyline overlay, as a KML LineString */
public KmlPlacemark(Polyline polyline, KmlDocument kmlDoc){
	this();
	mName = "LineString - "+polyline.getNumberOfPoints()+" points";
	mGeometry = new KmlLineString();
	mGeometry.mCoordinates = (ArrayList<GeoPoint>)polyline.getPoints();
	mVisibility = polyline.isEnabled();
	//Style:
	Style style = new Style();
	style.mLineStyle = new LineStyle(polyline.getColor(), polyline.getWidth());
	mStyle = kmlDoc.addStyle(style);
}
 
Example 8
Project: SmartNavi   File: RoadManager.java View source code 6 votes vote down vote up
/**
 * Using the road high definition shape, builds and returns a Polyline. 
 * @param road
 * @param color
 * @param width
 * @param context
 */
public static Polyline buildRoadOverlay(Road road, int color, float width, Context context){
	Polyline roadOverlay = new Polyline(context);
	roadOverlay.setColor(color);
	roadOverlay.setWidth(width);
	if (road != null) {
		ArrayList<GeoPoint> polyline = road.mRouteHigh;
		roadOverlay.setPoints(polyline);
	}
	return roadOverlay;
}
 
Example 9
Project: osmbonuspack   File: MapActivity.java View source code 6 votes vote down vote up
void updateUIWithRoads(Road[] roads){
mRoadNodeMarkers.getItems().clear();
TextView textView = (TextView)findViewById(R.id.routeInfo);
textView.setText("");
List<Overlay> mapOverlays = map.getOverlays();
if (mRoadOverlays != null){
	for (int i=0; i<mRoadOverlays.length; i++)
		mapOverlays.remove(mRoadOverlays[i]);
	mRoadOverlays = null;
}
if (roads == null)
	return;
if (roads[0].mStatus == Road.STATUS_TECHNICAL_ISSUE)
	Toast.makeText(map.getContext(), "Technical issue when getting the route", Toast.LENGTH_SHORT).show();
else if (roads[0].mStatus > Road.STATUS_TECHNICAL_ISSUE) //functional issues
	Toast.makeText(map.getContext(), "No possible route here", Toast.LENGTH_SHORT).show();
mRoadOverlays = new Polyline[roads.length];
for (int i=0; i<roads.length; i++) {
	Polyline roadPolyline = RoadManager.buildRoadOverlay(roads[i], this);
	mRoadOverlays[i] = roadPolyline;
	if (mWhichRouteProvider == GRAPHHOPPER_BICYCLE || mWhichRouteProvider == GRAPHHOPPER_PEDESTRIAN) {
		Paint p = roadPolyline.getPaint();
		p.setPathEffect(new DashPathEffect(new float[]{10, 5}, 0));
	}
	String routeDesc = roads[i].getLengthDurationText(-1);
	roadPolyline.setTitle(getString(R.string.route) + " - " + routeDesc);
	roadPolyline.setInfoWindow(new BasicInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, map));
	roadPolyline.setRelatedObject(i);
	roadPolyline.setOnClickListener(new RoadOnClickListener());
	mapOverlays.add(1, roadPolyline);
	//we insert the road overlays at the "bottom", just above the MapEventsOverlay,
	//to avoid covering the other overlays. 
}
selectRoad(0);
  }
 
Example 10
Project: osmbonuspack   File: KmlFolder.java View source code 6 votes vote down vote up
/** 
 * Converts the overlay to a KmlFeature and add it inside this. 
 * Conversion from Overlay subclasses to KML Features is as follow: <br>
 *   FolderOverlay, MarkerClusterer => Folder<br>
 *   Marker => Point<br>
 *   Polygon => Polygon<br>
 *   Polyline => LineString<br>
 *   GroundOverlay => GroundOverlay<br>
 *   Else, add nothing. 
 * @param overlay to convert and add
 * @param kmlDoc for style handling. 
 * @return true if OK, false if the overlay has not been added. 
 */
public boolean addOverlay(Overlay overlay, KmlDocument kmlDoc){
	if (overlay == null)
		return false;
	KmlFeature kmlItem;
	if (overlay instanceof GroundOverlay){
		kmlItem = new KmlGroundOverlay((GroundOverlay)overlay);
	} else if (overlay instanceof FolderOverlay){
		kmlItem = new KmlFolder((FolderOverlay)overlay, kmlDoc);
	} else if (overlay instanceof MarkerClusterer){
		kmlItem = new KmlFolder((MarkerClusterer)overlay, kmlDoc);
	} else if (overlay instanceof Marker){
		Marker marker = (Marker)overlay;
		kmlItem = new KmlPlacemark(marker);
	} else if (overlay instanceof Polygon){
		Polygon polygon = (Polygon)overlay;
		kmlItem = new KmlPlacemark(polygon, kmlDoc);
	} else if (overlay instanceof Polyline){
		Polyline polyline = (Polyline)overlay;
		kmlItem = new KmlPlacemark(polyline, kmlDoc);
	} else {
		return false;
	}
	mItems.add(kmlItem);
	return true;
}
 
Example 11
Project: osmbonuspack   File: KmlLineString.java View source code 6 votes vote down vote up
public void applyDefaultStyling(Polyline lineStringOverlay, Style defaultStyle, KmlPlacemark kmlPlacemark,
		KmlDocument kmlDocument, MapView map){
	Context context = map.getContext();
	Style style = kmlDocument.getStyle(kmlPlacemark.mStyle);
	if (style != null){
		lineStringOverlay.setColor(style.getOutlinePaint().getColor());
		lineStringOverlay.setWidth(style.getOutlinePaint().getStrokeWidth());
	} else if (defaultStyle!=null && defaultStyle.mLineStyle!=null){ 
		lineStringOverlay.setColor(defaultStyle.getOutlinePaint().getColor());
		lineStringOverlay.setWidth(defaultStyle.getOutlinePaint().getStrokeWidth());
	}
	if ((kmlPlacemark.mName!=null && !"".equals(kmlPlacemark.mName)) 
			|| (kmlPlacemark.mDescription!=null && !"".equals(kmlPlacemark.mDescription))
			|| (lineStringOverlay.getSubDescription()!=null && !"".equals(lineStringOverlay.getSubDescription()))
			){
		if (mDefaultLayoutResId == BonusPackHelper.UNDEFINED_RES_ID){
			String packageName = context.getPackageName();
			mDefaultLayoutResId = context.getResources().getIdentifier("layout/bonuspack_bubble", null, packageName);
		}
		lineStringOverlay.setInfoWindow(new BasicInfoWindow(mDefaultLayoutResId, map));
	}
	lineStringOverlay.setEnabled(kmlPlacemark.mVisibility);
}
 
Example 12
Project: osmbonuspack   File: KmlLineString.java View source code 6 votes vote down vote up
/** Build the corresponding Polyline overlay */	
@Override public Overlay buildOverlay(MapView map, Style defaultStyle, Styler styler, KmlPlacemark kmlPlacemark, 
		KmlDocument kmlDocument){
	Context context = map.getContext();
	Polyline lineStringOverlay = new Polyline(context);
	lineStringOverlay.setPoints(mCoordinates);
	lineStringOverlay.setTitle(kmlPlacemark.mName);
	lineStringOverlay.setSnippet(kmlPlacemark.mDescription);
	lineStringOverlay.setSubDescription(kmlPlacemark.getExtendedDataAsText());
	if (styler != null)
		styler.onLineString(lineStringOverlay, kmlPlacemark, this);
	else {
		applyDefaultStyling(lineStringOverlay, defaultStyle, kmlPlacemark, kmlDocument, map);
	}
	return lineStringOverlay;
}
 
Example 13
Project: osmbonuspack   File: KmlPlacemark.java View source code 6 votes vote down vote up
/** constructs a Placemark from a Polyline overlay, as a KML LineString */
public KmlPlacemark(Polyline polyline, KmlDocument kmlDoc){
	this();
	mName = polyline.getTitle();
	mDescription = polyline.getSnippet();
	mGeometry = new KmlLineString();
	mGeometry.mCoordinates = (ArrayList<GeoPoint>)polyline.getPoints();
	mVisibility = polyline.isEnabled();
	//Style:
	Style style = new Style();
	style.mLineStyle = new LineStyle(polyline.getColor(), polyline.getWidth());
	mStyle = kmlDoc.addStyle(style);
}
 
Example 14
Project: osmbonuspack   File: RoadManager.java View source code 6 votes vote down vote up
/**
 * Using the road high definition shape, builds and returns a Polyline. 
 * @param road
 * @param color
 * @param width
 * @param context
 */
public static Polyline buildRoadOverlay(Road road, int color, float width, Context context){
	Polyline roadOverlay = new Polyline(context);
	roadOverlay.setColor(color);
	roadOverlay.setWidth(width);
	if (road != null) {
		ArrayList<GeoPoint> polyline = road.mRouteHigh;
		roadOverlay.setPoints(polyline);
	}
	return roadOverlay;
}
 
Example 15
Project: osmbonuspack   File: MainActivity.java View source code 6 votes vote down vote up
OnMarkerDragListenerDrawer() {
	mTrace = new ArrayList<GeoPoint>(100);
	mPolyline = new Polyline(map.getContext());
	mPolyline.setColor(0xAA0000FF);
	mPolyline.setWidth(2.0f);
	mPolyline.setGeodesic(true);
	map.getOverlays().add(mPolyline);
}
 
Example 16
Project: Data4All   File: D4AMapView.java View source code 6 votes vote down vote up
/**
 * Adds an Path as an Overlay to the Map.
 *
 * @param ctx
 *            The invoking Activity
 * @param polyElement
 *            the path which should be added to the map
 * @param edit
 *            is the Element editable
 **/
private void addPathToMap(AbstractActivity ctx, PolyElement polyElement,
        boolean edit) {
    final Polyline path = new MapLine(ctx, this, polyElement);

    Log.i(TAG, "Set Path Points to " + polyElement.toString());
    path.setPoints(polyElement.getGeoPoints());

    if (edit) {
        // set the polygon to editable
        ((MapLine) path).setEditable(true);
        // set the original points to calculate the offset of all points
        ((MapLine) path).setOriginalPoints();
        Log.i(TAG, "Set Path Color to " + MARKED_STROKE_COLOR);
        path.setColor(MARKED_STROKE_COLOR);
    } else {
        Log.i(TAG, "Set Path Color to " + DEFAULT_STROKE_COLOR);
        path.setColor(DEFAULT_STROKE_COLOR);
    }
    Log.i(TAG, "Set Path Width to " + DEFAULT_STROKE_WIDTH);
    path.setWidth(DEFAULT_STROKE_WIDTH);

    this.getOverlays().add(path);
    this.postInvalidate();
}
 
Example 17
Project: Data4All   File: D4AMapView.java View source code 6 votes vote down vote up
/**
 * Draw a given track as a polyline and adds it to the overlays
 * @author sbollen
 * @author sbrede
 * @param ctx The context
 * @param track The track which should be drawn
 */
public void addGPSTrackToMap(AbstractActivity ctx, Track track) {
    if (viewTrack() && track != null && !track.getTrackPoints().isEmpty()) {
        final Polyline trackPath = new MapTrack(ctx, this, track);

        Log.i(TAG, "Set Path Points to " + track.toString());
        trackPath.setPoints(track.getTrackGeoPoints());

        Log.i(TAG, "Set Path Color to " + Color.MAGENTA);
        trackPath.setColor(Color.MAGENTA);
        Log.i(TAG, "Set Path Width to " + DEFAULT_STROKE_WIDTH);
        trackPath.setWidth(4.0f);

        this.getOverlays().add(trackPath);
        this.postInvalidate();
    }

}
 
Example 18
Project: osmbonuspack   File: MainActivity.java View source code 5 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {

		//Disable StrictMode.ThreadPolicy to perform network calls in the UI thread.
		//Yes, it's not the good practice, but this is just a tutorial!
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		StrictMode.setThreadPolicy(policy);

		//Introduction
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		map = (MapView) findViewById(R.id.map);
		map.setBuiltInZoomControls(true);
		map.setMultiTouchControls(true);
		GeoPoint startPoint = new GeoPoint(48.13, -1.63);
		IMapController mapController = map.getController();
		mapController.setZoom(10);
		mapController.setCenter(startPoint);

		//0. Using the Marker overlay
		Marker startMarker = new Marker(map);
		startMarker.setPosition(startPoint);
		startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
		startMarker.setTitle("Start point");
		//startMarker.setIcon(getResources().getDrawable(R.drawable.marker_kml_point).mutate());
		//startMarker.setImage(getResources().getDrawable(R.drawable.ic_launcher));
		//startMarker.setInfoWindow(new MarkerInfoWindow(R.layout.bonuspack_bubble_black, map));
		startMarker.setDraggable(true);
		startMarker.setOnMarkerDragListener(new OnMarkerDragListenerDrawer());
		map.getOverlays().add(startMarker);
		
		//1. "Hello, Routing World"
		RoadManager roadManager = new OSRMRoadManager();
		//2. Playing with the RoadManager
		//roadManager roadManager = new MapQuestRoadManager("YOUR_API_KEY");
		//roadManager.addRequestOption("routeType=bicycle");
		ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
		waypoints.add(startPoint);
		GeoPoint endPoint = new GeoPoint(48.4, -1.9);
		waypoints.add(endPoint);
		Road road = roadManager.getRoad(waypoints);
		if (road.mStatus != Road.STATUS_OK)
			Toast.makeText(this, "Error when loading the road - status="+road.mStatus, Toast.LENGTH_SHORT).show();
		
		Polyline roadOverlay = RoadManager.buildRoadOverlay(road, this);
		map.getOverlays().add(roadOverlay);
		
		//3. Showing the Route steps on the map
		FolderOverlay roadMarkers = new FolderOverlay(this);
		map.getOverlays().add(roadMarkers);
		Drawable nodeIcon = getResources().getDrawable(R.drawable.marker_node);
		for (int i=0; i<road.mNodes.size(); i++){
			RoadNode node = road.mNodes.get(i);
			Marker nodeMarker = new Marker(map);
			nodeMarker.setPosition(node.mLocation);
			nodeMarker.setIcon(nodeIcon);
			
			//4. Filling the bubbles
			nodeMarker.setTitle("Step "+i);
			nodeMarker.setSnippet(node.mInstructions);
			nodeMarker.setSubDescription(Road.getLengthDurationText(node.mLength, node.mDuration));
			Drawable iconContinue = getResources().getDrawable(R.drawable.ic_continue);
			nodeMarker.setImage(iconContinue);
			//4. end
			
			roadMarkers.add(nodeMarker);
		}
		
		//5. OpenStreetMap POIs with Nominatim
		NominatimPOIProvider poiProvider = new NominatimPOIProvider("OsmNavigator/1.0");
		ArrayList<POI> pois = poiProvider.getPOICloseTo(startPoint, "cinema", 50, 0.1);
		//or : ArrayList<POI> pois = poiProvider.getPOIAlong(road.getRouteLow(), "fuel", 50, 2.0);
		
		//6. Wikipedia POIs with GeoNames 
		/*
		GeoNamesPOIProvider poiProvider = new GeoNamesPOIProvider("mkergall");
		//BoundingBoxE6 bb = map.getBoundingBox();
		//ArrayList<POI> pois = poiProvider.getPOIInside(bb, 30);
		//=> not possible in onCreate, as map bounding box is not correct until a draw occurs (osmdroid issue). 
		ArrayList<POI> pois = poiProvider.getPOICloseTo(startPoint, 30, 20.0);
		*/
		
		//8. Quick overview of the Flickr and Picasa POIs */
		/*
		PicasaPOIProvider poiProvider = new PicasaPOIProvider(null);
		BoundingBoxE6 bb = BoundingBoxE6.fromGeoPoints(waypoints);
		ArrayList<POI> pois = poiProvider.getPOIInside(bb, 20, null);
		*/
		
		//FolderOverlay poiMarkers = new FolderOverlay(this);
		//10. Marker Clustering
		RadiusMarkerClusterer poiMarkers = new RadiusMarkerClusterer(this);
		//Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster);
		Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_poi_cluster);
		Bitmap clusterIcon = ((BitmapDrawable)clusterIconD).getBitmap();
		poiMarkers.setIcon(clusterIcon);
		//end of 10.
		//11. Customizing the clusters design
		poiMarkers.getTextPaint().setTextSize(12.0f);
		poiMarkers.mAnchorV = Marker.ANCHOR_BOTTOM;
		poiMarkers.mTextAnchorU = 0.70f;
		poiMarkers.mTextAnchorV = 0.27f;
		//end of 11.
		map.getOverlays().add(poiMarkers);
		Drawable poiIcon = getResources().getDrawable(R.drawable.marker_poi_default);
		if (pois != null) {
			for (POI poi:pois){
	            Marker poiMarker = new Marker(map);
	            poiMarker.setTitle(poi.mType);
	            poiMarker.setSnippet(poi.mDescription);
	            poiMarker.setPosition(poi.mLocation);
	            poiMarker.setIcon(poiIcon);
	            if (poi.mThumbnail != null){
	            	poiMarker.setImage(new BitmapDrawable(poi.mThumbnail));
	            }
				// 7.
				poiMarker.setInfoWindow(new CustomInfoWindow(map));
	            poiMarker.setRelatedObject(poi);
	            poiMarkers.add(poiMarker);
			}
		}

		//12. Loading KML content
		//String url = "http://mapsengine.google.com/map/kml?forcekml=1&mid=z6IJfj90QEd4.kUUY9FoHFRdE";
		mKmlDocument = new KmlDocument();
		//boolean ok = mKmlDocument.parseKMLUrl(url);

		//Get OpenStreetMap content as KML with Overpass API:
		OverpassAPIProvider overpassProvider = new OverpassAPIProvider();
		BoundingBoxE6 oBB = new BoundingBoxE6(startPoint.getLatitude()+0.25, startPoint.getLongitude()+0.25,
			startPoint.getLatitude()-0.25, startPoint.getLongitude()-0.25);
		String oUrl = overpassProvider.urlForTagSearchKml("highway=speed_camera", oBB, 500, 30);
		boolean ok = overpassProvider.addInKmlFolder(mKmlDocument.mKmlRoot, oUrl);
		
		if (ok){
			//13.1 Simple styling
			Drawable defaultMarker = getResources().getDrawable(R.drawable.marker_kml_point);
			Bitmap defaultBitmap = ((BitmapDrawable)defaultMarker).getBitmap();
			Style defaultStyle = new Style(defaultBitmap, 0x901010AA, 3.0f, 0x20AA1010);
			//13.2 Advanced styling with Styler
			KmlFeature.Styler styler = new MyKmlStyler(defaultStyle);
			
			FolderOverlay kmlOverlay = (FolderOverlay)mKmlDocument.mKmlRoot.buildOverlay(map, defaultStyle, styler, mKmlDocument);
			map.getOverlays().add(kmlOverlay);
			BoundingBoxE6 bb = mKmlDocument.mKmlRoot.getBoundingBox();
			if (bb != null){
				//map.zoomToBoundingBox(bb); => not working in onCreate - this is a well-known osmdroid bug. 
				//Workaround:
				map.getController().setCenter(bb.getCenter());
			}
		} else
			Toast.makeText(this, "Error when loading KML", Toast.LENGTH_SHORT).show();
		
		//14. Grab overlays in KML structure, save KML document locally
		if (mKmlDocument.mKmlRoot != null){
			KmlFolder root = (KmlFolder)mKmlDocument.mKmlRoot;
			root.addOverlay(roadOverlay, mKmlDocument);
			root.addOverlay(roadMarkers, mKmlDocument);
			mKmlDocument.saveAsKML(mKmlDocument.getDefaultPathForAndroid("my_route.kml"));
			//15. Loading and saving of GeoJSON content
			mKmlDocument.saveAsGeoJSON(mKmlDocument.getDefaultPathForAndroid("my_route.json"));
		}
		
		//16. Handling Map events
		MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this, this);
		map.getOverlays().add(0, mapEventsOverlay); //inserted at the "bottom" of all overlays
	}
 
Example 19
Project: smartnavi   File: OsmMapActivity.java View source code 5 votes vote down vote up
@Override
protected Polyline doInBackground(ArrayList<GeoPoint>... waypoints) {
    // old without pedestrian support
    // RoadManager roadManager = new OSRMRoadManager();
    RoadManager roadManager = new MapQuestRoadManager(Config.MAPQUEST_API_KEY);
    roadManager.addRequestOption("routeType=pedestrian");
    // retreive the road between those points:
    road = roadManager.getRoad(waypoints[0]);
    //build a Polyline with the route shape
    Polyline roadOverlay = RoadManager.buildRoadOverlay(road, OsmMapActivity.this);
    return roadOverlay;
}
 
Example 20
Project: smartnavi   File: OsmMapActivity.java View source code 5 votes vote down vote up
@Override
protected void onPostExecute(Polyline roadOverlay) {
    FolderOverlay myMarkersFolder = new FolderOverlay(OsmMapActivity.this);
    AbstractList<Overlay> list = myMarkersFolder.getItems();
    list.add(roadOverlay);

    showRouteInfo(false);

    //Show Route Steps on the map
    Drawable nodeIcon = getResources().getDrawable(R.drawable.finish2);
    for (int i = 0; i < road.mNodes.size(); i++) {
        RoadNode node = road.mNodes.get(i);
        Marker nodeMarker = new Marker(map);
        nodeMarker.setPosition(node.mLocation);
        nodeMarker.setIcon(nodeIcon);
        nodeMarker.setTitle("Step " + i);
        nodeMarker.setSnippet(node.mInstructions);
        nodeMarker.setSubDescription(Road.getLengthDurationText(node.mLength, node.mDuration));
        Drawable icon = getResources().getDrawable(R.drawable.ic_continue);
        if (node.mManeuverType == 1) {
            icon = getResources().getDrawable(R.drawable.ic_continue);
        } else if (node.mManeuverType == 3) {
            icon = getResources().getDrawable(R.drawable.ic_slight_left);
        } else if (node.mManeuverType == 4 || node.mManeuverType == 5) {
            icon = getResources().getDrawable(R.drawable.ic_turn_left);
        } else if (node.mManeuverType == 6) {
            icon = getResources().getDrawable(R.drawable.ic_slight_right);
        } else if (node.mManeuverType == 7 || node.mManeuverType == 8) {
            icon = getResources().getDrawable(R.drawable.ic_turn_right);
        } else if (node.mManeuverType == 24 || node.mManeuverType == 25 || node.mManeuverType == 26) {
            icon = getResources().getDrawable(R.drawable.ic_arrived);
        }
        nodeMarker.setImage(icon);
        nodeMarker.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker, MapView mapView) {
                marker.showInfoWindow();
                return true;
            }
        });

        //put into FolderOverlay list
        list.add(nodeMarker);
    }

    OverlayManager om = map.getOverlayManager();

    if (om.size() > 2) {
        om.remove(1);
        om.remove(1);
    } else {
        om.remove(1);
    }

    map.getOverlays().add(myMarkersFolder);
    setNewPositionMarker();
    map.invalidate();
}