Search in sources :

Example 1 with GridMarkerClusterer

use of org.osmdroid.bonuspack.clustering.GridMarkerClusterer in project OpenBikeSharing by bparmentier.

the class MapActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    stationsDataSource = new StationsDataSource(this);
    ArrayList<Station> stations = stationsDataSource.getStations();
    map = (MapView) findViewById(R.id.mapView);
    stationMarkerInfoWindow = new StationMarkerInfoWindow(R.layout.bonuspack_bubble, map);
    /* handling map events */
    MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this, this);
    map.getOverlays().add(0, mapEventsOverlay);
    /* markers list */
    GridMarkerClusterer stationsMarkers = new GridMarkerClusterer();
    Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster);
    Bitmap clusterIcon = ((BitmapDrawable) clusterIconD).getBitmap();
    map.getOverlays().add(stationsMarkers);
    stationsMarkers.setIcon(clusterIcon);
    stationsMarkers.setGridSize(100);
    for (final Station station : stations) {
        stationsMarkers.add(createStationMarker(station));
    }
    map.invalidate();
    map.setMultiTouchControls(true);
    map.setBuiltInZoomControls(true);
    map.setMinZoomLevel(3);
    /* map tile source */
    String mapLayer = settings.getString(PREF_KEY_MAP_LAYER, "");
    switch(mapLayer) {
        case MAP_LAYER_MAPNIK:
            map.setTileSource(TileSourceFactory.MAPNIK);
            break;
        case MAP_LAYER_CYCLEMAP:
            map.setTileSource(TileSourceFactory.CYCLEMAP);
            break;
        case MAP_LAYER_OSMPUBLICTRANSPORT:
            map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
            break;
        default:
            map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
            break;
    }
    GpsMyLocationProvider imlp = new GpsMyLocationProvider(this.getBaseContext());
    imlp.setLocationUpdateMinDistance(1000);
    imlp.setLocationUpdateMinTime(60000);
    map.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
        }
    });
    myLocationOverlay = new MyLocationNewOverlay(imlp, this.map);
    myLocationOverlay.enableMyLocation();
    map.getOverlays().add(this.myLocationOverlay);
    mapController = map.getController();
    if (savedInstanceState != null) {
        mapController.setZoom(savedInstanceState.getInt(MAP_CURRENT_ZOOM_KEY));
        mapController.setCenter(new GeoPoint(savedInstanceState.getDouble(MAP_CENTER_LAT_KEY), savedInstanceState.getDouble(MAP_CENTER_LON_KEY)));
    } else {
        LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        Location userLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (userLocation != null) {
            mapController.setZoom(16);
            mapController.animateTo(new GeoPoint(userLocation));
        } else {
            double bikeNetworkLatitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LATITUDE, 0));
            double bikeNetworkLongitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LONGITUDE, 0));
            mapController.setZoom(13);
            mapController.setCenter(new GeoPoint(bikeNetworkLatitude, bikeNetworkLongitude));
            Toast.makeText(this, R.string.location_not_found, Toast.LENGTH_LONG).show();
        }
    }
}
Also used : LocationManager(android.location.LocationManager) SharedPreferences(android.content.SharedPreferences) MapEventsOverlay(org.osmdroid.views.overlay.MapEventsOverlay) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GpsMyLocationProvider(org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider) MyLocationNewOverlay(org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) View(android.view.View) MapView(org.osmdroid.views.MapView) Station(be.brunoparmentier.openbikesharing.app.models.Station) GeoPoint(org.osmdroid.util.GeoPoint) Bitmap(android.graphics.Bitmap) GridMarkerClusterer(org.osmdroid.bonuspack.clustering.GridMarkerClusterer) StationsDataSource(be.brunoparmentier.openbikesharing.app.db.StationsDataSource) Location(android.location.Location)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Location (android.location.Location)1 LocationManager (android.location.LocationManager)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 StationsDataSource (be.brunoparmentier.openbikesharing.app.db.StationsDataSource)1 Station (be.brunoparmentier.openbikesharing.app.models.Station)1 GridMarkerClusterer (org.osmdroid.bonuspack.clustering.GridMarkerClusterer)1 GeoPoint (org.osmdroid.util.GeoPoint)1 MapView (org.osmdroid.views.MapView)1 MapEventsOverlay (org.osmdroid.views.overlay.MapEventsOverlay)1 GpsMyLocationProvider (org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider)1 MyLocationNewOverlay (org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay)1