Search in sources :

Example 1 with DefaultResourceProxyImpl

use of org.osmdroid.DefaultResourceProxyImpl in project open-event-android by fossasia.

the class OSMapFragment method populateMap.

private void populateMap() {
    if (!mayRequestStorageForOfflineMap())
        return;
    final MapView mapView = (MapView) rootView.findViewById(R.id.mapview);
    final ZoomControls zoomControls = (ZoomControls) rootView.findViewById(R.id.zoomControls);
    Resources resources = getContext().getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        zoomControls.setPadding(0, 0, 0, resources.getDimensionPixelSize(resourceId) + 4);
    }
    mapView.setBuiltInZoomControls(false);
    mapView.setMultiTouchControls(true);
    event = realmRepo.getEvent();
    event.addChangeListener(new RealmChangeListener<RealmModel>() {

        @Override
        public void onChange(RealmModel realmModel) {
            showEvent();
        }
    });
    GeoPoint geoPoint = new GeoPoint(getDestinationLatitude(), getDestinationLongitude());
    mapView.getController().setCenter(geoPoint);
    mapView.getController().setZoom(17);
    mapView.setMaxZoomLevel(20);
    mapView.setMinZoomLevel(3);
    OverlayItem position = new OverlayItem(getDestinationName(), "Location", geoPoint);
    zoomControls.setOnZoomInClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mapView.getController().zoomIn();
        }
    });
    zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mapView.getController().zoomOut();
        }
    });
    ArrayList<OverlayItem> items = new ArrayList<>();
    items.add(position);
    mapView.getOverlays().add(new ItemizedIconOverlay<>(items, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {

        @Override
        public boolean onItemSingleTapUp(int index, OverlayItem item) {
            return false;
        }

        @Override
        public boolean onItemLongPress(int index, OverlayItem item) {
            return false;
        }
    }, new DefaultResourceProxyImpl(getActivity())));
    mapView.invalidate();
}
Also used : ZoomControls(android.widget.ZoomControls) OverlayItem(org.osmdroid.views.overlay.OverlayItem) ArrayList(java.util.ArrayList) View(android.view.View) MapView(org.osmdroid.views.MapView) DefaultResourceProxyImpl(org.osmdroid.DefaultResourceProxyImpl) GeoPoint(org.osmdroid.util.GeoPoint) RealmModel(io.realm.RealmModel) GeoPoint(org.osmdroid.util.GeoPoint) MapView(org.osmdroid.views.MapView) Resources(android.content.res.Resources)

Aggregations

Resources (android.content.res.Resources)1 View (android.view.View)1 ZoomControls (android.widget.ZoomControls)1 RealmModel (io.realm.RealmModel)1 ArrayList (java.util.ArrayList)1 DefaultResourceProxyImpl (org.osmdroid.DefaultResourceProxyImpl)1 GeoPoint (org.osmdroid.util.GeoPoint)1 MapView (org.osmdroid.views.MapView)1 OverlayItem (org.osmdroid.views.overlay.OverlayItem)1