Java源码示例:org.osmdroid.config.Configuration

示例1
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);
}
 
示例2
public BookmarkDatastore() {

        Configuration.getInstance().getOsmdroidTileCache().mkdirs();
        db_file = new File(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + File.separator + DATABASE_FILENAME);


        try {
            mDatabase = SQLiteDatabase.openOrCreateDatabase(db_file, null);
            mDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE + " (" +
                COLUMN_LAT+ " INTEGER , " +
                COLUMN_LON + " INTEGER, " +
                COLUMN_TITLE + " TEXT, " +
                COLUMN_ID + " TEXT, " +
                COLUMN_DESC+" TEXT, PRIMARY KEY (" + COLUMN_ID + ") );");
        } catch (Throwable ex) {
            Log.e(IMapView.LOGTAG, "Unable to start the bookmark database. Check external storage availability.", ex);
        }
    }
 
示例3
/**
 * 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);
}
 
示例4
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);
}
 
示例5
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());
}
 
示例6
@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();
	}
}
 
示例7
/**
 * Start animating the map towards the given point.
 */
@Override
public void animateTo(int x, int y) {
    // If no layout, delay this call
    if (!mMapView.isLayoutOccurred()) {
        mReplayController.animateTo(x, y);
        return;
    }

    if (!mMapView.isAnimating()) {
        mMapView.mIsFlinging = false;
        final int xStart = (int)mMapView.getMapScrollX();
        final int yStart = (int)mMapView.getMapScrollY();

        final int dx = x - mMapView.getWidth() / 2;
        final int dy = y - mMapView.getHeight() / 2;

        if (dx != xStart || dy != yStart) {
            mMapView.getScroller().startScroll(xStart, yStart, dx, dy, Configuration.getInstance().getAnimationSpeedDefault());
            mMapView.postInvalidate();
        }
    }
}
 
示例8
@Override
public boolean onSnapToItem(final int x, final int y, final Point snapPoint,
		final IMapView mapView) {
	if (this.mLocation != null) {
		Projection pj = mMapView.getProjection();
		pj.toPixels(mGeoPoint, mSnapPixel);
		snapPoint.x = mSnapPixel.x;
		snapPoint.y = mSnapPixel.y;
		final double xDiff = x - mSnapPixel.x;
		final double yDiff = y - mSnapPixel.y;
		boolean snap = xDiff * xDiff + yDiff * yDiff < 64;
		if (Configuration.getInstance().isDebugMode()) {
                   Log.d(IMapView.LOGTAG, "snap=" + snap);
		}
		return snap;
	} else {
		return false;
	}
}
 
示例9
public TileWriter() {

		if (!hasInited) {
			hasInited = true;
			// do this in the background because it takes a long time
			initThread = new Thread() {
				@Override
				public void run() {
					mUsedCacheSpace = 0; // because it's static

					calculateDirectorySize(Configuration.getInstance().getOsmdroidTileCache());

					if (mUsedCacheSpace > Configuration.getInstance().getTileFileSystemCacheMaxBytes()) {
						cutCurrentCache();
					}
					if (Configuration.getInstance().isDebugMode()) {
						Log.d(IMapView.LOGTAG, "Finished init thread");
					}
				}
			};
			initThread.setName("TileWriter#init");
			initThread.setPriority(Thread.MIN_PRIORITY);
			initThread.start();
		}
	}
 
示例10
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    //overrides the default animation speeds
    //note: the mapview creates the default double tap to zoom in animator when the map view is created
    //this we have to set the desired zoom speed here before the mapview is created/inflated
    Configuration.getInstance().setAnimationSpeedShort(100);
    Configuration.getInstance().setAnimationSpeedDefault(100);

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

    mMapView = root.findViewById(R.id.mapview);
    TextView textViewCurrentLocation = root.findViewById(R.id.textViewCurrentLocation);
    textViewCurrentLocation.setText("Animation Speed Test");
    ImageButton btn = root.findViewById(R.id.btnRotateLeft);
    btn.setOnClickListener(this);

    btn = root.findViewById(R.id.btnRotateRight);
    btn.setOnClickListener(this);
    return root;
}
 
