use of org.mapsforge.map.layer.Layer in project satstat by mvglasow.
the class MapSectionFragment method destroyLayers.
/**
* Destroys layers and associated tile caches for the map view.
*
* @param destroyOverlays Whether to destroy overlays (markers and circles) or just the tile layers
*/
private void destroyLayers(boolean destroyOverlays) {
Layers layers = null;
if (mapMap != null)
layers = mapMap.getLayerManager().getLayers();
if (mapDownloadLayer != null) {
if (layers != null)
layers.remove(mapDownloadLayer);
mapDownloadLayer.onDestroy();
mapDownloadLayer = null;
}
if (mapRendererLayer != null) {
if (layers != null)
layers.remove(mapRendererLayer);
mapRendererLayer.onDestroy();
mapRendererLayer = null;
}
if (mapDownloadTileCache != null) {
mapDownloadTileCache.destroy();
mapDownloadTileCache = null;
}
if (mapRendererTileCache != null) {
mapRendererTileCache.destroy();
mapRendererTileCache = null;
}
if (destroyOverlays && (layers != null))
for (Layer layer : layers) {
layer.onDestroy();
layers.remove(layer);
}
}
use of org.mapsforge.map.layer.Layer in project satstat by mvglasow.
the class MapSectionFragment method onLocationProvidersChanged.
/**
* Updates internal data structures when the user's selection of location providers has changed.
* @param providers The new set of location providers
*/
public void onLocationProvidersChanged(Set<String> providers) {
Context context = this.getContext();
List<String> allProviders = mainActivity.locationManager.getAllProviders();
ArrayList<String> removedProviders = new ArrayList<String>();
for (String pr : providerLocations.keySet()) if (!providers.contains(pr))
removedProviders.add(pr);
// remove cached locations and invalidators for providers which are no longer selected
for (String pr : removedProviders) {
providerLocations.remove(pr);
providerInvalidators.remove(pr);
}
// ensure there is a cached location for each chosen provider (can be null)
for (String pr : providers) {
if ((allProviders.indexOf(pr) >= 0) && !providerLocations.containsKey(pr)) {
Location location = new Location("");
providerLocations.put(pr, location);
}
}
// add overlays
updateLocationProviderStyles();
mapCircles = new HashMap<String, Circle>();
mapMarkers = new HashMap<String, Marker>();
Log.d(TAG, "Provider location cache: " + providerLocations.keySet().toString());
Layers layers = mapMap.getLayerManager().getLayers();
// remove all layers other than tile render layer from map
for (Layer layer : layers) if (!(layer instanceof TileRendererLayer) && !(layer instanceof TileDownloadLayer)) {
layer.onDestroy();
layers.remove(layer);
}
for (String pr : providers) {
// no invalidator for GPS, which is invalidated through GPS status
if ((!pr.equals(LocationManager.GPS_PROVIDER)) && (providerInvalidators.get(pr)) == null) {
final String provider = pr;
final Context ctx = context;
providerInvalidators.put(pr, new Runnable() {
private String mProvider = provider;
@Override
public void run() {
Location location = providerLocations.get(mProvider);
if (location != null)
markLocationAsStale(location);
applyLocationProviderStyle(ctx, mProvider, Const.LOCATION_PROVIDER_GRAY);
}
});
}
String styleName = assignLocationProviderStyle(pr);
LatLong latLong;
float acc;
boolean visible;
if ((providerLocations.get(pr) != null) && (providerLocations.get(pr).getProvider() != "")) {
latLong = new LatLong(providerLocations.get(pr).getLatitude(), providerLocations.get(pr).getLongitude());
if (providerLocations.get(pr).hasAccuracy())
acc = providerLocations.get(pr).getAccuracy();
else
acc = 0;
visible = true;
if (isLocationStale(providerLocations.get(pr)))
styleName = Const.LOCATION_PROVIDER_GRAY;
Log.d("MainActivity", pr + " has " + latLong.toString());
} else {
latLong = new LatLong(0, 0);
acc = 0;
visible = false;
Log.d("MainActivity", pr + " has no location, hiding");
}
// Circle layer
Resources res = context.getResources();
TypedArray style = res.obtainTypedArray(res.getIdentifier(styleName, "array", context.getPackageName()));
Paint fill = AndroidGraphicFactory.INSTANCE.createPaint();
float density = context.getResources().getDisplayMetrics().density;
fill.setColor(style.getColor(Const.STYLE_FILL, R.color.circle_gray_fill));
fill.setStyle(Style.FILL);
Paint stroke = AndroidGraphicFactory.INSTANCE.createPaint();
stroke.setColor(style.getColor(Const.STYLE_STROKE, R.color.circle_gray_stroke));
stroke.setStrokeWidth(Math.max(1.5f * density, 1));
stroke.setStyle(Style.STROKE);
Circle circle = new Circle(latLong, acc, fill, stroke);
mapCircles.put(pr, circle);
layers.add(circle);
circle.setVisible(visible);
// Marker layer
Drawable drawable = style.getDrawable(Const.STYLE_MARKER);
Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable);
Marker marker = new Marker(latLong, bitmap, 0, -bitmap.getHeight() * 10 / 24);
mapMarkers.put(pr, marker);
layers.add(marker);
marker.setVisible(visible);
style.recycle();
}
// move layers into view
updateMap();
}
Aggregations