use of carnero.cgeo.mapinterfaces.GeoPointImpl in project c-geo by just-radovan.
the class cgMapMyOverlay method drawInternal.
private void drawInternal(Canvas canvas, MapProjectionImpl projection) {
if (coordinates == null || location == null)
return;
MapFactory mapFactory = settings.getMapFactory();
if (accuracyCircle == null) {
accuracyCircle = new Paint();
accuracyCircle.setAntiAlias(true);
accuracyCircle.setStrokeWidth(1.0f);
}
if (historyLine == null) {
historyLine = new Paint();
historyLine.setAntiAlias(true);
historyLine.setStrokeWidth(3.0f);
historyLine.setColor(0xFFFFFFFF);
}
if (historyLineShadow == null) {
historyLineShadow = new Paint();
historyLineShadow.setAntiAlias(true);
historyLineShadow.setStrokeWidth(7.0f);
historyLineShadow.setColor(0x66000000);
}
if (setfil == null)
setfil = new PaintFlagsDrawFilter(0, Paint.FILTER_BITMAP_FLAG);
if (remfil == null)
remfil = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG, 0);
canvas.setDrawFilter(setfil);
double latitude = coordinates.getLatitude();
double longitude = coordinates.getLongitude();
float accuracy = coordinates.getAccuracy();
float[] result = new float[1];
Location.distanceBetween(latitude, longitude, latitude, longitude + 1, result);
float longitudeLineDistance = result[0];
GeoPointImpl leftGeo = mapFactory.getGeoPointBase((int) (latitude * 1e6), (int) ((longitude - accuracy / longitudeLineDistance) * 1e6));
projection.toPixels(leftGeo, left);
projection.toPixels(location, center);
int radius = center.x - left.x;
accuracyCircle.setColor(0x66000000);
accuracyCircle.setStyle(Style.STROKE);
canvas.drawCircle(center.x, center.y, radius, accuracyCircle);
accuracyCircle.setColor(0x08000000);
accuracyCircle.setStyle(Style.FILL);
canvas.drawCircle(center.x, center.y, radius, accuracyCircle);
if (coordinates.getAccuracy() < 50f && ((historyRecent != null && cgBase.getDistance(historyRecent.getLatitude(), historyRecent.getLongitude(), coordinates.getLatitude(), coordinates.getLongitude()) > 0.005) || historyRecent == null)) {
if (historyRecent != null)
history.add(historyRecent);
historyRecent = coordinates;
int toRemove = history.size() - 700;
if (toRemove > 0) {
for (int cnt = 0; cnt < toRemove; cnt++) {
history.remove(cnt);
}
}
}
if (settings.maptrail == 1) {
int size = history.size();
if (size > 1) {
int alpha = 0;
int alphaCnt = size - 201;
if (alphaCnt < 1)
alphaCnt = 1;
for (int cnt = 1; cnt < size; cnt++) {
Location prev = history.get(cnt - 1);
Location now = history.get(cnt);
if (prev != null && now != null) {
projection.toPixels(mapFactory.getGeoPointBase((int) (prev.getLatitude() * 1e6), (int) (prev.getLongitude() * 1e6)), historyPointP);
projection.toPixels(mapFactory.getGeoPointBase((int) (now.getLatitude() * 1e6), (int) (now.getLongitude() * 1e6)), historyPointN);
if ((alphaCnt - cnt) > 0)
alpha = Math.round(255 / (alphaCnt - cnt));
else
alpha = 255;
historyLineShadow.setAlpha(alpha);
historyLine.setAlpha(alpha);
canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLineShadow);
canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLine);
}
}
}
if (size > 0) {
Location prev = history.get(size - 1);
Location now = coordinates;
if (prev != null && now != null) {
projection.toPixels(mapFactory.getGeoPointBase((int) (prev.getLatitude() * 1e6), (int) (prev.getLongitude() * 1e6)), historyPointP);
projection.toPixels(mapFactory.getGeoPointBase((int) (now.getLatitude() * 1e6), (int) (now.getLongitude() * 1e6)), historyPointN);
historyLineShadow.setAlpha(255);
historyLine.setAlpha(255);
canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLineShadow);
canvas.drawLine(historyPointP.x, historyPointP.y, historyPointN.x, historyPointN.y, historyLine);
}
}
}
if (arrow == null) {
arrow = BitmapFactory.decodeResource(settings.getContext().getResources(), R.drawable.my_location_chevron);
widthArrow = arrow.getWidth();
heightArrow = arrow.getHeight();
}
int marginLeft;
int marginTop;
marginLeft = center.x - (widthArrow / 2);
marginTop = center.y - (heightArrow / 2);
canvas.rotate(new Float(heading), center.x, center.y);
canvas.drawBitmap(arrow, marginLeft, marginTop, null);
canvas.rotate(-(new Float(heading)), center.x, center.y);
canvas.setDrawFilter(remfil);
//super.draw(canvas, mapView, shadow);
}
use of carnero.cgeo.mapinterfaces.GeoPointImpl in project c-geo by just-radovan.
the class cgOverlayScale method draw.
@Override
public void draw(Canvas canvas, MapViewImpl mapView, boolean shadow) {
//super.draw(canvas, mapView, shadow);
final double span = mapView.getLongitudeSpan() / 1e6;
final GeoPointImpl center = mapView.getMapViewCenter();
// pixels related to following latitude span
pixels = mapView.getWidth() / 2;
// pixels from bottom side of screen
bottom = mapView.getHeight() - 14;
distance = cgBase.getDistance((center.getLatitudeE6() / 1e6), ((center.getLongitudeE6() / 1e6) - (span / 2)), (center.getLatitudeE6() / 1e6), ((center.getLongitudeE6() / 1e6) + (span / 2)));
distance = distance / 2;
distanceRound = 0d;
if (settings.units == cgSettings.unitsImperial) {
distance *= cgBase.kmInMiles;
if (distance > 100) {
// 100+ mi > 1xx mi
distanceRound = Math.floor(distance / 100) * 100;
units = "mi";
} else if (distance > 10) {
// 10 - 100 mi > 1x mi
distanceRound = Math.floor(distance / 10) * 10;
units = "mi";
} else if (distance > 1) {
// 1 - 10 mi > 1.x mi
distanceRound = Math.floor(distance);
units = "mi";
} else if (distance > 0.1) {
// 0.1 mi - 1.0 mi > 1xx ft
distance *= 5280;
distanceRound = Math.floor(distance / 100) * 100;
units = "ft";
} else {
// 1 - 100 ft > 1x ft
distance *= 5280;
distanceRound = Math.round(distance / 10) * 10;
units = "ft";
}
} else {
if (distance > 100) {
// 100+ km > 1xx km
distanceRound = Math.floor(distance / 100) * 100;
units = "km";
} else if (distance > 10) {
// 10 - 100 km > 1x km
distanceRound = Math.floor(distance / 10) * 10;
units = "km";
} else if (distance > 1) {
// 1 - 10 km > 1.x km
distanceRound = Math.floor(distance);
units = "km";
} else if (distance > 0.1) {
// 100 m - 1 km > 1xx m
distance *= 1000;
distanceRound = Math.floor(distance / 100) * 100;
units = "m";
} else {
// 1 - 100 m > 1x m
distance *= 1000;
distanceRound = Math.round(distance / 10) * 10;
units = "m";
}
}
pixels = Math.round((pixels / distance) * distanceRound);
if (blur == null) {
blur = new BlurMaskFilter(3, BlurMaskFilter.Blur.NORMAL);
}
if (scaleShadow == null) {
scaleShadow = new Paint();
scaleShadow.setAntiAlias(true);
scaleShadow.setStrokeWidth(4 * pixelDensity);
scaleShadow.setMaskFilter(blur);
scaleShadow.setTextSize(14 * pixelDensity);
scaleShadow.setTypeface(Typeface.DEFAULT_BOLD);
}
if (scale == null) {
scale = new Paint();
scale.setAntiAlias(true);
scale.setStrokeWidth(2 * pixelDensity);
scale.setTextSize(14 * pixelDensity);
scale.setTypeface(Typeface.DEFAULT_BOLD);
}
if (mapView.isSatellite()) {
scaleShadow.setColor(0xFF000000);
scale.setColor(0xFFFFFFFF);
} else {
scaleShadow.setColor(0xFFFFFFFF);
scale.setColor(0xFF000000);
}
canvas.drawLine(10, bottom, 10, (bottom - (8 * pixelDensity)), scaleShadow);
canvas.drawLine((int) (pixels + 10), bottom, (int) (pixels + 10), (bottom - (8 * pixelDensity)), scaleShadow);
canvas.drawLine(8, bottom, (int) (pixels + 12), bottom, scaleShadow);
canvas.drawText(String.format("%.0f", distanceRound) + " " + units, (float) (pixels - (10 * pixelDensity)), (bottom - (10 * pixelDensity)), scaleShadow);
canvas.drawLine(11, bottom, 11, (bottom - (6 * pixelDensity)), scale);
canvas.drawLine((int) (pixels + 9), bottom, (int) (pixels + 9), (bottom - (6 * pixelDensity)), scale);
canvas.drawLine(10, bottom, (int) (pixels + 10), bottom, scale);
canvas.drawText(String.format("%.0f", distanceRound) + " " + units, (float) (pixels - (10 * pixelDensity)), (bottom - (10 * pixelDensity)), scale);
}
use of carnero.cgeo.mapinterfaces.GeoPointImpl in project c-geo by just-radovan.
the class cgMapOverlay method drawInternal.
private void drawInternal(Canvas canvas, MapProjectionImpl projection) {
MapFactory mapFactory = settings.getMapFactory();
if (displayCircles) {
if (blockedCircle == null) {
blockedCircle = new Paint();
blockedCircle.setAntiAlias(true);
blockedCircle.setStrokeWidth(1.0f);
}
if (setfil == null)
setfil = new PaintFlagsDrawFilter(0, Paint.FILTER_BITMAP_FLAG);
if (remfil == null)
remfil = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG, 0);
canvas.setDrawFilter(setfil);
for (CacheOverlayItemImpl item : items) {
final cgCoord itemCoord = item.getCoord();
float[] result = new float[1];
Location.distanceBetween(itemCoord.latitude, itemCoord.longitude, itemCoord.latitude, itemCoord.longitude + 1, result);
final float longitudeLineDistance = result[0];
GeoPointImpl itemGeo = mapFactory.getGeoPointBase((int) (itemCoord.latitude * 1e6), (int) (itemCoord.longitude * 1e6));
GeoPointImpl leftGeo = mapFactory.getGeoPointBase((int) (itemCoord.latitude * 1e6), (int) ((itemCoord.longitude - 161 / longitudeLineDistance) * 1e6));
projection.toPixels(itemGeo, center);
projection.toPixels(leftGeo, left);
int radius = center.x - left.x;
final String type = item.getType();
if (type == null || "multi".equals(type) || "mystery".equals(type) || "virtual".equals(type)) {
blockedCircle.setColor(0x66000000);
blockedCircle.setStyle(Style.STROKE);
canvas.drawCircle(center.x, center.y, radius, blockedCircle);
} else {
blockedCircle.setColor(0x66BB0000);
blockedCircle.setStyle(Style.STROKE);
canvas.drawCircle(center.x, center.y, radius, blockedCircle);
blockedCircle.setColor(0x44BB0000);
blockedCircle.setStyle(Style.FILL);
canvas.drawCircle(center.x, center.y, radius, blockedCircle);
}
}
canvas.setDrawFilter(remfil);
}
}
use of carnero.cgeo.mapinterfaces.GeoPointImpl in project c-geo by just-radovan.
the class cgeomap method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final int id = item.getItemId();
if (id == 1) {
if (mapView != null && mapView.isSatellite() == false) {
mapView.setSatellite(true);
prefsEdit.putInt("maptype", cgSettings.mapSatellite);
prefsEdit.commit();
} else {
mapView.setSatellite(false);
prefsEdit.putInt("maptype", cgSettings.mapClassic);
prefsEdit.commit();
}
return true;
} else if (id == 2) {
if (settings.maptrail == 1) {
prefsEdit.putInt("maptrail", 0);
prefsEdit.commit();
settings.maptrail = 0;
} else {
prefsEdit.putInt("maptrail", 1);
prefsEdit.commit();
settings.maptrail = 1;
}
} else if (id == 3) {
if (settings.maplive == 1) {
settings.liveMapDisable();
} else {
settings.liveMapEnable();
}
liveChanged = true;
searchId = null;
searchIdIntent = null;
} else if (id == 4) {
if (live && !isLoading() && caches != null && !caches.isEmpty()) {
final ArrayList<String> geocodes = new ArrayList<String>();
ArrayList<cgCache> cachesProtected = (ArrayList<cgCache>) caches.clone();
try {
if (cachesProtected != null && cachesProtected.size() > 0) {
final GeoPointImpl mapCenter = mapView.getMapViewCenter();
final int mapCenterLat = mapCenter.getLatitudeE6();
final int mapCenterLon = mapCenter.getLongitudeE6();
final int mapSpanLat = mapView.getLatitudeSpan();
final int mapSpanLon = mapView.getLongitudeSpan();
for (cgCache oneCache : cachesProtected) {
if (oneCache != null && oneCache.latitude != null && oneCache.longitude != null) {
if (base.isCacheInViewPort(mapCenterLat, mapCenterLon, mapSpanLat, mapSpanLon, oneCache.latitude, oneCache.longitude) && app.isOffline(oneCache.geocode, null) == false) {
geocodes.add(oneCache.geocode);
}
}
}
}
} catch (Exception e) {
Log.e(cgSettings.tag, "cgeomap.onOptionsItemSelected.#4: " + e.toString());
}
detailTotal = geocodes.size();
if (detailTotal == 0) {
warning.showToast(res.getString(R.string.warn_save_nothing));
return true;
}
waitDialog = new ProgressDialog(activity);
waitDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
waitDialog.setCancelable(true);
waitDialog.setMax(detailTotal);
waitDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface arg0) {
try {
if (loadDetailsThread != null) {
loadDetailsThread.stopIt();
}
if (geo == null) {
geo = app.startGeo(activity, geoUpdate, base, settings, warning, 0, 0);
}
if (settings.useCompass == 1 && dir == null) {
dir = app.startDir(activity, dirUpdate, warning);
}
} catch (Exception e) {
Log.e(cgSettings.tag, "cgeocaches.onPrepareOptionsMenu.onCancel: " + e.toString());
}
}
});
Float etaTime = new Float((detailTotal * (float) 7) / 60);
if (etaTime < 0.4) {
waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + res.getString(R.string.caches_eta_ltm));
} else if (etaTime < 1.5) {
waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + String.format(Locale.getDefault(), "%.0f", etaTime) + " " + res.getString(R.string.caches_eta_min));
} else {
waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + String.format(Locale.getDefault(), "%.0f", etaTime) + " " + res.getString(R.string.caches_eta_mins));
}
waitDialog.show();
detailProgressTime = System.currentTimeMillis();
loadDetailsThread = new LoadDetails(loadDetailsHandler, geocodes);
loadDetailsThread.start();
return true;
}
} else if (id == 5) {
if (overlayCaches == null) {
return false;
}
overlayCaches.switchCircles();
}
return false;
}
Aggregations