Search in sources :

Example 1 with CompassOverlay

use of org.osmdroid.views.overlay.compass.CompassOverlay in project trackbook by y20k.

the class MainActivityMapFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // create basic map
    mMapView = new MapView(inflater.getContext());
    // get map controller
    mController = mMapView.getController();
    // basic map setup
    mMapView.setTileSource(TileSourceFactory.MAPNIK);
    mMapView.setTilesScaledToDpi(true);
    // add multi-touch capability
    mMapView.setMultiTouchControls(true);
    // disable default zoom controls
    mMapView.setBuiltInZoomControls(false);
    // add compass to map
    CompassOverlay compassOverlay = new CompassOverlay(mActivity, new InternalCompassOrientationProvider(mActivity), mMapView);
    compassOverlay.enableCompass();
    mMapView.getOverlays().add(compassOverlay);
    // initiate map state
    if (savedInstanceState != null) {
        // restore saved instance of map
        GeoPoint position = new GeoPoint(savedInstanceState.getDouble(INSTANCE_LATITUDE_MAIN_MAP, DEFAULT_LATITUDE), savedInstanceState.getDouble(INSTANCE_LONGITUDE_MAIN_MAP, DEFAULT_LONGITUDE));
        mController.setCenter(position);
        mController.setZoom(savedInstanceState.getDouble(INSTANCE_ZOOM_LEVEL_MAIN_MAP, 16f));
        // restore current location
        mCurrentBestLocation = savedInstanceState.getParcelable(INSTANCE_CURRENT_LOCATION);
    } else if (mCurrentBestLocation != null) {
        // fallback or first run: set map to current position
        GeoPoint position = convertToGeoPoint(mCurrentBestLocation);
        mController.setCenter(position);
        mController.setZoom(16f);
    }
    // inform user that new/better location is on its way
    if (mFirstStart && !mTrackerServiceRunning) {
        Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_acquiring_location), Toast.LENGTH_LONG).show();
        mFirstStart = false;
    }
    // mark user's location on map
    if (mCurrentBestLocation != null && !mTrackerServiceRunning) {
        mMyLocationOverlay = MapHelper.createMyLocationOverlay(mActivity, mCurrentBestLocation, LocationHelper.isNewLocation(mCurrentBestLocation));
        mMapView.getOverlays().add(mMyLocationOverlay);
    }
    return mMapView;
}
Also used : GeoPoint(org.osmdroid.util.GeoPoint) MapView(org.osmdroid.views.MapView) CompassOverlay(org.osmdroid.views.overlay.compass.CompassOverlay) InternalCompassOrientationProvider(org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider)

Example 2 with CompassOverlay

use of org.osmdroid.views.overlay.compass.CompassOverlay in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class MapFragment method setUpMapIfNeeded.

/**
 * Description:     Initialises the Map and sets initial options such as:
 * Zoom levels and controls
 * Compass
 * ScaleBar
 * Cluster Pin colors
 * Location update settings
 */
