org.osmdroid.tileprovider.tilesource.TileSourceFactory Java Examples

The following examples show how to use org.osmdroid.tileprovider.tilesource.TileSourceFactory. 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: 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 #2
Source File: TilesOverlay.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu pMenu, final int pMenuIdOffset,
		final MapView pMapView) {
	final SubMenu mapMenu = pMenu.addSubMenu(0, Menu.NONE, Menu.NONE,
			R.string.map_mode).setIcon(R.drawable.ic_menu_mapmode);

	for (int a = 0; a < TileSourceFactory.getTileSources().size(); a++) {
		final ITileSource tileSource = TileSourceFactory.getTileSources().get(a);
		mapMenu.add(MENU_MAP_MODE + pMenuIdOffset, MENU_TILE_SOURCE_STARTING_ID + a
				+ pMenuIdOffset, Menu.NONE, tileSource.name());
	}
	mapMenu.setGroupCheckable(MENU_MAP_MODE + pMenuIdOffset, true, true);

	if (ctx!=null) {
		final String title = ctx.getString(
				pMapView.useDataConnection() ? R.string.set_mode_offline
						: R.string.set_mode_online);
		final Drawable icon = ctx.getResources().getDrawable(R.drawable.ic_menu_offline);
		pMenu.add(0, MENU_OFFLINE + pMenuIdOffset, Menu.NONE, title).setIcon(icon);
		pMenu.add(0, MENU_SNAPSHOT + pMenuIdOffset, Menu.NONE, R.string.snapshot);
		pMenu.add(0, MENU_STATES + pMenuIdOffset, Menu.NONE, R.string.states);
	}
	return true;
}
 
Example #3
Source File: LocationActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onResume() {
	super.onResume();
	Configuration.getInstance().load(this, getPreferences());
	map.onResume();
	this.setMyLoc(null);
	requestLocationUpdates();
	updateLocationMarkers();
	updateUi();
	map.setTileSource(TileSourceFactory.MAPNIK);
	map.setTilesScaledToDpi(true);

	if (mapAtInitialLoc()) {
		gotoLoc();
	}
}
 
Example #4
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 #5
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 #6
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 #7
Source File: EditPoiFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private void mapSetup() {
    map = 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);
    map.setMultiTouchControls(true);

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

    IMapController controller = map.getController();
    GeoPoint position = new GeoPoint(POI.getLatitude(), POI.getLongitude());
    controller.setCenter(position);
    controller.setZoom(18);

    MapUtils.addMarker(getActivity(), map, POI.getLatitude(), POI.getLongitude());
}
 
Example #8
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 #9
Source File: PoiListFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Show marker of POI on map preview, on {@link RecyclerView} long press
 *
 * @param element POI to  display
 */
private void openMapPreview(Element element) {
    if (map == null) {
        //important! set your user agent to prevent getting banned from the osm servers
        Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));

        map = getActivity().findViewById(R.id.mapPoiList);
        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(element.lat, element.lon);
    controller.setCenter(position);
    controller.setZoom(18);

    MapUtils.addMarker(getActivity(), map, element);
}
 
Example #10
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 #11
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 #12
Source File: NativeOpenStreetMapController.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public void setMapType(MapType type) {
  switch (type) {
    case ROADS:
      tileType = type;
      view.setTileSource(TileSourceFactory.MAPNIK);
      break;
    case AERIAL:
      tileType = type;
      view.setTileSource(TileSourceFactory.USGS_SAT);
      break;
    case TERRAIN:
      tileType = type;
      view.setTileSource(TileSourceFactory.USGS_TOPO);
      break;
    case UNKNOWN:
    default:
      break;
  }
}
 
Example #13
Source File: SampleSplitScreen.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void addOverlays() {
    mMapView.setTileSource(TileSourceFactory.MAPNIK);
    mMapView.getController().setZoom(1);
    mMapView.getController().setCenter(new GeoPoint(39.8282, 98.5795));
    mMapView2.getController().setZoom(1);
    mMapView2.getController().setCenter(new GeoPoint(39.8282, 98.5795));
    mMapView.setMapListener(this);
    //hey, check out the other constructors for mapbox, there's a few options to load up your
    //access token and tile set preferences
    mMapView2.setTileSource(new MapBoxTileSource(getContext()));
    mMapView2.setMapListener(this);

    mMapView2.setMultiTouchControls(true);
    mMapView2.setTilesScaledToDpi(true);
}
 
