org.osmdroid.views.overlay.ScaleBarOverlay Java Examples

The following examples show how to use org.osmdroid.views.overlay.ScaleBarOverlay. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SampleMapSnapshot.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
    mMapSize = Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels);
    mBorderSize = mMapSize / 15;

    mScaleBarOverlay = new ScaleBarOverlay(getActivity(), mMapSize, mMapSize);
    mScaleBarOverlay.setCentred(true);
    mScaleBarOverlay.setScaleBarOffset(mMapSize / 2, 10);

    final RecyclerView recyclerView = new RecyclerView(getActivity());
    recyclerView.setHasFixedSize(true);

    final RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);

    try {
        final DataRegionLoader dataRegionLoader = new DataRegionLoader(getActivity(), R.raw.data_region_usstates);
        mAdapter = new MyAdapter(new ArrayList<>(dataRegionLoader.getList().values()));
        recyclerView.setAdapter(mAdapter);
    } catch(Exception e) {
        // DataRegionLoader KO, not supposed to happen
    }

    return recyclerView;
}
 
Example #2
Source File: ScaleBarOnBottom.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void addOverlays(){
    super.addOverlays();
    final Context context = this.getActivity();
    final DisplayMetrics dm = context.getResources().getDisplayMetrics();

    ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(mMapView);

    scaleBarOverlay.setCentred(true);

    //api15 and up, 85 is right at the bottom
    //we are also adding 20dp padding for the overlay overlay which is added by the super class
    scaleBarOverlay.setScaleBarOffset(dm.widthPixels / 2, dm.heightPixels - (int)(105*dm.density));

    scaleBarOverlay.setUnitsOfMeasure(ScaleBarOverlay.UnitsOfMeasure.imperial);
    mMapView.getOverlayManager().add(scaleBarOverlay);
}
 
Example #3
Source File: SampleRotation.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void addOverlays(){
    super.addOverlays();

    final DisplayMetrics dm = getActivity().getResources().getDisplayMetrics();
    RotationGestureOverlay  mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
    mRotationGestureOverlay.setEnabled(true);
    mMapView.getOverlays().add(mRotationGestureOverlay);

    ScaleBarOverlay mScaleBarOverlay = new ScaleBarOverlay(mMapView);
    mScaleBarOverlay.setScaleBarOffset(0,(int)(40 * dm.density));
    mScaleBarOverlay.setCentred(true);
    mScaleBarOverlay.setScaleBarOffset(dm.widthPixels / 2, 10);
    mMapView.getOverlays().add(mScaleBarOverlay);

}
 
Example #4
Source File: MapFragment.java    From AIMSICDL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    mMap.setMaxZoomLevel(19); // Latest OSM can go to 21!
    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);
    BitmapDrawable mapPinDrawable = (BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.ic_map_pin_orange, null);
    mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());

    GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(getActivity().getBaseContext());
    gpsMyLocationProvider.setLocationUpdateMinDistance(100); // [m]  // Set the minimum distance for location updates
    gpsMyLocationProvider.setLocationUpdateMinTime(10000);   // [ms] // Set the minimum time interval for location updates
    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);
}
 
Example #5
Source File: MapViewerOsmDroid.java    From AIMSICDL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    mMap.setMaxZoomLevel(19); // Latest OSM can go to 21!
    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);
    BitmapDrawable mapPinDrawable = (BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_map_pin_orange, null);

    mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());

    GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(MapViewerOsmDroid.this.getBaseContext());
    gpsMyLocationProvider.setLocationUpdateMinDistance(100); // [m]  // Set the minimum distance for location updates
    gpsMyLocationProvider.setLocationUpdateMinTime(10000);   // [ms] // Set the minimum time interval for location updates
    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);
}
 
Example #6
Source File: SampleVeryHighZoomLevel.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void addOverlays() {
    mMapView.setUseDataConnection(false);

    final ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(mMapView);
    scaleBarOverlay.setCentred(true);
    scaleBarOverlay.setScaleBarOffset(200, 10);
    mMapView.getOverlays().add(scaleBarOverlay);

    final ITileSource tileSource = new XYTileSource(
            "Abstract", 0, 29, 256, ".png", new String[]{"http://localhost/"}, "abstract data");
    mMapView.setUseDataConnection(false);

    final MapTileAssetsProvider assetsProvider = new MapTileAssetsProvider(new SimpleRegisterReceiver(getContext()), getActivity().getAssets(), tileSource);

    final MapTileApproximater approximationProvider = new MapTileApproximater();
    approximationProvider.addProvider(assetsProvider);

    final MapTileProviderArray array = new MapTileProviderArray(
            tileSource, new SimpleRegisterReceiver(getContext()),
            new MapTileModuleProviderBase[]{assetsProvider, approximationProvider});

    mMapView.setTileProvider(array);

    mMapView.getController().setZoom(29.);
    // cf. https://fr.wikipedia.org/wiki/Point_z%C3%A9ro_des_routes_de_France
    // In English: starting point of all French roads
    mMapView.setExpectedCenter(new GeoPoint(48.85340215825712, 2.348784611094743));
    mMapView.invalidate();
}
 
