com.mapbox.mapboxsdk.maps.Style Java Examples

The following examples show how to use com.mapbox.mapboxsdk.maps.Style. 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: MapDataManager.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
public MapDataManager(Context context, @NonNull Style mapboxMapStyle, LocationComponent locationComponent, int chatId, MapDataState updateCallback) {
    Log.d(TAG, "performance test - create map manager");
    this.mapboxStyle = mapboxMapStyle;
    this.context = context;
    this.dcContext = DcHelper.getContext(context);
    this.chatId = chatId;
    boundingBuilder = new LatLngBounds.Builder();
    this.callback = updateCallback;
    this.locationComponent = locationComponent;

    initInfoWindowLayer();
    initLastPositionLayer();
    initLocationComponent();

    filterProvider.setMessageFilter(true);
    filterProvider.setLastPositionFilter(System.currentTimeMillis() - DEFAULT_LAST_POSITION_DELTA);
    applyLastPositionFilter();

    updateSources();
    dcContext.eventCenter.addObserver(DC_EVENT_LOCATION_CHANGED, this);

    Log.d(TAG, "performance test - create map manager finished");
}
 
Example #2
Source File: ProgramEventDetailActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setLayer(Style style) {
    SymbolLayer symbolLayer = new SymbolLayer("POINT_LAYER", "events").withProperties(
            PropertyFactory.iconImage("ICON_ID"),
            iconAllowOverlap(true),
            iconOffset(new Float[]{0f, -9f})
    );
    symbolLayer.setMinZoom(0);
    style.addLayer(symbolLayer);

    if (featureType != FeatureType.POINT)
        style.addLayerBelow(new FillLayer("POLYGON_LAYER", "events").withProperties(
                fillColor(
                        ColorUtils.getPrimaryColorWithAlpha(this, ColorUtils.ColorType.PRIMARY_LIGHT, 150f)
                )
                ), "settlement-label"
        );
}
 
Example #3
Source File: FillChangeActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onMapReady(@NonNull MapboxMap map) {
  map.setStyle(new Style.Builder().fromUri(Style.MAPBOX_STREETS), style -> {
    fillManager = new FillManager(mapView, map, style, "aerialway");
    fillManager.addClickListener(fill -> {
      Toast.makeText(
          FillChangeActivity.this,
          "Clicked: " + fill.getId(),
          Toast.LENGTH_SHORT).show();
      return false;
    });

    fill = fillManager.create(new FillOptions()
      .withLatLngs(STAR_SHAPE_POINTS)
      .withFillColor(ColorUtils.colorToRgbaString(BLUE_COLOR))
    );
  });
}
 
Example #4
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 #5
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 #6
Source File: PressForSymbolActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_annotation);
  AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
  mapView = findViewById(R.id.mapView);
  mapView.onCreate(savedInstanceState);
  mapView.getMapAsync(map -> {
    mapboxMap = map;
    mapboxMap.setCameraPosition(new CameraPosition.Builder()
      .target(new LatLng(60.169091, 24.939876))
      .zoom(12)
      .tilt(20)
      .bearing(90)
      .build()
    );
    mapboxMap.addOnMapLongClickListener(this::addSymbol);
    mapboxMap.addOnMapClickListener(this::addSymbol);
    mapboxMap.setStyle(getStyleBuilder(Style.MAPBOX_STREETS), style -> {
      findViewById(R.id.fabStyles).setOnClickListener(v ->
        mapboxMap.setStyle(getStyleBuilder(Utils.INSTANCE.getNextStyle())));

      symbolManager = new SymbolManager(mapView, mapboxMap, style);
      symbolManager.setIconAllowOverlap(true);
      symbolManager.setTextAllowOverlap(true);
    });
  });
}
 
Example #7
Source File: ProgramEventDetailActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setMap(FeatureCollection featureCollection, BoundingBox boundingBox) {
        if (map == null) {
            binding.mapView.getMapAsync(mapbox -> {
                map = mapbox;
                if (map.getStyle() == null){
                    map.setStyle(Style.MAPBOX_STREETS, style -> {
                        map.addOnMapClickListener(this);
                        style.addImage("ICON_ID", BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default));
                        setSource(style, featureCollection);
                        setLayer(style);

                        initCameraPosition(map,this,boundingBox);

                        markerViewManager = new MarkerViewManager(binding.mapView, map);
                        symbolManager = new SymbolManager(binding.mapView, map, style, null,
                                new GeoJsonOptions().withTolerance(0.4f));

                        symbolManager.setIconAllowOverlap(true);
                        symbolManager.setTextAllowOverlap(true);
                        symbolManager.create(featureCollection);

                    });
                }
                else {
                    ((GeoJsonSource) mapbox.getStyle().getSource("events")).setGeoJson(featureCollection);
                    initCameraPosition(map,this,boundingBox);
                }
            });
        } else {
            ((GeoJsonSource) map.getStyle().getSource("events")).setGeoJson(featureCollection);
            initCameraPosition(map,this, boundingBox);
        }
}
 