Example #14
Source File: MapViewerOsmDroid.java    From AIMSICDL with GNU General Public License v3.0 6 votes vote down vote up
private void setupMapType(int mapType) {
    mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
    // There are two other map types (hybrid and satellite), but we don't use them
    // as they are redundant (hybrid) and broken (satellite).
    switch (mapType) {
        case 0:
            mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
            break;
        case 1:
            mMap.setTileSource(TileSourceFactory.CYCLEMAP);
            break;
        default:
            mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
            break;
    }
}
 
Example #15
Source File: MapFragment.java    From AIMSICDL with GNU General Public License v3.0 6 votes vote down vote up
private void setupMapType(int mapType) {
    mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
    // There are two other map types (hybrid and satellite), but we don't use them
    // as they are redundant (hybrid) and broken (satellite).
    switch (mapType) {
        case 0:
            mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
            break;
        case 1:
            mMap.setTileSource(TileSourceFactory.CYCLEMAP);
            break;
        default:
            mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
            break;
    }
}
 
Example #16
Source File: SampleAssetsOnly.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void addOverlays() {
    this.mMapView.setUseDataConnection(false);
    MapTileAssetsProvider prov = new MapTileAssetsProvider(new SimpleRegisterReceiver(getContext()  ), getActivity().getAssets());

    this.mMapView.setTileProvider(new MapTileProviderArray(TileSourceFactory.MAPNIK, new SimpleRegisterReceiver(getContext()), new MapTileModuleProviderBase[]{ prov }));
}
 
Example #17
Source File: StarterMapFragment.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    final String tileSourceName = mPrefs.getString(PREFS_TILE_SOURCE,
        TileSourceFactory.DEFAULT_TILE_SOURCE.name());
    try {
        final ITileSource tileSource = TileSourceFactory.getTileSource(tileSourceName);
        mMapView.setTileSource(tileSource);
    } catch (final IllegalArgumentException e) {
        mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
    }

    mMapView.onResume();
}
 
Example #18
Source File: MapView.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
private ITileSource getTileSourceFromAttributes(final AttributeSet aAttributeSet) {

		ITileSource tileSource = TileSourceFactory.DEFAULT_TILE_SOURCE;

		if (aAttributeSet != null) {
			final String tileSourceAttr = aAttributeSet.getAttributeValue(null, "tilesource");
			if (tileSourceAttr != null) {
				try {
					final ITileSource r = TileSourceFactory.getTileSource(tileSourceAttr);
					Log.i(IMapView.LOGTAG,"Using tile source specified in layout attributes: " + r);
					tileSource = r;
				} catch (final IllegalArgumentException e) {
					Log.w(IMapView.LOGTAG,"Invalid tile source specified in layout attributes: " + tileSource);
				}
			}
		}

		if (aAttributeSet != null && tileSource instanceof IStyledTileSource) {
			final String style = aAttributeSet.getAttributeValue(null, "style");
			if (style == null) {
				Log.i(IMapView.LOGTAG,"Using default style: 1");
			} else {
				Log.i(IMapView.LOGTAG,"Using style specified in layout attributes: " + style);
				((IStyledTileSource<?>) tileSource).setStyle(style);
			}
		}

		Log.i(IMapView.LOGTAG,"Using tile source: " + tileSource.name());
		return tileSource;
	}
 
Example #19
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 #20
Source File: TilesOverlay.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(final Menu pMenu, final int pMenuIdOffset,
		final MapView pMapView) {
	final int index = TileSourceFactory.getTileSources().indexOf(
			pMapView.getTileProvider().getTileSource());
	if (index >= 0) {
		pMenu.findItem(MENU_TILE_SOURCE_STARTING_ID + index + pMenuIdOffset).setChecked(true);
	}

	pMenu.findItem(MENU_OFFLINE + pMenuIdOffset).setTitle(
					pMapView.useDataConnection() ? R.string.set_mode_offline
							: R.string.set_mode_online);

	return true;
}
 
Example #21
Source File: SampleOpenSeaMap.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void addOverlays(){
    super.addOverlays();
    mProvider = new MapTileProviderBasic(getContext());
    TilesOverlay seaMap = new TilesOverlay(mProvider, getContext());
    seaMap.setLoadingLineColor(Color.TRANSPARENT);
    seaMap.setLoadingBackgroundColor(Color.TRANSPARENT);
    seaMap.setLoadingDrawable(null);
    mProvider.setTileSource(TileSourceFactory.OPEN_SEAMAP);
    mMapView.getOverlays().add(seaMap);
    mMapView.postInvalidate();
    mMapView.getController().setCenter(new GeoPoint(40.65716,-74.06507));
    mMapView.getController().setZoom(18);
}
 