Example #7
Source File: SampleAnimateTo.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void addOverlays() {
    super.addOverlays();

    final DisplayMetrics dm = getActivity().getResources().getDisplayMetrics();
    mScaleBarOverlay = new ScaleBarOverlay(mMapView);
    mScaleBarOverlay.setCentred(true);
    mScaleBarOverlay.setScaleBarOffset(dm.widthPixels / 2, 10);
    mMapView.getOverlays().add(mScaleBarOverlay);

    // according to https://www.flickr.com/places/info/12589342
    final GeoPoint manhattanCenter = new GeoPoint(40.7909, -73.9664);
    final BoundingBox manhattanBoundingBox = new BoundingBox(40.8820, -73.9067, 40.6829, -74.0479);
    // testing a "single point bounding box" (actually using zoom fallback in animateTo)
    mList.add(new DataRegion("dummy1", "Manhattan - single point",
            new BoundingBox(manhattanCenter.getLatitude(), manhattanCenter.getLongitude(), manhattanCenter.getLatitude(), manhattanCenter.getLongitude())));
    // testing a "single latitude bounding box"
    mList.add(new DataRegion("dummy2", "Manhattan - single latitude",
            new BoundingBox(manhattanCenter.getLatitude(), manhattanBoundingBox.getLonEast(), manhattanCenter.getLatitude(), manhattanBoundingBox.getLonWest())));
    // testing a "single longitude bounding box"
    mList.add(new DataRegion("dummy3", "Manhattan - single longitude",
            new BoundingBox(manhattanBoundingBox.getLatNorth(), manhattanCenter.getLongitude(), manhattanBoundingBox.getLatSouth(), manhattanCenter.getLongitude())));
    // testing a "single longitude bounding box"
    mList.add(new DataRegion("dummy4", "Manhattan - box", manhattanBoundingBox));

    try {
        mList.addAll(new DataRegionLoader(getActivity(), R.raw.data_region_usstates).getList().values());
    } catch(Exception e) {
        throw new IllegalArgumentException(e);
    }

    mMapView.post(new Runnable() {
        @Override
        public void run() {
            show();
        }
    });
}
 
Example #8
Source File: MapsActivity.java    From Finder with GNU General Public License v3.0 4 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Context ctx = getApplicationContext();
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
    Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);

    setContentView(R.layout.activity_open_map);
    SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    map = findViewById(R.id.map2);
    Configuration.getInstance().setTileFileSystemCacheMaxBytes(1024*1024*Long.parseLong(sPref.getString("cache_size", "5")));
    Configuration.getInstance().setTileFileSystemCacheTrimBytes(512*1024*Long.parseLong(sPref.getString("cache_size", "5")));  // trim storage to ~50% from max after oversize limit


    if (sPref.getBoolean("satellite", false)) {
        final MapBoxTileSource tileSource = new MapBoxTileSource();
        tileSource.retrieveAccessToken(this);
        tileSource.retrieveMapBoxMapId(this);
        map.setTileSource(tileSource);
    } else {
        map.setTileSource(TileSourceFactory.MAPNIK);
    }


    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);
    mapController = map.getController();

    CopyrightOverlay copyOverlay = new CopyrightOverlay(this);
    copyOverlay.setAlignRight(true);
    map.getOverlays().add(copyOverlay);

    ScaleBarOverlay scaleBar= new ScaleBarOverlay(map);
    scaleBar.setUnitsOfMeasure(ScaleBarOverlay.UnitsOfMeasure.metric);
    scaleBar.setScaleBarOffset(getResources().getDisplayMetrics().widthPixels/2, 50);
    scaleBar.setCentred(true);
    map.getOverlays().add(scaleBar);

    GpsMyLocationProvider gpsProvider = new GpsMyLocationProvider(this.getBaseContext());
    MyLocationNewOverlay myLoc = new MyLocationNewOverlay(gpsProvider, map);
    myLoc.setDrawAccuracyEnabled(true);
    map.getOverlays().add(myLoc);

    CompassOverlay compasOver = new CompassOverlay(this.getBaseContext(), map);
    compasOver.enableCompass();
    map.getOverlays().add(compasOver);

    dBase baseConnect = new dBase(this);
    db = baseConnect.getWritableDatabase();

    Intent intent = this.getIntent();
    mapController.setZoom(intent.getDoubleExtra("zoom", 15.0d));
    String act = intent.getAction();
    if (act.equals("track")) {
        track_id = intent.getIntExtra("track_id", 0);
        line = new Polyline(map);
        line.setColor(Color.BLUE);
        line.setInfoWindow(null);  //delete popup label from track
        line.setGeodesic(true);  //draw "true" lines instead simple lines (great circles)
        trackRedraw();
        map.getOverlays().add(line);
    } else {
        String accuracy = intent.getStringExtra("accuracy");
        GeoPoint startPoint = new GeoPoint(intent.getDoubleExtra("lat", 0d), intent.getDoubleExtra("lon", 0d));
        mapController.setCenter(startPoint);
        Marker startMarker = new Marker(map);
        startMarker.setPosition(startPoint);
        startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
        map.getOverlays().add(startMarker);
        startMarker.setTitle(accuracy);
    }

    //receiver to map updating
    LocalBroadcastManager.getInstance(this).registerReceiver(updMap, new IntentFilter("update_map"));
}
 
