Search in sources :

Example 1 with MapBoxTileSource

use of org.osmdroid.tileprovider.tilesource.MapBoxTileSource in project osmbonuspack by MKergall.

the class MapActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
    MapsForgeTileSource.createInstance(getApplication());
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.main, null);
    setContentView(v);
    SharedPreferences prefs = getSharedPreferences("OSMNAVIGATOR", MODE_PRIVATE);
    MAPBOXSATELLITELABELLED = new MapBoxTileSource("MapBoxSatelliteLabelled", 1, 19, 256, ".png");
    ((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveAccessToken(this);
    ((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveMapBoxMapId(this);
    TileSourceFactory.addTileSource(MAPBOXSATELLITELABELLED);
    graphHopperApiKey = ManifestUtil.retrieveKey(this, "GRAPHHOPPER_API_KEY");
    flickrApiKey = ManifestUtil.retrieveKey(this, "FLICKR_API_KEY");
    geonamesAccount = ManifestUtil.retrieveKey(this, "GEONAMES_ACCOUNT");
    mapzenApiKey = ManifestUtil.retrieveKey(this, "MAPZEN_APIKEY");
    map = (MapView) v.findViewById(R.id.map);
    String tileProviderName = prefs.getString("TILE_PROVIDER", "Mapnik");
    mNightMode = prefs.getBoolean("NIGHT_MODE", false);
    if ("rendertheme-v4".equals(tileProviderName)) {
        setMapsForgeTileProvider();
    } else {
        try {
            ITileSource tileSource = TileSourceFactory.getTileSource(tileProviderName);
            map.setTileSource(tileSource);
        } catch (IllegalArgumentException e) {
            map.setTileSource(TileSourceFactory.MAPNIK);
        }
    }
    if (mNightMode)
        map.getOverlayManager().getTilesOverlay().setColorFilter(TilesOverlay.INVERT_COLORS);
    map.setTilesScaledToDpi(true);
    map.setMultiTouchControls(true);
    map.setMinZoomLevel(1.0);
    map.setMaxZoomLevel(21.0);
    map.setVerticalMapRepetitionEnabled(false);
    map.setScrollableAreaLimitLatitude(TileSystem.MaxLatitude, -TileSystem.MaxLatitude, 0);
    // Toast.makeText(this, "H="+map.getHeight(), Toast.LENGTH_LONG).show();
    IMapController mapController = map.getController();
    // To use MapEventsReceiver methods, we add a MapEventsOverlay:
    MapEventsOverlay overlay = new MapEventsOverlay(this);
    map.getOverlays().add(overlay);
    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    // mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    // mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    // map prefs:
    mapController.setZoom((double) prefs.getFloat("MAP_ZOOM_LEVEL_F", 5));
    mapController.setCenter(new GeoPoint((double) prefs.getFloat("MAP_CENTER_LAT", 48.5f), (double) prefs.getFloat("MAP_CENTER_LON", 2.5f)));
    myLocationOverlay = new DirectedLocationOverlay(this);
    map.getOverlays().add(myLocationOverlay);
    if (savedInstanceState == null) {
        Location location = null;
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (location == null)
                location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
        if (location != null) {
            // location known:
            onLocationChanged(location);
        } else {
            // no location known: hide myLocationOverlay
            myLocationOverlay.setEnabled(false);
        }
        startPoint = null;
        destinationPoint = null;
        viaPoints = new ArrayList<GeoPoint>();
    } else {
        myLocationOverlay.setLocation((GeoPoint) savedInstanceState.getParcelable("location"));
        // TODO: restore other aspects of myLocationOverlay...
        startPoint = savedInstanceState.getParcelable("start");
        destinationPoint = savedInstanceState.getParcelable("destination");
        viaPoints = savedInstanceState.getParcelableArrayList("viapoints");
    }
    ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(map);
    map.getOverlays().add(scaleBarOverlay);
    // Itinerary markers:
    mItineraryMarkers = new FolderOverlay();
    mItineraryMarkers.setName(getString(R.string.itinerary_markers_title));
    map.getOverlays().add(mItineraryMarkers);
    mViaPointInfoWindow = new ViaPointInfoWindow(R.layout.itinerary_bubble, map);
    updateUIWithItineraryMarkers();
    // Tracking system:
    mTrackingModeButton = (Button) findViewById(R.id.buttonTrackingMode);
    mTrackingModeButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            mTrackingMode = !mTrackingMode;
            updateUIWithTrackingMode();
        }
    });
    if (savedInstanceState != null) {
        mTrackingMode = savedInstanceState.getBoolean("tracking_mode");
        updateUIWithTrackingMode();
    } else
        mTrackingMode = false;
    // TODO restore state
    mIsRecordingTrack = false;
    AutoCompleteOnPreferences departureText = (AutoCompleteOnPreferences) findViewById(R.id.editDeparture);
    departureText.setPrefKeys(SHARED_PREFS_APPKEY, PREF_LOCATIONS_KEY);
    Button searchDepButton = (Button) findViewById(R.id.buttonSearchDep);
    searchDepButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            handleSearchButton(START_INDEX, R.id.editDeparture);
        }
    });
    AutoCompleteOnPreferences destinationText = (AutoCompleteOnPreferences) findViewById(R.id.editDestination);
    destinationText.setPrefKeys(SHARED_PREFS_APPKEY, PREF_LOCATIONS_KEY);
    Button searchDestButton = (Button) findViewById(R.id.buttonSearchDest);
    searchDestButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            handleSearchButton(DEST_INDEX, R.id.editDestination);
        }
    });
    View expander = findViewById(R.id.expander);
    expander.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            View searchPanel = findViewById(R.id.search_panel);
            if (searchPanel.getVisibility() == View.VISIBLE) {
                searchPanel.setVisibility(View.GONE);
            } else {
                searchPanel.setVisibility(View.VISIBLE);
            }
        }
    });
    View searchPanel = findViewById(R.id.search_panel);
    searchPanel.setVisibility(prefs.getInt("PANEL_VISIBILITY", View.VISIBLE));
    registerForContextMenu(searchDestButton);
    // context menu for clicking on the map is registered on this button.
    // (a little bit strange, but if we register it on mapView, it will catch map drag events)
    // Route and Directions
    mWhichRouteProvider = prefs.getInt("ROUTE_PROVIDER", OSRM);
    mRoadNodeMarkers = new FolderOverlay();
    mRoadNodeMarkers.setName("Route Steps");
    map.getOverlays().add(mRoadNodeMarkers);
    if (savedInstanceState != null) {
        // STATIC mRoad = savedInstanceState.getParcelable("road");
        updateUIWithRoads(mRoads);
    }
    // POIs:
    // POI search interface:
    String[] poiTags = getResources().getStringArray(R.array.poi_tags);
    poiTagText = (AutoCompleteTextView) findViewById(R.id.poiTag);
    ArrayAdapter<String> poiAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, poiTags);
    poiTagText.setAdapter(poiAdapter);
    Button setPOITagButton = (Button) findViewById(R.id.buttonSetPOITag);
    setPOITagButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // Hide the soft keyboard:
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(poiTagText.getWindowToken(), 0);
            // Start search:
            String feature = poiTagText.getText().toString();
            if (!feature.equals(""))
                Toast.makeText(v.getContext(), "Searching:\n" + feature, Toast.LENGTH_LONG).show();
            getPOIAsync(feature);
        }
    });
    // POI markers:
    mPoiMarkers = new RadiusMarkerClusterer(this);
    Bitmap clusterIcon = BonusPackHelper.getBitmapFromVectorDrawable(this, R.drawable.marker_poi_cluster);
    mPoiMarkers.setIcon(clusterIcon);
    mPoiMarkers.mAnchorV = Marker.ANCHOR_BOTTOM;
    mPoiMarkers.mTextAnchorU = 0.70f;
    mPoiMarkers.mTextAnchorV = 0.27f;
    mPoiMarkers.getTextPaint().setTextSize(12 * getResources().getDisplayMetrics().density);
    map.getOverlays().add(mPoiMarkers);
    if (savedInstanceState != null) {
        // STATIC - mPOIs = savedInstanceState.getParcelableArrayList("poi");
        updateUIWithPOI(mPOIs, "");
    }
    // KML handling:
    mKmlOverlay = null;
    if (savedInstanceState != null) {
        // STATIC - mKmlDocument = savedInstanceState.getParcelable("kml");
        updateUIWithKml();
    } else {
        // first launch:
        mKmlDocument = new KmlDocument();
        mKmlStack = new Stack<KmlFeature>();
        mKmlClipboard = new KmlFolder();
        // check if intent has been passed with a kml URI to load (url or file)
        Intent onCreateIntent = getIntent();
        if (onCreateIntent.getAction().equals(Intent.ACTION_VIEW)) {
            String uri = onCreateIntent.getDataString();
            openFile(uri, true, false);
        }
    }
    // Sharing
    mFriendsManager = new FriendsManager(this, map);
    mFriendsManager.onCreate(savedInstanceState);
    checkPermissions();
    Button menuButton = (Button) findViewById(R.id.buttonMenu);
    menuButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            openOptionsMenu();
        }
    });
}
Also used : MapEventsOverlay(org.osmdroid.views.overlay.MapEventsOverlay) InputMethodManager(android.view.inputmethod.InputMethodManager) DirectedLocationOverlay(org.osmdroid.views.overlay.mylocation.DirectedLocationOverlay) ScaleBarOverlay(org.osmdroid.views.overlay.ScaleBarOverlay) GeoPoint(org.osmdroid.util.GeoPoint) Bitmap(android.graphics.Bitmap) Button(android.widget.Button) IMapController(org.osmdroid.api.IMapController) FolderOverlay(org.osmdroid.views.overlay.FolderOverlay) SharedPreferences(android.content.SharedPreferences) RadiusMarkerClusterer(org.osmdroid.bonuspack.clustering.RadiusMarkerClusterer) Intent(android.content.Intent) AutoCompleteTextView(android.widget.AutoCompleteTextView) MapView(org.osmdroid.views.MapView) View(android.view.View) TextView(android.widget.TextView) KmlFeature(org.osmdroid.bonuspack.kml.KmlFeature) LayoutInflater(android.view.LayoutInflater) KmlFolder(org.osmdroid.bonuspack.kml.KmlFolder) MapBoxTileSource(org.osmdroid.tileprovider.tilesource.MapBoxTileSource) ITileSource(org.osmdroid.tileprovider.tilesource.ITileSource) ArrayAdapter(android.widget.ArrayAdapter) KmlDocument(org.osmdroid.bonuspack.kml.KmlDocument) Location(android.location.Location)

Aggregations

Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 Location (android.location.Location)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 ArrayAdapter (android.widget.ArrayAdapter)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 IMapController (org.osmdroid.api.IMapController)1 RadiusMarkerClusterer (org.osmdroid.bonuspack.clustering.RadiusMarkerClusterer)1 KmlDocument (org.osmdroid.bonuspack.kml.KmlDocument)1 KmlFeature (org.osmdroid.bonuspack.kml.KmlFeature)1 KmlFolder (org.osmdroid.bonuspack.kml.KmlFolder)1 ITileSource (org.osmdroid.tileprovider.tilesource.ITileSource)1 MapBoxTileSource (org.osmdroid.tileprovider.tilesource.MapBoxTileSource)1 GeoPoint (org.osmdroid.util.GeoPoint)1 MapView (org.osmdroid.views.MapView)1