Example #8
Source File: BulkSymbolActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void initMap(MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;
  mapboxMap.moveCamera(
    CameraUpdateFactory.newLatLngZoom(
      new LatLng(38.87031, -77.00897), 10
    )
  );

  mapboxMap.setStyle(new Style.Builder().fromUri(Style.MAPBOX_STREETS), style -> {
    findViewById(R.id.fabStyles).setOnClickListener(v -> mapboxMap.setStyle(Utils.INSTANCE.getNextStyle()));
    symbolManager = new SymbolManager(mapView, mapboxMap, style);
    symbolManager.setIconAllowOverlap(true);
    loadData(0);
  });
}
 
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 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 #10
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void reattachLocalCaseWithLoadNewStyle() 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.CASE_LAYER_ID) != null);
    }
  });
}
 
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 reattachSecondaryBaseWithLoadNewStyle() 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(Secondary.BASE_LAYER_ID) != null);
    }
  });
}
 
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 reattachSecondaryCaseWithLoadNewStyle() 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(Secondary.CASE_LAYER_ID) != null);
    }
  });
}
 
Example #13
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void reattachPrimaryBaseWithLoadNewStyle() 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.BASE_LAYER_ID) != null);
    }
  });
}
 
Example #14
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 #15
Source File: TrafficPluginTest.java    From mapbox-plugins-android with 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 #16
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void reattachTrunkCaseWithLoadNewStyle() 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.CASE_LAYER_ID) != null);
    }
  });
}
 
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 reattachMotorWayBaseWithLoadNewStyle() 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.BASE_LAYER_ID) != null);
    }
  });
}
 
Example #18
Source File: TrafficPluginTest.java    From mapbox-plugins-android with 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 #19
Source File: OnMapReadyIdlingResource.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
  this.mapboxMap = mapboxMap;
  mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
    if (resourceCallback != null) {
      resourceCallback.onTransitionToIdle();
    }
  });
}
 
Example #20
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 #21
Source File: TrafficPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onDidFinishLoadingStyle() {
  mapboxMap.getStyle(new Style.OnStyleLoaded() {
    @Override
    public void onStyleLoaded(@NonNull Style style) {
      TrafficPlugin.this.style = style;
      setVisibility(visible);
    }
  });
}
 
Example #22
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 #23
Source File: PlacePickerActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@SuppressWarnings( {"MissingPermission"})
private void enableLocationComponent(@NonNull Style loadedMapStyle) {
  // Check if permissions are enabled and if not request
  if (PermissionsManager.areLocationPermissionsGranted(this)) {

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

    // Activate with options
    locationComponent.activateLocationComponent(
      LocationComponentActivationOptions.builder(this, loadedMapStyle).build());

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

    // Set the component's camera mode
    locationComponent.setCameraMode(CameraMode.NONE);

    // Set the component's render mode
    locationComponent.setRenderMode(RenderMode.NORMAL);

    addUserLocationButton();
  } else {
    permissionsManager = new PermissionsManager(this);
    permissionsManager.requestLocationPermissions(this);
  }
}
 
Example #24
Source File: SearchTEActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setLayer(Style style) {

        SymbolLayer symbolLayer = new SymbolLayer("POINT_LAYER", "teis").withProperties(
                PropertyFactory.iconImage(get("teiImage")),
                iconOffset(new Float[]{0f, -25f}),
                iconAllowOverlap(true),
                textAllowOverlap(true)
        );

        symbolLayer.setFilter(eq(literal("$type"), literal("Point")));

        style.addLayer(symbolLayer);

        if (featureType != FeatureType.POINT) {
            style.addLayerBelow(new FillLayer("POLYGON_LAYER", "teis")
                            .withProperties(
                                    fillColor(
                                            ColorUtils.getPrimaryColorWithAlpha(this, ColorUtils.ColorType.PRIMARY_LIGHT, 150f)
                                    ))
                            .withFilter(eq(literal("$type"), literal("Polygon"))),
                    "POINT_LAYER"
            );
            style.addLayerAbove(new LineLayer("POLYGON_BORDER_LAYER", "teis")
                            .withProperties(
                                    lineColor(
                                            ColorUtils.getPrimaryColor(this, ColorUtils.ColorType.PRIMARY_DARK)
                                    ),
                                    lineWidth(2f))
                            .withFilter(eq(literal("$type"), literal("Polygon"))),
                    "POLYGON_LAYER"

            );
        }
    }
 