private void setUpMapIfNeeded() {
    // Check if we were successful in obtaining the map.
    mMap.setBuiltInZoomControls(true);
    mMap.setMultiTouchControls(true);
    mMap.setMinZoomLevel(3);
    // Latest OSM can go to 21!
    mMap.setMaxZoomLevel(19);
    mMap.getTileProvider().createTileCache();
    mCompassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), mMap);
    ScaleBarOverlay mScaleBarOverlay = new ScaleBarOverlay(getActivity());
    mScaleBarOverlay.setScaleBarOffset(getResources().getDisplayMetrics().widthPixels / 2, 10);
    mScaleBarOverlay.setCentred(true);
    // Sets cluster pin color
    mCellTowerGridMarkerClusterer = new CellTowerGridMarkerClusterer(getActivity());
    BitmapDrawable mapPinDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_map_pin_orange);
    mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());
    GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(getActivity().getBaseContext());
    // [m]  // Set the minimum distance for location updates
    gpsMyLocationProvider.setLocationUpdateMinDistance(100);
    // [ms] // Set the minimum time interval for location updates
    gpsMyLocationProvider.setLocationUpdateMinTime(10000);
    mMyLocationOverlay = new MyLocationNewOverlay(getActivity().getBaseContext(), gpsMyLocationProvider, mMap);
    mMyLocationOverlay.setDrawAccuracyEnabled(true);
    mMap.getOverlays().add(mCellTowerGridMarkerClusterer);
    mMap.getOverlays().add(mMyLocationOverlay);
    mMap.getOverlays().add(mCompassOverlay);
    mMap.getOverlays().add(mScaleBarOverlay);
}
Also used : CellTowerGridMarkerClusterer(com.secupwn.aimsicd.map.CellTowerGridMarkerClusterer) GpsMyLocationProvider(org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider) MyLocationNewOverlay(org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CompassOverlay(org.osmdroid.views.overlay.compass.CompassOverlay) ScaleBarOverlay(org.osmdroid.views.overlay.ScaleBarOverlay) InternalCompassOrientationProvider(org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider)

Example 3 with CompassOverlay

use of org.osmdroid.views.overlay.compass.CompassOverlay in project Android-IMSI-Catcher-Detector by CellularPrivacy.

the class MapViewerOsmDroid method setUpMapIfNeeded.

/**
 * Description:     Initialises the Map and sets initial options such as:
 * Zoom levels and controls
 * Compass
 * ScaleBar
 * Cluster Pin colors
 * Location update settings
 */
private void setUpMapIfNeeded() {
    // Check if we were successful in obtaining the map.
    mMap.setBuiltInZoomControls(true);
    mMap.setMultiTouchControls(true);
    mMap.setMinZoomLevel(3);
    // Latest OSM can go to 21!
    mMap.setMaxZoomLevel(19);
    mMap.getTileProvider().createTileCache();
    mCompassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this), mMap);
    ScaleBarOverlay mScaleBarOverlay = new ScaleBarOverlay(this);
    mScaleBarOverlay.setScaleBarOffset(getResources().getDisplayMetrics().widthPixels / 2, 10);
    mScaleBarOverlay.setCentred(true);
    // Sets cluster pin color
    mCellTowerGridMarkerClusterer = new CellTowerGridMarkerClusterer(MapViewerOsmDroid.this);
    BitmapDrawable mapPinDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_map_pin_orange);
    mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());
    GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(MapViewerOsmDroid.this.getBaseContext());
    // [m]  // Set the minimum distance for location updates
    gpsMyLocationProvider.setLocationUpdateMinDistance(100);
    // [ms] // Set the minimum time interval for location updates
    gpsMyLocationProvider.setLocationUpdateMinTime(10000);
    mMyLocationOverlay = new MyLocationNewOverlay(MapViewerOsmDroid.this.getBaseContext(), gpsMyLocationProvider, mMap);
    mMyLocationOverlay.setDrawAccuracyEnabled(true);
    mMap.getOverlays().add(mCellTowerGridMarkerClusterer);
    mMap.getOverlays().add(mMyLocationOverlay);
    mMap.getOverlays().add(mCompassOverlay);
    mMap.getOverlays().add(mScaleBarOverlay);
}
Also used : CellTowerGridMarkerClusterer(com.secupwn.aimsicd.map.CellTowerGridMarkerClusterer) GpsMyLocationProvider(org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider) MyLocationNewOverlay(org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CompassOverlay(org.osmdroid.views.overlay.compass.CompassOverlay) ScaleBarOverlay(org.osmdroid.views.overlay.ScaleBarOverlay) InternalCompassOrientationProvider(org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider)

Example 4 with CompassOverlay

use of org.osmdroid.views.overlay.compass.CompassOverlay in project trackbook by y20k.

the class MainActivityTrackFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    // inflate root view from xml
    mRootView = inflater.inflate(R.layout.fragment_main_track, container, false);
    // get reference to onboarding layout
    mOnboardingView = (LinearLayout) mRootView.findViewById(R.id.track_tab_onboarding);
    // get reference to basic map
    mMapView = (MapView) mRootView.findViewById(R.id.track_map);
    // get map controller
    mController = mMapView.getController();
    // basic map setup
    mMapView.setTileSource(TileSourceFactory.MAPNIK);
    mMapView.setTilesScaledToDpi(true);
    // add multi-touch capability
    mMapView.setMultiTouchControls(true);
    // disable default zoom controls
    mMapView.setBuiltInZoomControls(false);
    // add compass to map
    CompassOverlay compassOverlay = new CompassOverlay(mActivity, new InternalCompassOrientationProvider(mActivity), mMapView);
    compassOverlay.enableCompass();
    // move the compass overlay down a bit
    compassOverlay.setCompassCenter(35.0f, 96.0f);
    mMapView.getOverlays().add(compassOverlay);
    // initiate map state
    if (savedInstanceState != null) {
        // restore saved instance of map
        GeoPoint position = new GeoPoint(savedInstanceState.getDouble(INSTANCE_LATITUDE_TRACK_MAP, DEFAULT_LATITUDE), savedInstanceState.getDouble(INSTANCE_LONGITUDE_TRACK_MAP, DEFAULT_LONGITUDE));
        mController.setCenter(position);
        mController.setZoom(savedInstanceState.getDouble(INSTANCE_ZOOM_LEVEL_MAIN_MAP, 16f));
    } else {
        mController.setZoom(16f);
    }
    // get views for track selector
    mTrackManagementLayout = (ConstraintLayout) mRootView.findViewById(R.id.track_management_layout);
    mDropdown = (Spinner) mRootView.findViewById(R.id.track_selector);
    // attach listeners to export and delete buttons
    ImageButton exportButton = (ImageButton) mRootView.findViewById(R.id.export_button);
    ImageButton deleteButton = (ImageButton) mRootView.findViewById(R.id.delete_button);
    exportButton.setOnClickListener(getExportButtonListener());
    deleteButton.setOnClickListener(getDeleteButtonListener());
    // get views for statistics sheet
    View statisticsView = mRootView.findViewById(R.id.statistics_view);
    mStatisticsSheet = mRootView.findViewById(R.id.statistics_sheet);
    mDistanceView = (TextView) mRootView.findViewById(R.id.statistics_data_distance);
    mStepsView = (TextView) mRootView.findViewById(R.id.statistics_data_steps);
    mWaypointsView = (TextView) mRootView.findViewById(R.id.statistics_data_waypoints);
    mDurationView = (TextView) mRootView.findViewById(R.id.statistics_data_duration);
    mRecordingStartView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_start);
    mRecordingStopView = (TextView) mRootView.findViewById(R.id.statistics_data_recording_stop);
    mMaxAltitudeView = (TextView) mRootView.findViewById(R.id.statistics_data_max_altitude);
    mMinAltitudeView = (TextView) mRootView.findViewById(R.id.statistics_data_min_altitude);
    mPositiveElevationView = (TextView) mRootView.findViewById(R.id.statistics_data_positive_elevation);
    mNegativeElevationView = (TextView) mRootView.findViewById(R.id.statistics_data_negative_elevation);
    mElevationDataViews = (Group) mRootView.findViewById(R.id.elevation_data);
    // attach listners for taps on elevation views
    attachTapListeners();
    // display map and statistics
    if (savedInstanceState != null) {
        // get track from saved instance and display map and statistics
        mTrack = savedInstanceState.getParcelable(INSTANCE_TRACK_TRACK_MAP);
        displayTrack();
    } else if (mTrack == null) {
        // load track and display map and statistics
        LoadTrackAsyncHelper loadTrackAsyncHelper = new LoadTrackAsyncHelper();
        loadTrackAsyncHelper.execute();
    } else {
        // just display map and statistics
        displayTrack();
    }
    // set up and show statistics sheet
    mStatisticsSheetBehavior = BottomSheetBehavior.from(mStatisticsSheet);
    mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    mStatisticsSheetBehavior.setBottomSheetCallback(getStatisticsSheetCallback());
    statisticsView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mStatisticsSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
                mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
            } else {
                mStatisticsSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            }
        }
    });
    return mRootView;
}
Also used : GeoPoint(org.osmdroid.util.GeoPoint) ImageButton(android.widget.ImageButton) CompassOverlay(org.osmdroid.views.overlay.compass.CompassOverlay) View(android.view.View) AdapterView(android.widget.AdapterView) MapView(org.osmdroid.views.MapView) TextView(android.widget.TextView) InternalCompassOrientationProvider(org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider) Nullable(android.support.annotation.Nullable)

Aggregations

CompassOverlay (org.osmdroid.views.overlay.compass.CompassOverlay)4 InternalCompassOrientationProvider (org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 CellTowerGridMarkerClusterer (com.secupwn.aimsicd.map.CellTowerGridMarkerClusterer)2 GeoPoint (org.osmdroid.util.GeoPoint)2 MapView (org.osmdroid.views.MapView)2 ScaleBarOverlay (org.osmdroid.views.overlay.ScaleBarOverlay)2 GpsMyLocationProvider (org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider)2 MyLocationNewOverlay (org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay)2 Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageButton (android.widget.ImageButton)1 TextView (android.widget.TextView)1