com.mapbox.mapboxsdk.maps.MapboxMap Java Examples

The following examples show how to use com.mapbox.mapboxsdk.maps.MapboxMap. 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: RegionSelectionFragment.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onMapReady(final MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;
  mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
    @Override
    public void onStyleLoaded(@NonNull Style style) {
      RegionSelectionFragment.this.style = style;
      mapboxMap.addOnCameraIdleListener(RegionSelectionFragment.this);
      if (options != null) {
        if (options.startingBounds() != null) {
          mapboxMap.moveCamera(CameraUpdateFactory.newLatLngBounds(options.startingBounds(), 0));
        } else if (options.statingCameraPosition() != null) {
          mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(options.statingCameraPosition()));
        }
      }
    }
  });
}
 
Example #2
Source File: MainActivity.java    From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void recenterCamera(View view) {
    mapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(MapboxMap mapboxMap) {
            Location loc = gps.getLocation();
            if( loc == null )
                return;
            CameraPosition position = new CameraPosition.Builder()
                    .target(new LatLng(loc.getLatitude(), loc.getLongitude()))
                    .zoom(17)
                    .bearing(0)
                    .build();
            mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 3000);
        }
    });
}
 
Example #3
Source File: MainActivity.java    From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void recenterMap() {
    final Location l = gps.getLocation();

    // This shouldn't normally happen, but does on the Android emulator.
    // It only occurs if recenterMap is called before we receive our first
    // gps ping. We normally receive a ping within a second or two of app
    // launch, but *not* if the emulator only pings on demand.
    if( l == null )
        return;

    mapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(MapboxMap mapboxMap) {
            // We'll maintain zoom level and tilt, just want to change position
            CameraPosition old = mapboxMap.getCameraPosition();
            CameraPosition pos = new CameraPosition.Builder()
                    .target(new LatLng(l.getLatitude(), l.getLongitude()))
                    .zoom(old.zoom)
                    .tilt(old.tilt)
                    .build();
            mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos));
        }
    });
}
 
Example #4
Source File: PlacePickerActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onMapReady(final MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;
  mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
    @Override
    public void onStyleLoaded(@NonNull Style style) {
      adjustCameraBasedOnOptions();
      if (includeReverseGeocode) {
        // Initialize with the marker's current coordinates.
        makeReverseGeocodingSearch();
      }
      bindListeners();

      if (options != null && options.includeDeviceLocationButton()) {
        enableLocationComponent(style);
      } else {
        userLocationButton.hide();
      }
    }
  });
}
 
Example #5
Source File: MockNavigationActivity.java    From graphhopper-navigation-android with MIT License 6 votes vote down vote up
@Override
public void onMapReady(MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;

  locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap);
  locationLayerPlugin.setRenderMode(RenderMode.GPS);
  locationLayerPlugin.setLocationLayerEnabled(false);
  navigationMapRoute = new NavigationMapRoute(navigation, mapView, mapboxMap);

  mapboxMap.addOnMapClickListener(this);
  Snackbar.make(findViewById(R.id.container), "Tap map to place waypoint", BaseTransientBottomBar.LENGTH_LONG).show();

  locationEngine = new ReplayRouteLocationEngine();

  newOrigin();
}
 
Example #6
Source File: MainActivity.java    From WhereAreTheEyes with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setMapTracking() {
    final String trackingPref = getTrackingPreference();
    mapView.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(MapboxMap mapboxMap) {
            TrackingSettings tracking = mapboxMap.getTrackingSettings();
            switch(trackingPref)
            {
                case "position":
                    tracking.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
                    tracking.setMyBearingTrackingMode(MyBearingTracking.NONE);
                    break;
                case "direction":
                    tracking.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
                    tracking.setMyBearingTrackingMode(MyBearingTracking.COMPASS);
                    break;
                case "movement":
                    tracking.setMyBearingTrackingMode(MyLocationTracking.TRACKING_NONE);
                    tracking.setMyLocationTrackingMode(MyBearingTracking.GPS);
                    break;
            }
        }
    });
}
 
Example #7
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void toggleHidesPrimaryCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      trafficPlugin.setVisibility(false);
      assertTrue(mapboxMap.getStyle().getLayer(Primary.CASE_LAYER_ID).getVisibility().getValue().equals(Property.NONE));
    }
  });
}
 
Example #8
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void toggleHidesLocalBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      trafficPlugin.setVisibility(false);
      assertTrue(mapboxMap.getStyle().getLayer(Local.BASE_LAYER_ID).getVisibility().getValue().equals(Property.NONE));
    }
  });
}
 
Example #9
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void sourceAdded() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertTrue(mapboxMap.getStyle().getSource(TrafficData.SOURCE_ID) != null);
    }
  });
}
 
Example #10
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void localBaseLayerMinZoom() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertTrue(mapboxMap.getStyle().getLayer(Local.BASE_LAYER_ID).getMinZoom() == Local.ZOOM_LEVEL);
    }
  });
}
 
Example #11
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void toggleHidesPrimaryBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      trafficPlugin.setVisibility(false);
      assertTrue(mapboxMap.getStyle().getLayer(Primary.BASE_LAYER_ID).getVisibility().getValue().equals(Property.NONE));
    }
  });
}
 
Example #12
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineWidthFunctionSecondaryBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      LineLayer layer = mapboxMap.getStyle().getLayerAs(Secondary.BASE_LAYER_ID);
      assertNotNull(layer.getLineWidth());
      assertNotNull(layer.getLineWidth().getExpression());
    }
  });
}
 