示例11
@Override
public Drawable loadTile(final ITileSource pTileSource, final long pMapTileIndex) throws Exception{
	// Check the tile source to see if its file is available and if so, then render the
	// drawable and return the tile
	final File file = getFile(pTileSource, pMapTileIndex);
	if (!file.exists()) {
		return null;
	}

	final Drawable drawable = pTileSource.getDrawable(file.getPath());

	// Check to see if file has expired
	final long now = System.currentTimeMillis();
	final long lastModified = file.lastModified();
	final boolean fileExpired = lastModified < now - mMaximumCachedFileAge;

	if (fileExpired && drawable != null) {
		if (Configuration.getInstance().isDebugMode()) {
			Log.d(IMapView.LOGTAG,"Tile expired: " + MapTileIndex.toString(pMapTileIndex));
		}
		ExpirableBitmapDrawable.setState(drawable, ExpirableBitmapDrawable.EXPIRED);
	}

	return drawable;
}
 
示例12
@Override
public void onResume() {
    super.onResume();
    updateStorage(getContext());

    textViewCacheDirectory.setText(Configuration.getInstance().getOsmdroidTileCache().toString());
    textViewCacheMaxSize.setText(readableFileSize(Configuration.getInstance().getTileFileSystemCacheMaxBytes()));
    textViewCacheTrimSize.setText(readableFileSize(Configuration.getInstance().getTileFileSystemCacheTrimBytes()));
    textViewCacheFreeSpace.setText(readableFileSize(Configuration.getInstance().getOsmdroidTileCache().getFreeSpace()));

    File dbFile = new File(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + File.separator + SqlTileWriter.DATABASE_FILENAME);
    if (dbFile.exists()) {
        textViewCacheCurrentSize.setText(readableFileSize(dbFile.length()));
    } else {
        textViewCacheCurrentSize.setText("");
    }
}
 
示例13
/**
 * this could be a long running operation, don't run on the UI thread unless necessary.
 * This function prunes the database for old or expired tiles.
 *
 * @since 5.6
 */
public void runCleanupOperation() {
    final SQLiteDatabase db = getDb();
    if (db == null || !db.isOpen()) {
        if (Configuration.getInstance().isDebugMode()) {
            Log.d(IMapView.LOGTAG, "Finished init thread, aborted due to null database reference");
        }
        return;
    }

    // index creation is run now (regardless of the table size)
    // therefore potentially on a small table, for better index creation performances
    createIndex(db);

    final long dbLength = db_file.length();
    if (dbLength <= Configuration.getInstance().getTileFileSystemCacheMaxBytes()) {
        return;
    }

    runCleanupOperation(
            dbLength - Configuration.getInstance().getTileFileSystemCacheTrimBytes(),
            Configuration.getInstance().getTileGCBulkSize(),
            Configuration.getInstance().getTileGCBulkPauseInMillis(),
            true);
}
 
示例14
/**
 * @since 6.0.2
 */
protected SQLiteDatabase getDb() {
    if (mDb != null) {
        return mDb;
    }
    synchronized (mLock) {
        Configuration.getInstance().getOsmdroidTileCache().mkdirs();
        db_file = new File(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + File.separator + DATABASE_FILENAME);
        if (mDb == null) {
            try {
                mDb = SQLiteDatabase.openOrCreateDatabase(db_file, null);
                mDb.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE + " (" + DatabaseFileArchive.COLUMN_KEY + " INTEGER , " + DatabaseFileArchive.COLUMN_PROVIDER + " TEXT, " + DatabaseFileArchive.COLUMN_TILE + " BLOB, " + COLUMN_EXPIRES + " INTEGER, PRIMARY KEY (" + DatabaseFileArchive.COLUMN_KEY + ", " + DatabaseFileArchive.COLUMN_PROVIDER + "));");
            } catch (Exception ex) {
                Log.e(IMapView.LOGTAG, "Unable to start the sqlite tile writer. Check external storage availability.", ex);
                catchException(ex);
                return null;
            }
        }
    }
    return mDb;
}
 
