com.mapbox.mapboxsdk.maps.MapView Java Examples

The following examples show how to use com.mapbox.mapboxsdk.maps.MapView. 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 Project: ShapeOfView   Author: florent37   File: TabbedMainActivity.java    License: Apache License 2.0 8 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.shape_of_view_tabbed_activity_main);
    ButterKnife.bind(this);
    Mapbox.getInstance(this, "pk.eyJ1IjoiY2hpY2tpbm5pY2siLCJhIjoiY2pka3U2YTdiMDE1YTJ4cjA0YzVyYnpoMSJ9.xlyPakmrR_N4bNqIGe6AKg");
    viewPager.setAdapter(new FakeAdapter(getSupportFragmentManager()));

    tabLayout.setupWithViewPager(viewPager);

    TabIndicatorFollower.setupWith(tabLayout, triangle);
    mapView = (MapView) findViewById(R.id.mapView);
    mapView.onCreate(savedInstanceState);

    RxLifecycle.with(this).onResume().subscribe(event -> mapView.onResume());
    RxLifecycle.with(this).onPause().subscribe(event -> mapView.onPause());
    RxLifecycle.with(this).onStop().subscribe(event -> mapView.onStop());
    RxLifecycle.with(this).onDestroy().subscribe(event -> mapView.onDestroy());
}
 
Example #2
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 6 votes vote down vote up
/**
 * Construct an instance of {@link NavigationMapRoute}.
 *
 * @param navigation an instance of the {@link MapboxNavigation} object. Passing in null means
 *                   your route won't consider rerouting during a navigation session.
 * @param mapView    the MapView to apply the route to
 * @param mapboxMap  the MapboxMap to apply route with
 * @param styleRes   a style resource with custom route colors, scale, etc.
 * @param belowLayer optionally pass in a layer id to place the route line below
 */
public NavigationMapRoute(@Nullable MapboxNavigation navigation, @NonNull MapView mapView,
                          @NonNull MapboxMap mapboxMap, @StyleRes int styleRes,
                          @Nullable String belowLayer) {
  this.styleRes = styleRes;
  this.mapView = mapView;
  this.mapboxMap = mapboxMap;
  this.navigation = navigation;
  this.belowLayer = belowLayer;
  featureCollections = new ArrayList<>();
  directionsRoutes = new ArrayList<>();
  routeLineStrings = new HashMap<>();
  layerIds = new ArrayList<>();
  initialize();
  addListeners();
}
 
Example #3
@VisibleForTesting
public DraggableAnnotationController(MapView mapView, MapboxMap mapboxMap,
                                     final AndroidGesturesManager androidGesturesManager,
                                     int touchAreaShiftX, int touchAreaShiftY,
                                     int touchAreaMaxX, int touchAreaMaxY) {
  this.mapboxMap = mapboxMap;
  this.touchAreaShiftX = touchAreaShiftX;
  this.touchAreaShiftY = touchAreaShiftY;
  this.touchAreaMaxX = touchAreaMaxX;
  this.touchAreaMaxY = touchAreaMaxY;

  androidGesturesManager.setMoveGestureListener(new AnnotationMoveGestureListener());

  mapView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      androidGesturesManager.onTouchEvent(event);
      // if drag is started, don't pass motion events further
      return draggedAnnotation != null;
    }
  });
}
 
Example #4
Source Project: mapbox-plugins-android   Author: mapbox   File: FillChangeActivity.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // configure initial map state
  MapboxMapOptions options = new MapboxMapOptions()
    .attributionTintColor(RED_COLOR)
    .compassFadesWhenFacingNorth(false)
    .camera(new CameraPosition.Builder()
      .target(new LatLng(45.520486, -122.673541))
      .zoom(12)
      .tilt(40)
      .build());

  // create map
  mapView = new MapView(this, options);
  mapView.setId(R.id.mapView);
  mapView.onCreate(savedInstanceState);
  mapView.getMapAsync(this);

  setContentView(mapView);
}
 
Example #5
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapboxMap.java    License: MIT License 5 votes vote down vote up
/**
 * Constructor that can be used once {@link com.mapbox.mapboxsdk.maps.OnMapReadyCallback}
 * has been called via {@link MapView#getMapAsync(OnMapReadyCallback)}.
 *
 * @param mapView   for map size and Context
 * @param mapboxMap for APIs to interact with the map
 */