Example #22
Source File: LocationActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
protected void setupMapView(MapView mapView, final GeoPoint pos) {
	map = mapView;
	map.getOverlays().add(new CopyrightOverlay(this));
	map.setTileSource(TileSourceFactory.MAPNIK);
	map.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER);
	map.setMultiTouchControls(true);
	map.setTilesScaledToDpi(false);
	mapController = map.getController();
	mapController.setZoom(Config.Map.INITIAL_ZOOM_LEVEL);
	mapController.setCenter(pos);
}
 
Example #23
Source File: MapView.java    From android_frameworks_mapsv1 with Apache License 2.0 5 votes vote down vote up
public WrappedMapView(Context context, AttributeSet attrs) {
    super(context, new CustomResourceProxyImpl(context), new SafeMapTileProviderBasic(context,
            new SimpleRegisterReceiver(context), new SafeNetworkAvailabilityCheck(context),
            TileSourceFactory.DEFAULT_TILE_SOURCE), null, attrs);
    setMultiTouchControls(true);
    updateTileSource();
}
 
Example #24
Source File: WeathForceActivity.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_starter_mapview);

    Intent intent = getIntent();
    //if (intent)
    final double lat1 = 25.633;
    final double long1 = 71.094;

    //super important. Many tile servers, including open street maps, will BAN applications by user
    //agent. Do not use the sample application's user agent for your app! Use your own setting, such
    //as the app id.
    Configuration.getInstance().setUserAgentValue(getPackageName());

    mMapView = findViewById(R.id.mapview);
    mMapView.setTileSource(TileSourceFactory.MAPNIK);


    mCompassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this),
            mMapView);
    mCompassOverlay.enableCompass();
    mMapView.getOverlays().add(this.mCompassOverlay);

    addOverlays();

    GeoPoint startPoint = new GeoPoint(lat1, long1);
    IMapController mapController = mMapView.getController();
    mapController.setZoom(9);
    mapController.setCenter(startPoint);
    Marker startMarker = new Marker(mMapView);
    startMarker.setPosition(startPoint);
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    mMapView.getOverlays().add(startMarker);


    mMapView.invalidate();

}
 
Example #25
Source File: FPOsmDroidView.java    From FancyPlaces with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fancy_places_osmview, container, false);

    mMapView = (OsmMapViewScrollWorkaround) v.findViewById(R.id.fp_map_view);
    mMapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
    mMapView.setMultiTouchControls(true);
    mMapView.setTilesScaledToDpi(true);
    mMapView.setWorkaroundEnabled(true);

    mapHandler = new OsmMapHandler(mMapView, fancyPlaceSelectedCallback);
    mapHandler.setAdapter(parent.fancyPlaceArrayAdapter);

    locationHandler = ((FancyPlacesApplication) parent.getApplicationContext()).getLocationHandler();
    locationHandler.addOnLocationUpdatedListener(this);
    locationHandler.updateLocation(false);

    // add fab callback
    FloatingActionButton fab = (FloatingActionButton) v.findViewById(R.id.fp_map_fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            fancyPlaceSelectedCallback.onFancyPlaceSelected(0, OnFancyPlaceSelectedListener.INTENT_CREATE_NEW);
        }
    });


    return v;
}
 
Example #26
Source File: PlacesOnMapActivity.java    From Travel-Mate with MIT License 5 votes vote down vote up
/**
 * move to center marker
 *
 * @param marker    marker
 * @param latitude  latitude
 * @param longitude longitude
 */
private void moveMakerToCenter(Marker marker, Double latitude, Double longitude) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    int width = displayMetrics.widthPixels;
    int height = displayMetrics.heightPixels;
    mMap.setBottom(height);
    mMap.setRight(width);
    mMap.setTileSource(TileSourceFactory.MAPNIK);
    mController.setZoom(15.0);
    GeoPoint center = new GeoPoint(latitude, longitude);
    mController.animateTo(center);
}
 
Example #27
Source File: PoiListFragment.java    From AndroidApp with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Show all markers of the POIs on the map preview
 *
 * @param elements List of POIs to display
 */