示例15
/**
 *
 * @since 6.0.0
 * @param pRegisterReceiver
 * @param pTileSource
 * @param pArchives
 * @param ignoreTileSource if true, tile source is ignored
 */
public MapTileFileArchiveProvider(final IRegisterReceiver pRegisterReceiver,
								  final ITileSource pTileSource, final IArchiveFile[] pArchives, final boolean ignoreTileSource) {
	super(pRegisterReceiver,
		Configuration.getInstance().getTileFileSystemThreads(),
		Configuration.getInstance().getTileFileSystemMaxQueueSize());

	this.ignoreTileSource=ignoreTileSource;
	setTileSource(pTileSource);

	if (pArchives == null) {
		mSpecificArchivesProvided = false;
		findArchiveFiles();
	} else {
		mSpecificArchivesProvided = true;
		for (int i = pArchives.length - 1; i >= 0; i--) {
			mArchiveFiles.add(pArchives[i]);
		}
	}

}
 
示例16
private void findArchiveFiles() {
	clearArcives();

         // path should be optionally configurable
         File cachePaths = Configuration.getInstance().getOsmdroidBasePath();
         final File[] files = cachePaths.listFiles();
         if (files != null) {
              for (final File file : files) {
                   final IArchiveFile archiveFile = ArchiveFileFactory.getArchiveFile(file);
                   if (archiveFile != null) {
                  		 archiveFile.setIgnoreTileSource(ignoreTileSource);
                        mArchiveFiles.add(archiveFile);
                   }
              }
         }
}
 
示例17
private synchronized InputStream getInputStream(final long pMapTileIndex,
		final ITileSource tileSource) {
	for (final IArchiveFile archiveFile : mArchiveFiles) {
		if (archiveFile!=null) {
			final InputStream in = archiveFile.getInputStream(tileSource, pMapTileIndex);
			if (in != null) {
				if (Configuration.getInstance().isDebugMode()) {
					Log.d(IMapView.LOGTAG, "Found tile " + MapTileIndex.toString(pMapTileIndex) + " in " + archiveFile);
				}
				return in;
			}
		}
	}

	return null;
}
 
示例18
/**
 * @since 6.0.3
 * @return the expiration time (as Epoch timestamp in milliseconds)
 * @deprecated Use {@link TileSourcePolicy#computeExpirationTime(HttpURLConnection, long)} instead
 */
@Deprecated
public long computeExpirationTime(final String pHttpExpiresHeader, final String pHttpCacheControlHeader, final long pNow) {
    final Long override=Configuration.getInstance().getExpirationOverrideDuration();
    if (override != null) {
        return pNow + override;
    }

    final long extension = Configuration.getInstance().getExpirationExtendedDuration();
    final Long cacheControlDuration = getHttpCacheControlDuration(pHttpCacheControlHeader);
    if (cacheControlDuration != null) {
        return pNow + cacheControlDuration * 1000 + extension;
    }

    final Long httpExpiresTime = getHttpExpiresTime(pHttpExpiresHeader);
    if (httpExpiresTime != null) {
        return httpExpiresTime + extension;
    }

    return pNow + OpenStreetMapTileProviderConstants.DEFAULT_MAXIMUM_CACHED_FILE_AGE + extension;
}
 
示例19
/**
 * refreshes the current osmdroid cache paths with user preferences plus soe logic to work around
 * file system permissions on api23 devices. it's primarily used for out android tests.
 * @param ctx
 * @return current cache size in bytes
 */
public static long updateStoragePreferences(Context ctx){

    //loads the osmdroid config from the shared preferences object.
    //if this is the first time launching this app, all settings are set defaults with one exception,
    //the tile cache. the default is the largest write storage partition, which could end up being
    //this app's private storage, depending on device config and permissions

    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

    //also note that our preference activity has the corresponding save method on the config object, but it can be called at any time.


    File dbFile = new File(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + File.separator + SqlTileWriter.DATABASE_FILENAME);
    if (dbFile.exists()) {
        return dbFile.length();
    }
    return -1;
}
 
示例20
/**
 * Get the most recent location from the GPS or Network provider.
 *
 * @return return the most recent location, or null if there's no known location
 */
