org.osmdroid.tileprovider.tilesource.XYTileSource Java Examples

The following examples show how to use org.osmdroid.tileprovider.tilesource.XYTileSource. 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: 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 #2
Source File: Bug512CacheManagerWp.java    From osmdroid with Apache License 2.0 5 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);

    btnCache = root.findViewById(R.id.btnCache);
    btnCache.setOnClickListener(this);
    btnCache.setText("Run job (watch logcat output)");

    // Workaround for failing unit test due to issues with https connections on API < 9
    // https://github.com/osmdroid/osmdroid/issues/1048
    // https://github.com/osmdroid/osmdroid/issues/1051
    // Also works around an issue with some emulator image that do not update their time/date
    // correctly and stay on 0 unix time. This causes SSLExceptions due to the validity of the
    // certificates.
    OnlineTileSourceBase onlineTileSourceBase = new XYTileSource("Mapnik",
                0, 19, 256, ".png",
                new String[]{
                        "http://a.tile.openstreetmap.org/",
                        "http://b.tile.openstreetmap.org/",
                        "http://c.tile.openstreetmap.org/"}, "© OpenStreetMap contributors");

    mMapView = new MapView(getActivity(), new MapTileProviderBasic(
            getActivity().getApplicationContext(), onlineTileSourceBase));

    ((LinearLayout) root.findViewById(R.id.mapview)).addView(mMapView);

    return root;
}
 
Example #3
Source File: SampleWithTilesOverlayAndCustomTileSource.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	// Setup base map
	setContentView(R.layout.activity_samplewithtilesoverlayandcustomtilesource);

	Toolbar toolbar = findViewById(R.id.my_toolbar);
	setSupportActionBar(toolbar);

	//noinspection ConstantConditions
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setDisplayShowHomeEnabled(true);

	final LinearLayout mapContainer = findViewById(R.id.map_container);

	mMapView = new MapView(this);
	mMapView.setTilesScaledToDpi(true);

	//Copyright overlay
	String copyrightNotice = mMapView.getTileProvider().getTileSource().getCopyrightNotice();
	CopyrightOverlay copyrightOverlay = new CopyrightOverlay(this);
	copyrightOverlay.setCopyrightNotice(copyrightNotice);
	mMapView.getOverlays().add(copyrightOverlay);

	mapContainer.addView(mMapView, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.MATCH_PARENT));
       mMapView.getZoomController().setVisibility(
               CustomZoomButtonsController.Visibility.SHOW_AND_FADEOUT);

	// zoom to the netherlands
	mMapView.getController().setZoom(7D);
	mMapView.getController().setCenter(new GeoPoint(51.5D, 5.4D));

	// Add tiles layer with custom tile source
	final MapTileProviderBasic tileProvider = new MapTileProviderBasic(getApplicationContext());
	final ITileSource tileSource = new XYTileSource("FietsRegionaal",  3, 18, 256, ".png",
			new String[] { "http://overlay.openstreetmap.nl/openfietskaart-rcn/" });
	tileProvider.setTileSource(tileSource);
	tileProvider.getTileRequestCompleteHandlers().add(mMapView.getTileRequestCompleteHandler());
	final TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, this.getBaseContext());
	tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
	mMapView.getOverlays().add(tilesOverlay);
}