use of net.osmand.plus.views.RulerControlLayer in project Osmand by osmandapp.
the class MapActivityLayers method createLayers.
public void createLayers(final OsmandMapTileView mapView) {
OsmandApplication app = getApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
// first create to make accessible
mapTextLayer = new MapTextLayer();
// 5.95 all labels
mapView.addLayer(mapTextLayer, 5.95f);
// 8. context menu layer
contextMenuLayer = new ContextMenuLayer(activity);
mapView.addLayer(contextMenuLayer, 8);
// mapView.addLayer(underlayLayer, -0.5f);
mapTileLayer = new MapTileLayer(true);
mapView.addLayer(mapTileLayer, 0.0f);
mapView.setMainLayer(mapTileLayer);
// 0.5 layer
mapVectorLayer = new MapVectorLayer(mapTileLayer, false);
mapView.addLayer(mapVectorLayer, 0.5f);
downloadedRegionsLayer = new DownloadedRegionsLayer();
mapView.addLayer(downloadedRegionsLayer, 0.5f);
// 0.9 gpx layer
gpxLayer = new GPXLayer();
mapView.addLayer(gpxLayer, 0.9f);
// 1. route layer
routeLayer = new RouteLayer(routingHelper);
mapView.addLayer(routeLayer, 1);
// 2. osm bugs layer
// 3. poi layer
poiMapLayer = new POIMapLayer(activity);
mapView.addLayer(poiMapLayer, 3);
// 4. favorites layer
mFavouritesLayer = new FavouritesLayer();
mapView.addLayer(mFavouritesLayer, 4);
// 4.6 measurement tool layer
measurementToolLayer = new MeasurementToolLayer();
mapView.addLayer(measurementToolLayer, 4.6f);
// 5. transport layer
transportStopsLayer = new TransportStopsLayer(activity);
mapView.addLayer(transportStopsLayer, 5);
// 5.95 all text labels
// 6. point location layer
locationLayer = new PointLocationLayer(activity.getMapViewTrackingUtilities());
mapView.addLayer(locationLayer, 6);
// 7. point navigation layer
navigationLayer = new PointNavigationLayer(activity);
mapView.addLayer(navigationLayer, 7);
// 7.3 map markers layer
mapMarkersLayer = new MapMarkersLayer(activity);
mapView.addLayer(mapMarkersLayer, 7.3f);
// 7.5 Impassible roads
impassableRoadsLayer = new ImpassableRoadsLayer(activity);
mapView.addLayer(impassableRoadsLayer, 7.5f);
// 7.8 ruler control layer
rulerControlLayer = new RulerControlLayer(activity);
mapView.addLayer(rulerControlLayer, 7.8f);
// 8. context menu layer
// 9. map info layer
mapInfoLayer = new MapInfoLayer(activity, routeLayer);
mapView.addLayer(mapInfoLayer, 9);
// 11. route info layer
mapControlsLayer = new MapControlsLayer(activity);
mapView.addLayer(mapControlsLayer, 11);
// 12. quick actions layer
mapQuickActionLayer = new MapQuickActionLayer(activity, contextMenuLayer);
mapView.addLayer(mapQuickActionLayer, 12);
contextMenuLayer.setMapQuickActionLayer(mapQuickActionLayer);
mapControlsLayer.setMapQuickActionLayer(mapQuickActionLayer);
transparencyListener = new StateChangedListener<Integer>() {
@Override
public void stateChanged(Integer change) {
mapTileLayer.setAlpha(change);
mapVectorLayer.setAlpha(change);
mapView.refreshMap();
}
};
app.getSettings().MAP_TRANSPARENCY.addListener(transparencyListener);
OsmandPlugin.createLayers(mapView, activity);
app.getAppCustomization().createLayers(mapView, activity);
app.getAidlApi().registerMapLayers(activity);
}
use of net.osmand.plus.views.RulerControlLayer in project Osmand by osmandapp.
the class MapInfoWidgetsFactory method createRulerControl.
public TextInfoWidget createRulerControl(final MapActivity map) {
final String title = "—";
final TextInfoWidget rulerControl = new TextInfoWidget(map) {
RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer();
LatLon cacheFirstTouchPoint = new LatLon(0, 0);
LatLon cacheSecondTouchPoint = new LatLon(0, 0);
LatLon cacheSingleTouchPoint = new LatLon(0, 0);
boolean fingerAndLocDistWasShown;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
OsmandMapTileView view = map.getMapView();
Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
if (rulerLayer.isShowDistBetweenFingerAndLocation() && currentLoc != null) {
if (!cacheSingleTouchPoint.equals(rulerLayer.getTouchPointLatLon())) {
cacheSingleTouchPoint = rulerLayer.getTouchPointLatLon();
setDistanceText(cacheSingleTouchPoint.getLatitude(), cacheSingleTouchPoint.getLongitude(), currentLoc.getLatitude(), currentLoc.getLongitude());
fingerAndLocDistWasShown = true;
}
} else if (rulerLayer.isShowTwoFingersDistance()) {
if (!cacheFirstTouchPoint.equals(view.getFirstTouchPointLatLon()) || !cacheSecondTouchPoint.equals(view.getSecondTouchPointLatLon()) || fingerAndLocDistWasShown) {
cacheFirstTouchPoint = view.getFirstTouchPointLatLon();
cacheSecondTouchPoint = view.getSecondTouchPointLatLon();
setDistanceText(cacheFirstTouchPoint.getLatitude(), cacheFirstTouchPoint.getLongitude(), cacheSecondTouchPoint.getLatitude(), cacheSecondTouchPoint.getLongitude());
fingerAndLocDistWasShown = false;
}
} else {
LatLon centerLoc = map.getMapLocation();
if (currentLoc != null && centerLoc != null) {
if (map.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
setDistanceText(0);
} else {
setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(), centerLoc.getLatitude(), centerLoc.getLongitude());
}
} else {
setText(title, null);
}
}
return true;
}
private void setDistanceText(float dist) {
calculateAndSetText(dist);
}
private void setDistanceText(double firstLat, double firstLon, double secondLat, double secondLon) {
float dist = (float) MapUtils.getDistance(firstLat, firstLon, secondLat, secondLon);
calculateAndSetText(dist);
}
private void calculateAndSetText(float dist) {
String distance = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
int ls = distance.lastIndexOf(' ');
setText(distance.substring(0, ls), distance.substring(ls + 1));
}
};
rulerControl.setText(title, null);
setRulerControlIcon(rulerControl, map.getMyApplication().getSettings().RULER_MODE.get());
rulerControl.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
final RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get();
RulerMode newMode = RulerMode.FIRST;
if (mode == RulerMode.FIRST) {
newMode = RulerMode.SECOND;
} else if (mode == RulerMode.SECOND) {
newMode = RulerMode.EMPTY;
}
setRulerControlIcon(rulerControl, newMode);
map.getMyApplication().getSettings().RULER_MODE.set(newMode);
map.refreshMap();
}
});
return rulerControl;
}
Aggregations