public static Location getLastKnownLocation(final LocationManager pLocationManager) {
	if (pLocationManager == null) {
		return null;
	}
	final Location gpsLocation = getLastKnownLocation(pLocationManager, LocationManager.GPS_PROVIDER);
	final Location networkLocation = getLastKnownLocation(pLocationManager, LocationManager.NETWORK_PROVIDER);
	if (gpsLocation == null) {
		return networkLocation;
	} else if (networkLocation == null) {
		return gpsLocation;
	} else {
		// both are non-null - use the most recent
		if (networkLocation.getTime() > gpsLocation.getTime() + Configuration.getInstance().getGpsWaitTime()) {
			return networkLocation;
		} else {
			return gpsLocation;
		}
	}
}
 
示例21
@Override
public void onResume() {
    super.onResume();

    //this will refresh the osmdroid configuration on resuming.
    //if you make changes to the configuration, use
    //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    //Configuration.getInstance().save(this, prefs);
    Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));
}
 
示例22
@Override
public void onResume() {
    super.onResume();

    //this will refresh the osmdroid configuration on resuming.
    //if you make changes to the configuration, use
    //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    //Configuration.getInstance().save(this, prefs);
    Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));
}
 
示例23
/**
 * 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();
}
 
示例24
@Override
public void onResume() {
    super.onResume();

    //this will refresh the osmdroid configuration on resuming.
    //if you make changes to the configuration, use
    //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    //Configuration.getInstance().save(this, prefs);
    Configuration.getInstance().load(getDialog().getContext(), PreferenceManager.getDefaultSharedPreferences(getDialog().getContext()));
}
 
示例25
@Override
public void onResume() {
    super.onResume();

    //this will refresh the osmdroid configuration on resuming.
    //if you make changes to the configuration, use
    //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    //Configuration.getInstance().save(this, prefs);
    Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity()));
}
 
示例26
public static void deleteMapFileCash() {
    try {
        IConfigurationProvider configurationProvider = Configuration.getInstance();
        FileUtils.deleteRecursive((configurationProvider.getOsmdroidBasePath()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
示例27
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    realmMapUsers = Realm.getDefaultInstance();
    Configuration.getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context));


    return inflater.inflate(R.layout.fragment_igap_map, container, false);
}
 
示例28
public WeatherService(Context ctx, BleDevice device) {
    mDevice = device;
    mCtx = ctx;

    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

    mSettings = mCtx.getSharedPreferences(PREFS_NAME, 0);
    mLatitude = mSettings.getFloat(PREFS_LATITUDE, PREFS_LATITUDE_DEFAULT);
    mLongitude = mSettings.getFloat(PREFS_LONGITUDE, PREFS_LONGITUDE_DEFAULT);
}
 
示例29
@Override
protected void onCreate(final Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	final Context ctx = getApplicationContext();
	setTheme(ThemeHelper.find(this));

	final PackageManager packageManager = ctx.getPackageManager();
	hasLocationFeature = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION) ||
			packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) ||
			packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK);
	this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
	this.marker_icon = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.marker);

	// Ask for location permissions if location services are enabled and we're
	// just starting the activity (we don't want to keep pestering them on every
	// screen rotation or if there's no point because it's disabled anyways).
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && savedInstanceState == null) {
		requestPermissions(REQUEST_CODE_CREATE);
	}

	final IConfigurationProvider config = Configuration.getInstance();
	config.load(ctx, getPreferences());
	config.setUserAgentValue(BuildConfig.APPLICATION_ID + "/" + BuildConfig.VERSION_CODE);
	if (QuickConversationsService.isConversations() && getBooleanPreference("use_tor", R.bool.use_tor)) {
		try {
			config.setHttpProxy(HttpConnectionManager.getProxy());
		} catch (IOException e) {
			throw new RuntimeException("Unable to configure proxy");
		}
	}
}
 
示例30
@Override
protected void onPause() {
	super.onPause();
	Configuration.getInstance().save(this, getPreferences());
	map.onPause();
	try {
		pauseLocationUpdates();
	} catch (final SecurityException ignored) {
	}
}