Search in sources :

Example 1 with MapFactory

use of carnero.cgeo.mapinterfaces.MapFactory 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);
}
Also used : MapFactory(carnero.cgeo.mapinterfaces.MapFactory) GeoPointImpl(carnero.cgeo.mapinterfaces.GeoPointImpl) Paint(android.graphics.Paint) PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter) Point(android.graphics.Point) Paint(android.graphics.Paint) Location(android.location.Location)

Example 2 with MapFactory

use of carnero.cgeo.mapinterfaces.MapFactory 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);
    }
}
Also used : carnero.cgeo.cgCoord(carnero.cgeo.cgCoord) MapFactory(carnero.cgeo.mapinterfaces.MapFactory) GeoPointImpl(carnero.cgeo.mapinterfaces.GeoPointImpl) Paint(android.graphics.Paint) PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter) CacheOverlayItemImpl(carnero.cgeo.mapinterfaces.CacheOverlayItemImpl) carnero.cgeo.cgeowaypoint(carnero.cgeo.cgeowaypoint) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 3 with MapFactory

use of carnero.cgeo.mapinterfaces.MapFactory in project c-geo by just-radovan.

the class cgeomap method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // class init
    res = this.getResources();
    activity = this.getActivity();
    app = (cgeoapplication) activity.getApplication();
    app.setAction(null);
    settings = new cgSettings(activity, activity.getSharedPreferences(cgSettings.preferences, 0));
    base = new cgBase(app, settings, activity.getSharedPreferences(cgSettings.preferences, 0));
    warning = new cgWarning(activity);
    prefsEdit = activity.getSharedPreferences(cgSettings.preferences, 0).edit();
    MapFactory mapFactory = settings.getMapFactory();
    // reset status
    noMapTokenShowed = false;
    // set layout
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    // set layout
    if (settings.skin == 1) {
        activity.setTheme(R.style.light);
    } else {
        activity.setTheme(R.style.dark);
    }
    activity.setContentView(settings.getMapFactory().getMapLayoutId());
    base.setTitle(activity, res.getString(R.string.map_map));
    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);
    }
    mapView = (MapViewImpl) activity.findViewById(mapFactory.getMapViewId());
    mapView.setMapSource(settings);
    if (!mapView.needsScaleOverlay()) {
        mapView.setBuiltinScale(true);
    }
    // initialize map
    if (settings.maptype == cgSettings.mapSatellite) {
        mapView.setSatellite(true);
    } else {
        mapView.setSatellite(false);
    }
    mapView.setBuiltInZoomControls(true);
    mapView.displayZoomControls(true);
    mapView.preLoad();
    // initialize overlays
    mapView.clearOverlays();
    if (overlayMyLoc == null) {
        overlayMyLoc = new cgMapMyOverlay(settings);
        mapView.addOverlay(mapFactory.getOverlayBaseWrapper(overlayMyLoc));
    }
    if (settings.publicLoc > 0 && overlayUsers == null) {
        overlayUsers = mapView.createAddUsersOverlay(activity, getResources().getDrawable(R.drawable.user_location));
    }
    if (overlayCaches == null) {
        overlayCaches = mapView.createAddMapOverlay(settings, mapView.getContext(), getResources().getDrawable(R.drawable.marker), fromDetailIntent);
    }
    if (overlayScale == null && mapView.needsScaleOverlay()) {
        overlayScale = new cgOverlayScale(activity, settings);
        mapView.addOverlay(mapFactory.getOverlayBaseWrapper(overlayScale));
    }
    mapView.invalidate();
    mapController = mapView.getMapController();
    mapController.setZoom(settings.mapzoom);
    // start location and directory services
    if (geo != null) {
        geoUpdate.updateLoc(geo);
    }
    if (dir != null) {
        dirUpdate.updateDir(dir);
    }
    // get parameters
    Bundle extras = activity.getIntent().getExtras();
    if (extras != null) {
        fromDetailIntent = extras.getBoolean("detail");
        searchIdIntent = extras.getLong("searchid");
        geocodeIntent = extras.getString("geocode");
        latitudeIntent = extras.getDouble("latitude");
        longitudeIntent = extras.getDouble("longitude");
        waypointTypeIntent = extras.getString("wpttype");
        if (searchIdIntent == 0l) {
            searchIdIntent = null;
        }
        if (latitudeIntent == 0.0) {
            latitudeIntent = null;
        }
        if (longitudeIntent == 0.0) {
            longitudeIntent = null;
        }
    }
    // live or death
    if (searchIdIntent == null && geocodeIntent == null && (latitudeIntent == null || longitudeIntent == null)) {
        live = true;
    } else {
        live = false;
    }
    // google analytics
    if (live) {
        base.sendAnal(activity, "/map/live");
        followMyLocation = true;
    } else {
        base.sendAnal(activity, "/map/normal");
        followMyLocation = false;
        if (geocodeIntent != null || searchIdIntent != null || (latitudeIntent != null && longitudeIntent != null)) {
            centerMap(geocodeIntent, searchIdIntent, latitudeIntent, longitudeIntent);
        }
    }
    setMyLoc(null);
    startTimer();
}
Also used : MapFactory(carnero.cgeo.mapinterfaces.MapFactory) carnero.cgeo.cgWarning(carnero.cgeo.cgWarning) Bundle(android.os.Bundle) carnero.cgeo.cgSettings(carnero.cgeo.cgSettings) carnero.cgeo.cgBase(carnero.cgeo.cgBase)

Aggregations

MapFactory (carnero.cgeo.mapinterfaces.MapFactory)3 Paint (android.graphics.Paint)2 PaintFlagsDrawFilter (android.graphics.PaintFlagsDrawFilter)2 Point (android.graphics.Point)2 GeoPointImpl (carnero.cgeo.mapinterfaces.GeoPointImpl)2 Location (android.location.Location)1 Bundle (android.os.Bundle)1 carnero.cgeo.cgBase (carnero.cgeo.cgBase)1 carnero.cgeo.cgCoord (carnero.cgeo.cgCoord)1 carnero.cgeo.cgSettings (carnero.cgeo.cgSettings)1 carnero.cgeo.cgWarning (carnero.cgeo.cgWarning)1 carnero.cgeo.cgeowaypoint (carnero.cgeo.cgeowaypoint)1 CacheOverlayItemImpl (carnero.cgeo.mapinterfaces.CacheOverlayItemImpl)1