private void setupMapMarkers(List<Element> elements) {
    //important! set your user agent to prevent getting banned from the osm servers
    Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));

    //clear existing markers
    if (map != null)
        map.getOverlays().clear();
    map = getActivity().findViewById(R.id.mapPoiList);
    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);

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

    for (Element element : elements)
        MapUtils.addMarker(getActivity(), map, element);

    if (elements.size() > 0) {
        GeoPoint position = new GeoPoint(elements.get(0).lat, elements.get(0).lon);
        controller.setCenter(position);
        controller.setZoom(14);
    }
    setupMyLocation();
}
 
Example #28
Source File: PMap.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a new tile source such as mapbox and others
 *
 * @param type
 * @return
 */
@PhonkMethod
public MapView tileSource(String type) {
    OnlineTileSourceBase source;
    if (type.equals("hikebikemap")) {
        source = TileSourceFactory.HIKEBIKEMAP;
    } else {
        source = TileSourceFactory.MAPNIK;
    }

    mapView.setTileSource(source);

    return mapView;
}
 
Example #29
Source File: SampleSqliteOnly.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void addOverlays() {
    this.mMapView.setUseDataConnection(false);

    //first we'll look at the default location for tiles that we support
    File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/osmdroid/");
    if (f.exists()) {

        File[] list = f.listFiles();
        if (list != null) {
            for (int i = 0; i < list.length; i++) {
                if (list[i].isDirectory()) {
                    continue;
                }
                String name = list[i].getName().toLowerCase();
                if (!name.contains(".")) {
                    continue; //skip files without an extension
                }
                name = name.substring(name.lastIndexOf(".") + 1);
                if (name.length() == 0) {
                    continue;
                }
                //narrow it down to only sqlite tiles
                if (ArchiveFileFactory.isFileExtensionRegistered(name) &&
                        name.equals("sqlite")) {
                    try {

                        //ok found a file we support and have a driver for the format, for this demo, we'll just use the first one

                        //create the offline tile provider, it will only do offline file archives
                        //again using the first file
                        OfflineTileProvider tileProvider = new OfflineTileProvider(new SimpleRegisterReceiver(getActivity()),
                                new File[]{list[i]});
                        //tell osmdroid to use that provider instead of the default rig which is (asserts, cache, files/archives, online
                        mMapView.setTileProvider(tileProvider);

                        //this bit enables us to find out what tiles sources are available. note, that this action may take some time to run
                        //and should be ran asynchronously. we've put it inline for simplicity

                        String source = "";
                        IArchiveFile[] archives = tileProvider.getArchives();
                        if (archives.length > 0) {
                            //cheating a bit here, get the first archive file and ask for the tile sources names it contains
                            Set<String> tileSources = archives[0].getTileSources();
                            //presumably, this would be a great place to tell your users which tiles sources are available
                            if (!tileSources.isEmpty()) {
                                //ok good, we found at least one tile source, create a basic file based tile source using that name
                                //and set it. If we don't set it, osmdroid will attempt to use the default source, which is "MAPNIK",
                                //which probably won't match your offline tile source, unless it's MAPNIK
                                source = tileSources.iterator().next();
                                this.mMapView.setTileSource(FileBasedTileSource.getSource(source));
                            } else {
                                this.mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
                            }

                        } else {
                            this.mMapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
                        }

                        Toast.makeText(getActivity(), "Using " + list[i].getAbsolutePath() + " " + source, Toast.LENGTH_SHORT).show();
                        this.mMapView.invalidate();
                        return;
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
        Toast.makeText(getActivity(), f.getAbsolutePath() + " did not have any files I can open! Try using MOBAC", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(getActivity(), f.getAbsolutePath() + " dir not found!", Toast.LENGTH_SHORT).show();
    }


}
 
Example #30
Source File: SampleWithTilesOverlay.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_samplewithtilesoverlay);

	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);
	mapContainer.addView(this.mMapView, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.MATCH_PARENT));
	mMapView.getZoomController().setVisibility(
			CustomZoomButtonsController.Visibility.SHOW_AND_FADEOUT);

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

	// zoom to the netherlands
	mMapView.getController().setZoom(8.);
	mMapView.getController().setCenter(new GeoPoint(53.6, 5.3));

	// Add tiles layer
	MapTileProviderBasic provider = new MapTileProviderBasic(getApplicationContext());
	provider.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
	TilesOverlay tilesOverlay = new TilesOverlay(provider, this.getBaseContext());
	tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
	mMapView.getOverlays().add(tilesOverlay);
}