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 Project: WhereAreTheEyes   Author: DaylightingSociety   File: MainActivity.java    License: 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 #2
Source Project: WhereAreTheEyes   Author: DaylightingSociety   File: MainActivity.java    License: 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 #3
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MockNavigationActivity.java    License: 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 #4
@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 #5
Source Project: mapbox-plugins-android   Author: mapbox   File: PlacePickerActivity.java    License: 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 #6
Source Project: WhereAreTheEyes   Author: DaylightingSociety   File: MainActivity.java    License: 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 #7
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineWidthFunctionLocalBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      LineLayer layer = mapboxMap.getStyle().getLayerAs(Local.BASE_LAYER_ID);
      assertNotNull(layer.getLineWidth());
      assertNotNull(layer.getLineWidth().getExpression());
    }
  });
}
 
Example #8
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void reattachLocalBaseWithLoadNewStyle() 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(Local.BASE_LAYER_ID) != null);
    }
  });
}
 
Example #9
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void primaryCaseLayerAdded() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertTrue(mapboxMap.getStyle().getLayer(Primary.CASE_LAYER_ID) != null);
    }
  });
}
 
Example #10
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 #11
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineJoinLocalCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertEquals(ROUND, ((LineLayer) mapboxMap.getStyle().getLayerAs(Local.CASE_LAYER_ID)).getLineJoin().getValue());
    }
  });
}
 
Example #12
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void toggleHidesMotorWayBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      trafficPlugin.setVisibility(false);
      assertTrue(mapboxMap.getStyle().getLayer(MotorWay.BASE_LAYER_ID).getVisibility().getValue().equals(Property.NONE));
    }
  });
}
 
Example #13
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 #14
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void motorWayCaseLayerAdded() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertTrue(mapboxMap.getStyle().getLayer(MotorWay.CASE_LAYER_ID) != null);
    }
  });
}
 
Example #15
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void localCaseLayerAdded() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertTrue(mapboxMap.getStyle().getLayer(Local.CASE_LAYER_ID) != null);
    }
  });
}
 
Example #16
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineJoinPrimaryCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertEquals(ROUND, ((LineLayer) mapboxMap.getStyle().getLayerAs(Primary.CASE_LAYER_ID)).getLineJoin().getValue());
    }
  });
}
 
Example #17
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void reattachTrunkBaseWithLoadNewStyle() 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(Trunk.BASE_LAYER_ID) != null);
    }
  });
}
 
Example #18
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineJoinTrunkBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertEquals(ROUND, ((LineLayer) mapboxMap.getStyle().getLayerAs(Trunk.BASE_LAYER_ID)).getLineJoin().getValue());
    }
  });
}
 
Example #19
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineWidthFunctionTrunkBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      LineLayer layer = mapboxMap.getStyle().getLayerAs(Trunk.BASE_LAYER_ID);
      assertNotNull(layer.getLineWidth());
      assertNotNull(layer.getLineWidth().getExpression());
    }
  });
}
 
Example #20
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineOffsetFunctionLocalBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      LineLayer layer = mapboxMap.getStyle().getLayerAs(Local.BASE_LAYER_ID);
      assertNotNull(layer.getLineOffset());
      assertNotNull(layer.getLineOffset().getExpression());
    }
  });
}
 
Example #21
Source Project: AirMapSDK-Android   Author: airmap   File: MyLocationMapActivity.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("MissingPermission")
protected void setupLocationEngine(MapboxMap map) {
    // Check if permissions are enabled and if not request
    if (PermissionsManager.areLocationPermissionsGranted(this)) {

        // Get an instance of the component
        locationComponent = map.getLocationComponent();

        // Set options
        LocationComponentOptions options = LocationComponentOptions.builder(this)
                .elevation(2f)
                .accuracyAlpha(0f)
                .enableStaleState(false)
                .build();

        // Activate with options
        map.getStyle((style -> locationComponent.activateLocationComponent(this, style, options)));

        // Enable to make component visible
        locationComponent.setLocationComponentEnabled(true);

        // Set the component's camera mode
        locationComponent.setCameraMode(CameraMode.TRACKING);
        locationComponent.setRenderMode(RenderMode.COMPASS);

        // turn on device GPS
        turnOnLocation();
    } else {
        permissionsManager = new PermissionsManager(this);
        permissionsManager.requestLocationPermissions(this);
    }
}
 