public NavigationMapboxMap(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;
  initializeLocationLayer(mapView, mapboxMap);
  initializeMapPaddingAdjustor(mapView, mapboxMap);
  initializeMapLayerInteractor(mapboxMap);
  initializeWayname(mapView, mapboxMap, layerInteractor, mapPaddingAdjustor);
  initializeRoute(mapView, mapboxMap);
  initializeCamera(mapboxMap);
}
 
Example #6
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapboxMap.java    License: MIT License 5 votes vote down vote up
private void initializeLocationLayer(MapView mapView, MapboxMap map) {
  Context context = mapView.getContext();
  int locationLayerStyleRes = ThemeSwitcher.retrieveNavigationViewStyle(context,
    R.attr.navigationViewLocationLayerStyle);
  locationLayer = new LocationLayerPlugin(mapView, map, null, locationLayerStyleRes);
  locationLayer.setRenderMode(RenderMode.GPS);
}
 
Example #7
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapboxMap.java    License: MIT License 5 votes vote down vote up
private void initializeWayname(MapView mapView, MapboxMap mapboxMap,
                               MapLayerInteractor layerInteractor, MapPaddingAdjustor paddingAdjustor) {
  initializeStreetsSource(mapboxMap);
  WaynameLayoutProvider layoutProvider = new WaynameLayoutProvider(mapView.getContext());
  WaynameFeatureFinder featureInteractor = new WaynameFeatureFinder(mapboxMap);
  initializeWaynameLayer(layerInteractor);
  mapWayname = new MapWayname(layoutProvider, layerInteractor, featureInteractor, paddingAdjustor);
}
 
Example #8
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapPaddingAdjustor.java    License: MIT License 5 votes vote down vote up
private int calculateTopPaddingDefault(MapView mapView) {
  Context context = mapView.getContext();
  Resources resources = context.getResources();
  int mapViewHeight = mapView.getHeight();
  int bottomSheetHeight = (int) resources.getDimension(R.dimen.summary_bottomsheet_height);
  return mapViewHeight - (bottomSheetHeight * BOTTOMSHEET_PADDING_MULTIPLIER);
}
 
Example #9
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationSnapshotReadyCallback.java    License: MIT License 5 votes vote down vote up
private void updateFeedbackScreenshot() {
  MapView mapView = navigationView.findViewById(R.id.navigationMapView);
  mapView.setVisibility(View.INVISIBLE);
  Bitmap capture = ViewUtils.captureView(mapView);
  String encoded = ViewUtils.encodeView(capture);
  navigationViewModel.updateFeedbackScreenshot(encoded);
}
 
Example #10
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapRoute.java    License: MIT License 5 votes vote down vote up
/**
 * Called when a map change events occurs. Used specifically to detect loading of a new style, if
 * applicable reapply the route line source and layers.
 *
 * @param change the map change event that occurred
 * @since 0.4.0
 */
@Override
public void onMapChanged(int change) {
  if (change == MapView.DID_FINISH_LOADING_STYLE) {
    placeRouteBelow();
    initializeUpcomingManeuverArrow();
    drawRoutes();
    addDirectionWaypoints();
    showAlternativeRoutes(alternativesVisible);
  }
}
 
Example #11
@Test
public void sanity() throws Exception {
  when(style.isFullyLoaded()).thenReturn(true);
  LocalizationPlugin localizationPlugin
    = new LocalizationPlugin(mock(MapView.class), mock(MapboxMap.class), style);
  assertNotNull(localizationPlugin);
}
 
Example #12
@Test
@Ignore
public void setMapLanguage_localePassedInNotValid() throws Exception {
  when(style.isFullyLoaded()).thenReturn(true);
  thrown.expect(NullPointerException.class);
  thrown.expectMessage(containsString("has no matching MapLocale object. You need to create"));
  LocalizationPlugin localizationPlugin
    = new LocalizationPlugin(mock(MapView.class), mock(MapboxMap.class), style);
  localizationPlugin.setMapLanguage(new Locale("foo", "bar"), false);
}
 
