本文整理汇总了Java中org.osmdroid.views.overlay.Polyline类的典型用法代码示例。如果您正苦于以下问题:Java Polyline类的具体用法?Java Polyline怎么用?Java Polyline使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Polyline类属于org.osmdroid.views.overlay包,在下文中一共展示了Polyline类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRoute
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
/**
* Create route on map
*
* @param fromLatitude Latitude to start drawing, users location
* @param fromLongitude Longitude to start drawing, users location
* @param toLatitude Latitude to end drawing
* @param toLongitude Longitude to end drawing
*/
private void createRoute(double fromLatitude, double fromLongitude, final double toLatitude, final double toLongitude) {
new RouteCreationTask(getActivity(), map, fromLatitude, fromLongitude, toLatitude, toLongitude, new PolylineCallback() {
@Override
public void onPolylineCreated(Polyline polyline) {
existingRoute = polyline;
//clear previously added marker
if (routeDestinationMarker != null)
map.getOverlays().remove(routeDestinationMarker);
//add destination marker if
routeDestinationMarker = MapUtils.addMarker(getActivity(), map, toLatitude, toLongitude);
if (getActivity() != null)
((MainActivity) getActivity()).routeAddedOnMap(routeDestinationMarker, existingRoute);
//start task to redraw the route ever 30 seconds, if no previous timer is set ont this route
if (routeUpdateTimer == null)
overrideRouteOnLocationChange();
}
@Override
public void onFailure() {
new AppToast(getActivity()).centerViewToast(getString(R.string.osm_routing_unavailable));
}
}).execute();
}
示例2: onSearchRouteResponse
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
@Override
public void onSearchRouteResponse(final Overlay overlay, final ServerResponse taskStatus) {
// actually plots the route on the map
if(taskStatus == ServerResponse.SUCCESS){
Polyline roadOverlay = (Polyline) overlay;
roadOverlay.setColor(ROUTE_LINE_COLORS.get(ROUTES_COUNTER));
roadOverlay.setWidth(10);
mapView.addOverlay(roadOverlay, OverlayTags.ROUTE);
ROUTES_COUNTER++;
}else if(taskStatus == ServerResponse.TIMEOUT){
Toast.makeText(context, getString(R.string.error_server_timeout), Toast.LENGTH_SHORT).show();
}else if (taskStatus == ServerResponse.CONNECTION_FAILED){
Toast.makeText(context, R.string.error_connection_failed, Toast.LENGTH_SHORT).show();
}else if(ROUTES_COUNTER == MAX_ROUTES){
Toast.makeText(context, R.string.msg_routes_limit, Toast.LENGTH_SHORT).show();
}
(getActivity().findViewById(R.id.progress_bar)).setVisibility(View.INVISIBLE);
}
示例3: setPolyline
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
public void setPolyline(Polyline newPolyline){
if (oldPolyline != null){
oldPolyline.remove();
}
if (newPolyline == null){
return;
}
PolylineOptions options = new PolylineOptions()
.color(newPolyline.getColor())
.visible(newPolyline.isVisible())
.width(newPolyline.getWidth())
;
for (GeoPoint p : newPolyline.getPoints()){
options.add(new LatLng(p.getLatitude(), p.getLongitude()));
}
oldPolyline = map.addPolyline(options);
}
示例4: calcRoute
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
/**
* Calculates a route from your start location to the next bus stop
*/
private void calcRoute()
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();//Strict mode for ignore NetworkOnMainExceptions (!for anytime, have to put in threading)
StrictMode.setThreadPolicy(policy);
ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>(); //Build up list of geopoints
waypoints.add(currenLocation);
GeoPoint endPoint = new GeoPoint(destinationLocation);
waypoints.add(endPoint);
Road road = roadManager.getRoad(waypoints);
double d = road.mDuration; // get duration
double x = road.mLength; // get length
String st_timeLeft = String.format("%s min", String.valueOf(myRound(d / 60,3)));//format string
String st_dist = String.valueOf(myRound(x * 1000,2)) + " m";
timeLeft.setText(st_timeLeft);
distGoal.setText(st_dist);
Polyline roadOverlay = RoadManager.buildRoadOverlay(road, Activity2.this);// draw route
mMapView.getOverlays().add(roadOverlay);
mMapView.invalidate();
}
示例5: calcRoute
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
/**
* Calulates a route from current destination to the next bus stop
*/
private void calcRoute()
{
ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
waypoints.add(currenLocation);
GeoPoint endPoint = new GeoPoint(destinationLocation);
waypoints.add(endPoint);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Road road = roadManager.getRoad(waypoints);
double d = road.mDuration;
double x = road.mLength;
Polyline roadOverlay = RoadManager.buildRoadOverlay(road, MainActivity.this);
mMapView.getOverlays().add(roadOverlay);
mMapView.invalidate();
}
示例6: add
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
protected void add(List<GeoPoint> points, int color) {
Polyline polyline = new Polyline();
polyline.setColor(color);
polyline.setPoints(points);
if (routes.isEmpty()){
initMarker.setPosition(points.get(0));
} else {
Marker marker = getInnerMarker();
marker.setPosition(points.get(0));
//markers.add(marker);
}
this.routes.add(polyline);
endMarker.setPosition(points.get(points.size()-1));
hideMarkers = false;
this.setDirty(true);
}
示例7: addOverlay
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
/**
* 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;
}
示例8: applyDefaultStyling
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
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);
}
示例9: buildOverlay
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
/** Build the corresponding overlay.
* Currently: a Polyline of gx:coords */
@Override public Overlay buildOverlay(MapView map, Style defaultStyle, Styler styler, KmlPlacemark kmlPlacemark,
KmlDocument kmlDocument){
Polyline lineStringOverlay = new Polyline();
lineStringOverlay.setGeodesic(true);
lineStringOverlay.setPoints(mCoordinates);
lineStringOverlay.setTitle(kmlPlacemark.mName);
lineStringOverlay.setSnippet(kmlPlacemark.mDescription);
lineStringOverlay.setSubDescription(kmlPlacemark.getExtendedDataAsText());
if (styler != null)
styler.onTrack(lineStringOverlay, kmlPlacemark, this);
else {
applyDefaultStyling(lineStringOverlay, defaultStyle, kmlPlacemark, kmlDocument, map);
}
return lineStringOverlay;
}
示例10: applyDefaultStyling
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
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);
}
示例11: buildOverlay
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
/** Build the corresponding Polyline overlay */
@Override public Overlay buildOverlay(MapView map, Style defaultStyle, Styler styler, KmlPlacemark kmlPlacemark,
KmlDocument kmlDocument){
Polyline lineStringOverlay = new Polyline();
lineStringOverlay.setGeodesic(true);
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;
}
示例12: toPolyline
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
/**
* Convert a {@link LineString} to a {@link PolylineOptions}
*
* @param lineString
* @return
*/
public Polyline toPolyline(LineString lineString) {
Polyline line = new Polyline();
if (polylineOptions!=null) {
line.setTitle(polylineOptions.getTitle());
line.setColor(polylineOptions.getColor());
line.setGeodesic(polylineOptions.isGeodesic());
line.setWidth(polylineOptions.getWidth());
line.setSubDescription(polygonOptions.getSubtitle());
}
List<GeoPoint> pts = new ArrayList<>();
for (Point point : lineString.getPoints()) {
GeoPoint latLng = toLatLng(point);
pts.add(latLng);
}
line.setPoints(pts);
return line;
}
示例13: onPostExecute
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
@Override
protected void onPostExecute(Road[] roads) {
double minLength = 0;
Road bestRoad = null;
roadList = roads;
if (roads == null)
return;
if (roads[0].mStatus == Road.STATUS_TECHNICAL_ISSUE) {
Toast.makeText(activity, "Technical issue when getting the route", Toast.LENGTH_SHORT).show();
} else if (roads[0].mStatus > Road.STATUS_TECHNICAL_ISSUE) { //functional issues
Toast.makeText(activity, "No possible route here", Toast.LENGTH_SHORT).show();
}
List<Overlay> mapOverlays = map.getOverlays();
for (Road road : roads) {
if(road.mLength < minLength || minLength == 0) {
minLength = road.mLength;
bestRoad = road;
}
}
String routeDesc = bestRoad.getLengthDurationText(activity, -1);
Polyline roadPolyline = RoadManager.buildRoadOverlay(bestRoad);
roadPolyline.setTitle(getString(R.string.app_name) + " - " + routeDesc);
roadPolyline.setInfoWindow(new BasicInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, map));
mapOverlays.add(0, roadPolyline);
map.invalidate();
}
示例14: onPostExecute
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
@Override
protected void onPostExecute(Road[] roads) {
double minLength = 0;
Road bestRoad = null;
roadList = roads;
if (roads == null)
return;
if (roads[0].mStatus == Road.STATUS_TECHNICAL_ISSUE) {
Toast.makeText(activity, "Technical issue when getting the route", Toast.LENGTH_SHORT).show();
} else if (roads[0].mStatus > Road.STATUS_TECHNICAL_ISSUE) { //functional issues
Toast.makeText(activity, "No possible route here", Toast.LENGTH_SHORT).show();
}
List<Overlay> mapOverlays = map.getOverlays();
for (Road road : roads) {
if(road.mLength < minLength || minLength == 0) {
minLength = road.mLength;
bestRoad = road;
}
}
String routeDesc = bestRoad.getLengthDurationText(activity, -1);
bundle.putDouble("distance", bestRoad.mLength);
bundle.putDouble("duration", bestRoad.mDuration);
Polyline roadPolyline = RoadManager.buildRoadOverlay(bestRoad);
roadPolyline.setTitle(getString(R.string.app_name) + " - " + routeDesc);
roadPolyline.setInfoWindow(new BasicInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, map));
mapOverlays.add(0, roadPolyline);
map.invalidate();
}
示例15: onPostExecute
import org.osmdroid.views.overlay.Polyline; //导入依赖的package包/类
@Override
protected void onPostExecute(Road[] roads) {
double minLength = 0;
Road bestRoad = null;
roadList = roads;
if (roads == null)
return;
if (roads[0].mStatus == Road.STATUS_TECHNICAL_ISSUE) {
Toast.makeText(activity, "Technical issue when getting the route", Toast.LENGTH_SHORT).show();
} else if (roads[0].mStatus > Road.STATUS_TECHNICAL_ISSUE) { //functional issues
Toast.makeText(activity, "No possible route here", Toast.LENGTH_SHORT).show();
}
List<Overlay> mapOverlays = map.getOverlays();
for (Road road : roads) {
if (road.mLength < minLength || minLength == 0) {
minLength = road.mLength;
bestRoad = road;
}
}
String routeDesc = bestRoad.getLengthDurationText(activity, -1);
Polyline roadPolyline = RoadManager.buildRoadOverlay(bestRoad);
roadPolyline.setTitle(getString(R.string.app_name) + " - " + routeDesc);
roadPolyline.setInfoWindow(new BasicInfoWindow(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, map));
mapOverlays.add(0, roadPolyline);
map.invalidate();
}