Java Code Examples for org.osmdroid.views.MapView#setTileSource()

The following examples show how to use org.osmdroid.views.MapView#setTileSource() . 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: CreatePoiFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private void mapSetup() {
    map = (MapView) getActivity().findViewById(R.id.createPoiMap);

    //important! set your user agent to prevent getting banned from the osm servers
    Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));

    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setTilesScaledToDpi(true);

    // add multi-touch capability
    map.setMultiTouchControls(true);

    // add compass to map
    CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map);
    compassOverlay.enableCompass();
    map.getOverlays().add(compassOverlay);

    // get map controller
    IMapController controller = map.getController();

    GeoPoint position = new GeoPoint(latitude, longitude);
    controller.setCenter(position);
    controller.setZoom(18);
    MapUtils.addMarker(getActivity(), map, latitude, longitude);
}
 
Example 2
Source File: MapFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private void mapSetup() {
    map = (MapView) getActivity().findViewById(R.id.map);  // create basic map
    mController = map.getController(); // get map controller
    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setTilesScaledToDpi(true);
    map.setMultiTouchControls(true);

    // add compass to map
    CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map);
    compassOverlay.enableCompass();
    map.getOverlays().add(compassOverlay);

    //attach listeners
    MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this);
    map.getOverlays().add(0, mapEventsOverlay);
    setupMyLocation();
}
 
Example 3
Source File: PoiDetailsFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private void setupMapPreview(double lat, double lon, String markerTitle) {
    //important! set your user agent to prevent getting banned from the osm servers
    Configuration.getInstance().load(getDialog().getContext(), PreferenceManager.getDefaultSharedPreferences(getDialog().getContext()));

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

    // add compass to map
    CompassOverlay compassOverlay = new CompassOverlay(getDialog().getContext(), new InternalCompassOrientationProvider(getDialog().getContext()), map);
    compassOverlay.enableCompass();
    map.getOverlays().add(compassOverlay);

    // get map controller
    IMapController controller = map.getController();
    GeoPoint position = new GeoPoint(lat, lon);
    controller.setCenter(position);
    controller.setZoom(18);

    MapUtils.addMarker(getActivity(), map, lat, lon, markerTitle);
}
 
Example 4
Source File: SampleCacheDownloaderCustomUI.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View root = inflater.inflate(R.layout.sample_cachemgr, container, false);

    //prevent the action bar/toolbar menu in order to prevent tile source changes.
    //if this is enabled, playstore users could actually download large volumes of tiles
    //from tile sources that do not allow it., causing our app to get banned, which would be
    //bad
    setHasOptionsMenu(false);

    mMapView = new MapView(getActivity());
    mMapView.setTileSource(TileSourceFactory.USGS_SAT);
    ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView);
    btnCache = root.findViewById(R.id.btnCache);
    btnCache.setOnClickListener(this);
    mgr = new CacheManager(mMapView);
    return root;
}
 
Example 5
Source File: SampleCacheDownloaderArchive.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View root = inflater.inflate(R.layout.sample_cachemgr, container,false);

    //prevent the action bar/toolbar menu in order to prevent tile source changes.
    //if this is enabled, playstore users could actually download large volumes of tiles
    //from tile sources that do not allow it., causing our app to get banned, which would be
    //bad
    setHasOptionsMenu(false);

    mMapView = new MapView(getActivity());
    mMapView.setTileSource(TileSourceFactory.USGS_SAT);
    ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView);
    btnCache = root.findViewById(R.id.btnCache);
    btnCache.setOnClickListener(this);
    return root;
}
 
Example 6
Source File: SampleCacheDelete.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View root = inflater.inflate(R.layout.sample_cachemgr, container, false);

    //prevent the action bar/toolbar menu in order to prevent tile source changes.
    //if this is enabled, playstore users could actually download large volumes of tiles
    //from tile sources that do not allow it., causing our app to get banned, which would be
    //bad
    setHasOptionsMenu(false);

    mMapView = new MapView(getActivity());
    mMapView.setTileSource(TileSourceFactory.USGS_SAT);
    ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView);
    btnCache = root.findViewById(R.id.btnCache);
    btnCache.setOnClickListener(this);
    mgr = new CacheManager(mMapView);
    return root;
}
 
Example 7
Source File: SampleCacheDownloader.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View root = inflater.inflate(R.layout.sample_cachemgr, container,false);

    //prevent the action bar/toolbar menu in order to prevent tile source changes.
    //if this is enabled, playstore users could actually download large volumes of tiles
    //from tile sources that do not allow it., causing our app to get banned, which would be
    //bad
    setHasOptionsMenu(false);


    mMapView = new MapView(getActivity());
    mMapView.setTileSource(TileSourceFactory.USGS_SAT);
    ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView);
    btnCache = root.findViewById(R.id.btnCache);
    btnCache.setOnClickListener(this);
    mgr = new CacheManager(mMapView);
    return root;
}
 
Example 8
Source File: TilesOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem pItem, final int pMenuIdOffset,
		final MapView pMapView) {

	final int menuId = pItem.getItemId() - pMenuIdOffset;
	if ((menuId >= MENU_TILE_SOURCE_STARTING_ID)
			&& (menuId < MENU_TILE_SOURCE_STARTING_ID
					+ TileSourceFactory.getTileSources().size())) {
		pMapView.setTileSource(TileSourceFactory.getTileSources().get(
				menuId - MENU_TILE_SOURCE_STARTING_ID));
		return true;
	} else if (menuId == MENU_OFFLINE) {
		final boolean useDataConnection = !pMapView.useDataConnection();
		pMapView.setUseDataConnection(useDataConnection);
		return true;
	} else if (menuId == MENU_STATES) {
		Toast.makeText(pMapView.getContext(), mTileStates.toString(), Toast.LENGTH_SHORT).show();
		return true;
	} else if (menuId == MENU_SNAPSHOT) {
		final MapSnapshot mapSnapshot = new MapSnapshot(new MapSnapshot.MapSnapshotable() {
			@Override
			public void callback(final MapSnapshot pMapSketch) {
				if (pMapSketch.getStatus() != MapSnapshot.Status.CANVAS_OK) {
					return;
				}
				final File file = new File(Configuration.getInstance().getOsmdroidBasePath(), "snapshot.png");
				pMapSketch.save(file);
				pMapSketch.onDetach();
			}
		}, MapSnapshot.INCLUDE_FLAG_UPTODATE, pMapView);
		Thread t = new Thread(mapSnapshot);
		t.setName("TilesOverlaySnapShotThread");
		t.start();
		return true;
	} else {
		return false;
	}
}
 
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);
}