Example #13
Source Project: mapbox-plugins-android   Author: mapbox   File: AnnotationManager.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@UiThread
protected AnnotationManager(MapView mapView, final MapboxMap mapboxMap, Style style,
                            CoreElementProvider<L> coreElementProvider,
                            DraggableAnnotationController<T, D> draggableAnnotationController,
                            String belowLayerId, final GeoJsonOptions geoJsonOptions) {
  this.mapboxMap = mapboxMap;
  this.style = style;
  this.belowLayerId = belowLayerId;
  this.coreElementProvider = coreElementProvider;

  if (!style.isFullyLoaded()) {
    throw new RuntimeException("The style has to be non-null and fully loaded.");
  }

  mapboxMap.addOnMapClickListener(mapClickResolver = new MapClickResolver());
  mapboxMap.addOnMapLongClickListener(mapClickResolver);
  this.draggableAnnotationController = draggableAnnotationController;
  draggableAnnotationController.injectAnnotationManager(this);

  initializeSourcesAndLayers(geoJsonOptions);

  mapView.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
    @Override
    public void onDidFinishLoadingStyle() {
      mapboxMap.getStyle(new Style.OnStyleLoaded() {
        @Override
        public void onStyleLoaded(@NonNull Style loadedStyle) {
          AnnotationManager.this.style = loadedStyle;
          initializeSourcesAndLayers(geoJsonOptions);
        }
      });
    }
  });
}
 
Example #14
Source Project: mapbox-plugins-android   Author: mapbox   File: ScaleBarTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testScaleBarWidth() {
  validateTestSetup();
  setupScaleBar();
  invoke(mapboxMap, (uiController, mapboxMap) -> {
    assertEquals(MapView.class, scaleBarWidget.getParent().getClass());
    MapView parent = (MapView) scaleBarWidget.getParent();
    assertEquals(parent.getWidth(), scaleBarWidget.getMapViewWidth());
  });
}
 
Example #15
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPlugin.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Create a traffic plugin.
 *
 * @param mapView    the MapView to apply the traffic plugin to
 * @param mapboxMap  the MapboxMap to apply traffic plugin with
 * @param belowLayer the layer id where you'd like the traffic to display below
 */
public TrafficPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style,
                     @Nullable String belowLayer) {
  if (!style.isFullyLoaded()) {
    throw new RuntimeException("The style has to be non-null and fully loaded.");
  }

  this.mapboxMap = mapboxMap;
  this.style = style;
  this.belowLayer = belowLayer;
  mapView.addOnDidFinishLoadingStyleListener(new StyleLoadHandler(this));
}
 
Example #16
Source Project: android   Author: codeandcoke   File: MainActivity.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MapboxAccountManager.start(this, "Pon aqui tu token");

    setContentView(R.layout.activity_main);

    mapView = (MapView) findViewById(R.id.mapa);
    mapView.onCreate(savedInstanceState);
}
 
Example #17
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationView.java    License: MIT License 4 votes vote down vote up
private void initializeNavigationMap(MapView mapView, MapboxMap map) {
  navigationMap = new NavigationMapboxMap(mapView, map);
  if (mapInstanceState != null) {
    navigationMap.restoreFrom(mapInstanceState);
  }
}
 
Example #18
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapboxMap.java    License: MIT License 4 votes vote down vote up
private void initializeMapPaddingAdjustor(MapView mapView, MapboxMap mapboxMap) {
  mapPaddingAdjustor = new MapPaddingAdjustor(mapView, mapboxMap);
}
 
Example #19
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationMapboxMap.java    License: MIT License 4 votes vote down vote up
private void initializeRoute(MapView mapView, MapboxMap map) {
  Context context = mapView.getContext();
  int routeStyleRes = ThemeSwitcher.retrieveNavigationViewStyle(context, R.attr.navigationViewRouteStyle);
  mapRoute = new NavigationMapRoute(null, mapView, map, routeStyleRes);
}
 
Example #20
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapPaddingAdjustor.java    License: MIT License 4 votes vote down vote up
MapPaddingAdjustor(MapView mapView, MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;
  defaultTopPadding = calculateTopPaddingDefault(mapView);
  waynameTopPadding = calculateTopPaddingWithWayname(mapView.getContext(), defaultTopPadding);
}
 
