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 File: TabbedMainActivity.java    From ShapeOfView with 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 File: NavigationMapRoute.java    From graphhopper-navigation-android with 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
Source File: FillChangeActivity.java    From mapbox-plugins-android with 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 #4
Source File: DraggableAnnotationController.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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 #5
Source File: LocalizationPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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 #6
Source File: LocalizationPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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 #7
Source File: NavigationMapRoute.java    From graphhopper-navigation-android with 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 #8
Source File: AnnotationManager.java    From mapbox-plugins-android with 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 #9
Source File: ScaleBarTest.java    From mapbox-plugins-android with 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 #10
Source File: TrafficPlugin.java    From mapbox-plugins-android with 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 #11
Source File: NavigationSnapshotReadyCallback.java    From graphhopper-navigation-android with 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 #12
Source File: MapPaddingAdjustor.java    From graphhopper-navigation-android with 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 #13
Source File: NavigationMapboxMap.java    From graphhopper-navigation-android with 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 #14
Source File: MainActivity.java    From android with 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 #15
Source File: NavigationMapboxMap.java    From graphhopper-navigation-android with 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 #16
Source File: NavigationMapboxMap.java    From graphhopper-navigation-android with 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 #17
Source File: DraggableAnnotationController.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
DraggableAnnotationController(MapView mapView, MapboxMap mapboxMap) {
  this(mapView, mapboxMap, new AndroidGesturesManager(mapView.getContext(), false),
    mapView.getScrollX(), mapView.getScrollY(), mapView.getMeasuredWidth(), mapView.getMeasuredHeight());
}
 
Example #18
Source File: SymbolManager.java    From mapbox-plugins-android with 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 #19
Source File: NavigationView.java    From graphhopper-navigation-android with 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 #20
Source File: FillManager.java    From mapbox-plugins-android with 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 #21
Source File: LineManager.java    From mapbox-plugins-android with 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 #22
Source File: DynamicSymbolChangeActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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 #23
Source File: OnMapReadyIdlingResource.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public MapView getMapView() {
  return mapView;
}
 
Example #24
Source File: GPS.java    From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public GPS(MapView m) {
    super();
    map = m;
    Log.d("GPS", "Initialized");
}
 
Example #25
Source File: PinData.java    From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
PinData(HashMap<LatLng, Integer> p, MapView m, Location l) {
    pins = p;
    map = m;
    position = l;
}
 
Example #26
Source File: DCMapFragment.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
public MapView getMapView() {
    return map;
}
 
Example #27
Source File: NavigationMapboxMap.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
private void initializeMapPaddingAdjustor(MapView mapView, MapboxMap mapboxMap) {
  mapPaddingAdjustor = new MapPaddingAdjustor(mapView, mapboxMap);
}
 
Example #28
Source File: CircleManager.java    From mapbox-plugins-android with 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 #29
Source File: NavigationMapboxMap.java    From graphhopper-navigation-android with 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 #30
Source File: MapPaddingAdjustor.java    From graphhopper-navigation-android with MIT License 4 votes vote down vote up
MapPaddingAdjustor(MapView mapView, MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;
  defaultTopPadding = calculateTopPaddingDefault(mapView);
  waynameTopPadding = calculateTopPaddingWithWayname(mapView.getContext(), defaultTopPadding);
}