Example #25
Source File: PlacePickerActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void onPermissionResult(boolean granted) {
  if (granted) {
    mapboxMap.getStyle(new Style.OnStyleLoaded() {
      @Override
      public void onStyleLoaded(@NonNull Style style) {
        if (options != null && options.includeDeviceLocationButton()) {
          enableLocationComponent(style);
        }
      }
    });
  }
}
 
Example #26
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private void setupJurisdictionsForEnterprise() {
    // Reload the style after setup is complete
    if (map == null || map.getMap() == null || map.getMap().getStyle() == null) {
        return;
    }

    OfflineManager.getInstance(map.getContext()).clearAmbientCache(null);

    Style style = map.getMap().getStyle();
    String jurisdictionsId = "jurisdictions";

    if (style.getLayer(jurisdictionsId) != null) {
        style.removeLayer(jurisdictionsId);
    }

    if (style.getSource(jurisdictionsId) != null) {
        style.removeSource(jurisdictionsId);
    }

    TileSet tileSet = new TileSet(tileJsonSpecVersion, AirMap.getBaseJurisdictionsUrlTemplate());
    tileSet.setMaxZoom(12f);
    tileSet.setMinZoom(8f);
    Source source = new VectorSource(jurisdictionsId, tileSet);
    style.addSource(source);
    Layer layer = new FillLayer(jurisdictionsId, jurisdictionsId)
            .withSourceLayer(jurisdictionsId)
            .withProperties(fillColor(TRANSPARENT), fillOpacity(1f));
    style.addLayerAt(layer, 0);
}
 
Example #27
Source File: LineActivity.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.onCreate(savedInstanceState);
  mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
    findViewById(R.id.fabStyles).setOnClickListener(v -> mapboxMap.setStyle(Utils.INSTANCE.getNextStyle()));

    mapboxMap.moveCamera(CameraUpdateFactory.zoomTo(2));

    lineManager = new LineManager(mapView, mapboxMap, style);
    lineManager.addClickListener(line -> {
      Toast.makeText(LineActivity.this,
          String.format("Line clicked %s", line.getId()),
          Toast.LENGTH_SHORT
      ).show();
      return false;
    });
    lineManager.addLongClickListener(line -> {
      Toast.makeText(LineActivity.this,
          String.format("Line long clicked %s", line.getId()),
          Toast.LENGTH_SHORT
      ).show();
      return false;
    });

    // create a fixed line
    List<LatLng> latLngs = new ArrayList<>();
    latLngs.add(new LatLng(-2.178992, -4.375974));
    latLngs.add(new LatLng(-4.107888, -7.639772));
    latLngs.add(new LatLng(2.798737, -11.439207));
    LineOptions lineOptions = new LineOptions()
      .withLatLngs(latLngs)
      .withLineColor(ColorUtils.colorToRgbaString(Color.RED))
      .withLineWidth(5.0f);
    lineManager.create(lineOptions);

    // random add lines across the globe
    List<List<LatLng>> lists = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
      lists.add(createRandomLatLngs());
    }

    List<LineOptions> lineOptionsList = new ArrayList<>();
    for (List<LatLng> list : lists) {
      int color = Color.argb(255, random.nextInt(256), random.nextInt(256), random.nextInt(256));
      lineOptionsList.add(new LineOptions().withLatLngs(list).withLineColor(ColorUtils.colorToRgbaString(color)));
    }
    lineManager.create(lineOptionsList);

    try {
      lineManager.create(Utils.INSTANCE.loadStringFromAssets(this, "annotations.json"));
    } catch (IOException e) {
      throw new RuntimeException("Unable to parse annotations.json");
    }
  }));
}
 
Example #28
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 #29
Source File: PressForSymbolActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private Style.Builder getStyleBuilder(@NonNull String styleUrl) {
  return new Style.Builder().fromUri(styleUrl)
    .withImage(ID_ICON, generateBitmap(R.drawable.mapbox_ic_place));
}
 
Example #30
Source File: SymbolActivity.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void addAirplaneImageToStyle(Style style) {
  style.addImage(ID_ICON_AIRPORT,
    BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_airplanemode_active_black_24dp)),
    true);
}