Example #21
Source Project: graphhopper-navigation-android   Author: graphhopper   File: NavigationSnapshotReadyCallback.java    License: MIT License 4 votes vote down vote up
private void resetViewVisibility(ImageView screenshotView) {
  screenshotView.setVisibility(View.INVISIBLE);
  MapView mapView = navigationView.findViewById(R.id.navigationMapView);
  mapView.setVisibility(View.VISIBLE);
}
 
Example #22
Source Project: mapbox-plugins-android   Author: mapbox   File: ScaleBarPlugin.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ScaleBarPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap) {
  this.mapView = mapView;
  this.mapboxMap = mapboxMap;
  this.projection = mapboxMap.getProjection();
}
 
Example #23
Source Project: mapbox-plugins-android   Author: mapbox   File: CircleManager.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
CircleManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<CircleLayer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController<Circle, OnCircleDragListener> draggableAnnotationController) {
  super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
}
 
Example #24
Source Project: mapbox-plugins-android   Author: mapbox   File: FillManager.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
FillManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<FillLayer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController<Fill, OnFillDragListener> draggableAnnotationController) {
  super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
}
 
Example #25
Source Project: mapbox-plugins-android   Author: mapbox   File: SymbolManager.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
SymbolManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<SymbolLayer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController<Symbol, OnSymbolDragListener> draggableAnnotationController) {
  super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
}
 
Example #26
@SuppressLint("ClickableViewAccessibility")
DraggableAnnotationController(MapView mapView, MapboxMap mapboxMap) {
  this(mapView, mapboxMap, new AndroidGesturesManager(mapView.getContext(), false),
    mapView.getScrollX(), mapView.getScrollY(), mapView.getMeasuredWidth(), mapView.getMeasuredHeight());
}
 
Example #27
Source Project: mapbox-plugins-android   Author: mapbox   File: LineManager.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
@VisibleForTesting
LineManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @NonNull CoreElementProvider<LineLayer> coreElementProvider, @Nullable String belowLayerId, @Nullable GeoJsonOptions geoJsonOptions, DraggableAnnotationController<Line, OnLineDragListener> draggableAnnotationController) {
  super(mapView, mapboxMap, style, coreElementProvider, draggableAnnotationController, belowLayerId, geoJsonOptions);
}
 
Example #28
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_annotation);

  mapView = findViewById(R.id.mapView);
  mapView.setTag(false);
  mapView.onCreate(savedInstanceState);
  mapView.getMapAsync(mapboxMap -> {
    DynamicSymbolChangeActivity.this.mapboxMap = mapboxMap;

    LatLng target = new LatLng(51.506675, -0.128699);

    mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
      new CameraPosition.Builder()
        .bearing(90)
        .tilt(40)
        .zoom(10)
        .target(target)
        .build()
    ));

    mapboxMap.setStyle(new Style.Builder()
        .fromUri(Style.MAPBOX_STREETS)
        .withImage(ID_ICON_1, generateBitmap(R.drawable.mapbox_ic_place), true)
        .withImage(ID_ICON_2, generateBitmap(R.drawable.mapbox_ic_offline), true)
      , style -> {
        symbolManager = new SymbolManager(mapView, mapboxMap, style);
        symbolManager.setIconAllowOverlap(true);
        symbolManager.setTextAllowOverlap(true);

        // Create Symbol
        SymbolOptions SymbolOptions = new SymbolOptions()
          .withLatLng(LAT_LNG_CHELSEA)
          .withIconImage(ID_ICON_1);

        symbol = symbolManager.create(SymbolOptions);
      });


  });

  FloatingActionButton fab = findViewById(R.id.fabStyles);
  fab.setVisibility(MapView.VISIBLE);
  fab.setOnClickListener(view -> {
    if (mapboxMap != null) {
      updateSymbol();
    }
  });
}
 
Example #29
public MapView getMapView() {
  return mapView;
}
 
Example #30
Source Project: WhereAreTheEyes   Author: DaylightingSociety   File: GPS.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public GPS(MapView m) {
    super();
    map = m;
    Log.d("GPS", "Initialized");
}