Example #22
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineOffsetFunctionMotorwayBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      LineLayer layer = mapboxMap.getStyle().getLayerAs(MotorWay.BASE_LAYER_ID);
      assertNotNull(layer.getLineOffset());
      assertNotNull(layer.getLineOffset().getExpression());
    }
  });
}
 
Example #23
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void trunkCaseLayerMinZoom() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertTrue(mapboxMap.getStyle().getLayer(Trunk.CASE_LAYER_ID).getMinZoom() == Trunk.ZOOM_LEVEL);
    }
  });
}
 
Example #24
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineWidthFunctionPrimaryCaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      LineLayer layer = mapboxMap.getStyle().getLayerAs(Primary.CASE_LAYER_ID);
      assertNotNull(layer.getLineWidth());
      assertNotNull(layer.getLineWidth().getExpression());
    }
  });
}
 
Example #25
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineWidthFunctionSecondaryCaseLayer() 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.getLineWidth());
      assertNotNull(layer.getLineWidth().getExpression());
    }
  });
}
 
Example #26
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void lineCapPrimaryBaseLayer() throws Exception {
  executeTrafficTest(new TrafficPluginAction.OnPerformTrafficAction() {
    @Override
    public void onTrafficAction(TrafficPlugin trafficPlugin, MapboxMap mapboxMap, UiController controller) {
      assertEquals(ROUND, ((LineLayer) mapboxMap.getStyle().getLayerAs(Primary.BASE_LAYER_ID)).getLineCap().getValue());
    }
  });
}
 
Example #27
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void reattachMotorWayCaseWithLoadNewStyle() 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(MotorWay.CASE_LAYER_ID) != null);
    }
  });
}
 
Example #28
Source Project: WhereAreTheEyes   Author: DaylightingSociety   File: DownloadPinsTask.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void renderPins(final PinData p) {
    // Note: Use a LinkedList here so we don't need contiguous memory
    // We were having some interesting memory problems with an ArrayList.
    final LinkedList<MarkerOptions> markers = new LinkedList<MarkerOptions>();

    Iterator it = p.pins.entrySet().iterator();
    while( it.hasNext() ) {
        Map.Entry pair = (Map.Entry)it.next();
        final MarkerOptions marker = new MarkerOptions().position((LatLng)pair.getKey());
        marker.title(p.map.getContext().getString(R.string.confirmations) + ": " + Integer.valueOf((int)pair.getValue()).toString());
        marker.icon(Images.getCameraIcon());
        marker.snippet("This is a camera.");
        markers.add(marker);
    }
    if( markers.size() != 0 ) {
        Log.d("GPS", "Trying to render pins: " + Integer.toString(markers.size()));

        Runnable clearPins = new Runnable() {
            public void run() {
                p.map.getMapAsync(new OnMapReadyCallback() {
                    @Override
                    public void onMapReady(MapboxMap mapboxMap) {
                        // We don't want to layer cameras on top
                        mapboxMap.removeAnnotations();
                        mapboxMap.addMarkers(markers);
                        Log.d("GPS", "Pins now on map: " + Integer.toString(mapboxMap.getAnnotations().size()));
                    }
                });
            }
        };

        // Note: Pins *must* be cleared on the main thread.
        // This is because if a UI window (like the pin detail screen) is currently open
        // then only the thread that created it can destroy it. If we delete the pins from
        // the background while a UI window for the pin is open it crashes the app.
        Handler mainThread = new Handler(Looper.getMainLooper());
        mainThread.post(clearPins);
    }
}
 
Example #29
Source Project: mapbox-plugins-android   Author: mapbox   File: TrafficPluginTest.java    License: 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 #30
Source Project: graphhopper-navigation-android   Author: graphhopper   File: MapLayerInteractorTest.java    License: 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));
}