Example #13
Source File: NavigationMapRouteActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Override
public void onMapReady(MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;
  navigationMapRoute = new NavigationMapRoute(null, mapView, mapboxMap,
    "admin-3-4-boundaries-bg");
  Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create())
    .create();
  DirectionsResponse response = gson.fromJson(loadJsonFromAsset(DIRECTIONS_RESPONSE),
    DirectionsResponse.class);
  navigationMapRoute.addRoute(response.routes().get(0));
  mapboxMap.addOnMapLongClickListener(this);
  navigationMapRoute.setOnRouteSelectionChangeListener(this);
}
 
Example #14
Source File: AirMapMapView.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
@UiThread
public MapboxMap getMap() {
    if (Looper.getMainLooper() != Looper.myLooper()) {
        Timber.e("*** AirMapMapView accessed from a thread other than the UI-thread:" + Thread.currentThread());
        Analytics.report(new Exception("AirMapMapView accessed from a thread other than the UI-thread: " + Thread.currentThread()));
    }
    return map;
}
 
Example #15
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineOffsetFunctionSecondaryCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      LineLayer layer = mapboxMap.getStyle().getLayerAs(Secondary.CASE_LAYER_ID);
      assertNotNull(layer.getLineOffset());
      assertNotNull(layer.getLineOffset().getExpression());
    }
  });
}
 
Example #16
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void toggleHidesLocalCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      trafficPlugin.setVisibility(false);
      assertTrue(mapboxMap.getStyle().getLayer(Local.CASE_LAYER_ID).getVisibility().getValue().equals(Property.NONE));
    }
  });
}
 
Example #17
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void toggleHidesSecondaryCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      trafficPlugin.setVisibility(false);
      assertTrue(mapboxMap.getStyle().getLayer(Secondary.CASE_LAYER_ID).getVisibility().getValue().equals(Property.NONE));
    }
  });
}
 
Example #18
Source File: DCMapFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
    this.mapboxMap = mapboxMap;
    for (OnMapReadyCallback onMapReadyCallback : mapReadyCallbackList) {
        onMapReadyCallback.onMapReady(mapboxMap);
    }
}
 
Example #19
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void secondaryBaseLayerAdded() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertTrue(mapboxMap.getStyle().getLayer(Secondary.BASE_LAYER_ID) != null);
    }
  });
}
 
Example #20
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void reattachPrimaryCaseWithLoadNewStyle() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      mapboxMap.setStyle(Style.DARK);
      controller.loopMainThreadForAtLeast(500);
      assertTrue(mapboxMap.getStyle().getLayer(Primary.CASE_LAYER_ID) != null);
    }
  });
}
 
Example #21
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineCapTrunkCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertEquals(ROUND, ((LineLayer) mapboxMap.getStyle().getLayerAs(Trunk.CASE_LAYER_ID)).getLineCap().getValue());
    }
  });
}
 
Example #22
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineJoinMotorWayBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertEquals(ROUND, ((LineLayer) mapboxMap.getStyle().getLayerAs(MotorWay.BASE_LAYER_ID)).getLineJoin().getValue());
    }
  });
}
 
Example #23
Source File: DualNavigationMapActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Override
public void onMapReady(MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;
  this.mapboxMap.setOnMapLongClickListener(this);
  initLocationEngine();
  initLocationLayer();
  initMapRoute();
  fetchRoute();
}
 
Example #24
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void secondaryCaseLayerMinZoom() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertTrue(mapboxMap.getStyle().getLayer(Secondary.CASE_LAYER_ID).getMinZoom() == Secondary.ZOOM_LEVEL);
    }
  });
}
 
Example #25
Source File: MapLayerInteractorTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void isLayerVisible_visibleReturnsFalseIfInvalidLayer() {
  HeatmapLayer invalidLayer = mock(HeatmapLayer.class);
  List<Layer> layers = buildLayerListWith(invalidLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  boolean isVisible = layerInteractor.isLayerVisible("heatmap");

  assertFalse(isVisible);
}
 
Example #26
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void toggleHidesTrunkCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      trafficPlugin.setVisibility(false);
      assertTrue(mapboxMap.getStyle().getLayer(Trunk.CASE_LAYER_ID).getVisibility().getValue().equals(Property.NONE));
    }
  });
}
 
Example #27
Source File: MapLayerInteractorTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void isLayerVisible_visibleReturnsTrue() {
  SymbolLayer anySymbolOrLineLayer = mock(SymbolLayer.class);
  when(anySymbolOrLineLayer.getSourceLayer()).thenReturn("any");
  when(anySymbolOrLineLayer.getVisibility()).thenReturn(visibility(Property.VISIBLE));
  List<Layer> layers = buildLayerListWith(anySymbolOrLineLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  boolean isVisible = layerInteractor.isLayerVisible("any");

  assertTrue(isVisible);
}
 
Example #28
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineJoinMotorWayCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertEquals(ROUND, ((LineLayer) mapboxMap.getStyle().getLayerAs(MotorWay.CASE_LAYER_ID)).getLineJoin().getValue());
    }
  });
}
 
Example #29
Source File: MapLayerInteractorTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void updateLayerVisibility_visibilityIsNotSet() {
  SymbolLayer anySymbolOrLineLayer = mock(SymbolLayer.class);
  when(anySymbolOrLineLayer.getSourceLayer()).thenReturn("any");
  List<Layer> layers = buildLayerListWith(anySymbolOrLineLayer);
  MapboxMap map = mock(MapboxMap.class);
  when(map.getLayers()).thenReturn(layers);
  MapLayerInteractor layerInteractor = new MapLayerInteractor(map);

  layerInteractor.updateLayerVisibility(true, "random");

  verify(anySymbolOrLineLayer, times(0)).setProperties(any(PropertyValue.class));
}
 
Example #30
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void motorWayCaseLayerVisible() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertTrue(mapboxMap.getStyle().getLayer(MotorWay.CASE_LAYER_ID).getVisibility().getValue().equals(Property.VISIBLE));
    }
  });
}