Example #9
Source File: MapActivity.java    From ActivityDiary with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Context ctx = getApplicationContext();
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View contentView = inflater.inflate(R.layout.activity_map, null, false);

    setContent(contentView);

    noMap = (TextView) findViewById(R.id.noMap);

    map = (MapView) findViewById(R.id.map);
    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setTilesScaledToDpi(true);
    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    IMapController mapController = map.getController();
    mapController.setZoom(14.0);
    GeoPoint startPoint = new GeoPoint(LocationHelper.helper.getCurrentLocation());
    mapController.setCenter(startPoint);

    CopyrightOverlay copyrightOverlay = new CopyrightOverlay(this);
    copyrightOverlay.setTextSize(10);
    map.getOverlays().add(copyrightOverlay);

    ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(map);
    map.getOverlays().add(scaleBarOverlay);
    // Scale bar tries to draw as 1-inch, so to put it in the top center, set x offset to
    // half screen width, minus half an inch.
    scaleBarOverlay.setScaleBarOffset(
            (int) (getResources().getDisplayMetrics().widthPixels / 2 - getResources()
                    .getDisplayMetrics().xdpi / 2), 10);

    getLoaderManager().initLoader(LOADER_ID_INIT, null, this);

    mDrawerToggle.setDrawerIndicatorEnabled(false);
}
 
Example #10
Source File: StarterMapFragment.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final Context context = this.getActivity();
    final DisplayMetrics dm = context.getResources().getDisplayMetrics();

    mPrefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);


    //My Location
    //note you have handle the permissions yourself, the overlay did not do it for you
    mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(context), mMapView);
    mLocationOverlay.enableMyLocation();
    mMapView.getOverlays().add(this.mLocationOverlay);



    //Mini map
    mMinimapOverlay = new MinimapOverlay(context, mMapView.getTileRequestCompleteHandler());
    mMinimapOverlay.setWidth(dm.widthPixels / 5);
    mMinimapOverlay.setHeight(dm.heightPixels / 5);
    mMapView.getOverlays().add(this.mMinimapOverlay);



    //Copyright overlay
    mCopyrightOverlay = new CopyrightOverlay(context);
    //i hate this very much, but it seems as if certain versions of android and/or
    //device types handle screen offsets differently
    mMapView.getOverlays().add(this.mCopyrightOverlay);




    //On screen compass
    mCompassOverlay = new CompassOverlay(context, new InternalCompassOrientationProvider(context),
        mMapView);
    mCompassOverlay.enableCompass();
    mMapView.getOverlays().add(this.mCompassOverlay);


    //map scale
    mScaleBarOverlay = new ScaleBarOverlay(mMapView);
    mScaleBarOverlay.setCentred(true);
    mScaleBarOverlay.setScaleBarOffset(dm.widthPixels / 2, 10);
    mMapView.getOverlays().add(this.mScaleBarOverlay);



    //support for map rotation
    mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
    mRotationGestureOverlay.setEnabled(true);
    mMapView.getOverlays().add(this.mRotationGestureOverlay);


    //needed for pinch zooms
    mMapView.setMultiTouchControls(true);

    //scales tiles to the current screen's DPI, helps with readability of labels
    mMapView.setTilesScaledToDpi(true);

    //the rest of this is restoring the last map location the user looked at
    final float zoomLevel = mPrefs.getFloat(PREFS_ZOOM_LEVEL_DOUBLE, 1);
    mMapView.getController().setZoom(zoomLevel);
    final float orientation = mPrefs.getFloat(PREFS_ORIENTATION, 0);
    mMapView.setMapOrientation(orientation, false);
    final String latitudeString = mPrefs.getString(PREFS_LATITUDE_STRING, "1.0");
    final String longitudeString = mPrefs.getString(PREFS_LONGITUDE_STRING, "1.0");
    final double latitude = Double.valueOf(latitudeString);
    final double longitude = Double.valueOf(longitudeString);
    mMapView.setExpectedCenter(new GeoPoint(latitude, longitude));

    setHasOptionsMenu(true);
}