Java Code Examples for org.osmdroid.views.overlay.compass.CompassOverlay#enableCompass()
The following examples show how to use
org.osmdroid.views.overlay.compass.CompassOverlay#enableCompass() .
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 |
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 |
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: PoiListFragment.java From AndroidApp with Mozilla Public License 2.0 | 6 votes |
/** * 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 4
Source File: PoiDetailsFragment.java From AndroidApp with Mozilla Public License 2.0 | 6 votes |
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 5
Source File: EditPoiFragment.java From AndroidApp with Mozilla Public License 2.0 | 6 votes |
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 6
Source File: PoiListFragment.java From AndroidApp with Mozilla Public License 2.0 | 5 votes |
/** * 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 7
Source File: SampleTester.java From osmdroid with Apache License 2.0 | 5 votes |
protected void addOverlays() { //sorry for the spaghetti code this is to filter out the compass on api 8 //Note: the compass overlay causes issues on API 8 devices. See https://github.com/osmdroid/osmdroid/issues/218 mCompassOverlay = new CompassOverlay(getContext(), new InternalCompassOrientationProvider(getContext()), mMapView); mCompassOverlay.enableCompass(); mMapView.getOverlays().add(this.mCompassOverlay); }
Example 8
Source File: CompassRoseSample.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void addOverlays(){ super.addOverlays(); CompassOverlay overlay = new CompassOverlay(getContext(), mMapView); overlay.setPointerMode(false); overlay.enableCompass(); mMapView.getOverlayManager().add(overlay); mMapView.invalidate(); }
Example 9
Source File: CompassPointerSample.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void addOverlays(){ super.addOverlays(); CompassOverlay overlay = new CompassOverlay(getContext(), mMapView); overlay.setPointerMode(true); overlay.enableCompass(); mMapView.getOverlayManager().add(overlay); mMapView.invalidate(); }
Example 10
Source File: WeathForceActivity.java From osmdroid with Apache License 2.0 | 5 votes |
@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 11
Source File: MapsActivity.java From Finder with GNU General Public License v3.0 | 4 votes |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Context ctx = getApplicationContext(); Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx)); Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID); setContentView(R.layout.activity_open_map); SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); map = findViewById(R.id.map2); Configuration.getInstance().setTileFileSystemCacheMaxBytes(1024*1024*Long.parseLong(sPref.getString("cache_size", "5"))); Configuration.getInstance().setTileFileSystemCacheTrimBytes(512*1024*Long.parseLong(sPref.getString("cache_size", "5"))); // trim storage to ~50% from max after oversize limit if (sPref.getBoolean("satellite", false)) { final MapBoxTileSource tileSource = new MapBoxTileSource(); tileSource.retrieveAccessToken(this); tileSource.retrieveMapBoxMapId(this); map.setTileSource(tileSource); } else { map.setTileSource(TileSourceFactory.MAPNIK); } map.setBuiltInZoomControls(true); map.setMultiTouchControls(true); mapController = map.getController(); CopyrightOverlay copyOverlay = new CopyrightOverlay(this); copyOverlay.setAlignRight(true); map.getOverlays().add(copyOverlay); ScaleBarOverlay scaleBar= new ScaleBarOverlay(map); scaleBar.setUnitsOfMeasure(ScaleBarOverlay.UnitsOfMeasure.metric); scaleBar.setScaleBarOffset(getResources().getDisplayMetrics().widthPixels/2, 50); scaleBar.setCentred(true); map.getOverlays().add(scaleBar); GpsMyLocationProvider gpsProvider = new GpsMyLocationProvider(this.getBaseContext()); MyLocationNewOverlay myLoc = new MyLocationNewOverlay(gpsProvider, map); myLoc.setDrawAccuracyEnabled(true); map.getOverlays().add(myLoc); CompassOverlay compasOver = new CompassOverlay(this.getBaseContext(), map); compasOver.enableCompass(); map.getOverlays().add(compasOver); dBase baseConnect = new dBase(this); db = baseConnect.getWritableDatabase(); Intent intent = this.getIntent(); mapController.setZoom(intent.getDoubleExtra("zoom", 15.0d)); String act = intent.getAction(); if (act.equals("track")) { track_id = intent.getIntExtra("track_id", 0); line = new Polyline(map); line.setColor(Color.BLUE); line.setInfoWindow(null); //delete popup label from track line.setGeodesic(true); //draw "true" lines instead simple lines (great circles) trackRedraw(); map.getOverlays().add(line); } else { String accuracy = intent.getStringExtra("accuracy"); GeoPoint startPoint = new GeoPoint(intent.getDoubleExtra("lat", 0d), intent.getDoubleExtra("lon", 0d)); mapController.setCenter(startPoint); Marker startMarker = new Marker(map); startMarker.setPosition(startPoint); startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); map.getOverlays().add(startMarker); startMarker.setTitle(accuracy); } //receiver to map updating LocalBroadcastManager.getInstance(this).registerReceiver(updMap, new IntentFilter("update_map")); }
Example 12
Source File: StarterMapFragment.java From osmdroid with Apache License 2.0 | 4 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final Context context = this.getActivity(); final DisplayMetrics dm = context.getResources().getDisplayMetrics(); mPrefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); //My Location //note you have handle the permissions yourself, the overlay did not do it for you mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(context), mMapView); mLocationOverlay.enableMyLocation(); mMapView.getOverlays().add(this.mLocationOverlay); //Mini map mMinimapOverlay = new MinimapOverlay(context, mMapView.getTileRequestCompleteHandler()); mMinimapOverlay.setWidth(dm.widthPixels / 5); mMinimapOverlay.setHeight(dm.heightPixels / 5); mMapView.getOverlays().add(this.mMinimapOverlay); //Copyright overlay mCopyrightOverlay = new CopyrightOverlay(context); //i hate this very much, but it seems as if certain versions of android and/or //device types handle screen offsets differently mMapView.getOverlays().add(this.mCopyrightOverlay); //On screen compass mCompassOverlay = new CompassOverlay(context, new InternalCompassOrientationProvider(context), mMapView); mCompassOverlay.enableCompass(); mMapView.getOverlays().add(this.mCompassOverlay); //map scale mScaleBarOverlay = new ScaleBarOverlay(mMapView); mScaleBarOverlay.setCentred(true); mScaleBarOverlay.setScaleBarOffset(dm.widthPixels / 2, 10); mMapView.getOverlays().add(this.mScaleBarOverlay); //support for map rotation mRotationGestureOverlay = new RotationGestureOverlay(mMapView); mRotationGestureOverlay.setEnabled(true); mMapView.getOverlays().add(this.mRotationGestureOverlay); //needed for pinch zooms mMapView.setMultiTouchControls(true); //scales tiles to the current screen's DPI, helps with readability of labels mMapView.setTilesScaledToDpi(true); //the rest of this is restoring the last map location the user looked at final float zoomLevel = mPrefs.getFloat(PREFS_ZOOM_LEVEL_DOUBLE, 1); mMapView.getController().setZoom(zoomLevel); final float orientation = mPrefs.getFloat(PREFS_ORIENTATION, 0); mMapView.setMapOrientation(orientation, false); final String latitudeString = mPrefs.getString(PREFS_LATITUDE_STRING, "1.0"); final String longitudeString = mPrefs.getString(PREFS_LONGITUDE_STRING, "1.0"); final double latitude = Double.valueOf(latitudeString); final double longitude = Double.valueOf(longitudeString); mMapView.setExpectedCenter(new GeoPoint(latitude, longitude)); setHasOptionsMenu(true); }