mapbox / mapbox-plugins-android

Mapbox Android Plugins are a collection of libraries that extend our other SDKs, helping you design powerful mapping features while the plugins handle most of the heavy lifting.
https://www.mapbox.com/android-docs/plugins/overview/
BSD 2-Clause "Simplified" License
241 stars 120 forks source link

Add Annotation Plugin custom image example #848

Closed lomza closed 5 years ago

lomza commented 5 years ago

Hi,

I've been following example of SymbolActivity.java - https://github.com/mapbox/mapbox-plugins-android/blob/master/app/src/main/java/com/mapbox/mapboxsdk/plugins/testapp/activity/annotation/SymbolActivity.java and found out that Maki images as used as symbol image. I have an svg image, imported as vector image into Android Studio. How can I use it for my symbol icon image?

Thanks!

LukasPaczos commented 5 years ago

Hey @lomza, thanks for reaching out!

You will need to convert your SVG to a bitmap (you can easily find how to do that on the web) and add it to the map with

mapboxMap.getStyle(new Style.OnStyleLoaded() {
  @Override
  public void onStyleLoaded(@NonNull Style style) {
    style.addImage("my_image", bitmap);
  }
});

then you can reference that image's ID in the SymbolOptions

SymbolOptions symbolOptions = new SymbolOptions()
        .withLatLng(new LatLng(6.687337, 0.381457))
        .withIconImage("my_image")
        ...
lomza commented 5 years ago

@LukasPaczos , thank you so much! It worked perfectly ;)

gracedotdotdot commented 5 years ago

Hi @LukasPaczos i want to add multiple markers on it, and I add in onStyleLoaded

// create symbol manager GeoJsonOptions geoJsonOptions = new GeoJsonOptions().withTolerance(0.4f); symbolManager = new SymbolManager(mapView, mapboxMap, style, null, geoJsonOptions); // create a symbol SymbolOptions symbolOptions = new SymbolOptions() .withLatLng(new LatLng(31.995560, 34.767070)) .withIconImage("Charge") .withIconSize(1.3f) .withDraggable(true); symbol = symbolManager.create(symbolOptions);

But it isn't showing any markers, may I ask what may be the problems? do you have any multiple markers' example?

LukasPaczos commented 5 years ago

Sure @gracedotdotdot, check out PressForSymbolActivity example.

gracedotdotdot commented 5 years ago

when I try to use the addSymbol function in your reference. I add the

implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v8:0.7.0'

line in my build.gradle, but it comes error

Duplicate class com.mapbox.mapboxsdk.plugins.annotation.Annotation found in modules classes.jar (com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.6.0) and classes.jar (com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v8:0.7.0)

May I ask what should I delete?

LukasPaczos commented 5 years ago

You can inspect your dependencies and verify where the duplicate is coming from: https://stackoverflow.com/a/39020703/9126211.

gracedotdotdot commented 5 years ago

Hi I've already deleted the duplicate libraries but it's still popping duplicate class error. may I ask why can't I use the code in #1017 to add multiple markers dynamically? Thank you

HridaySarma commented 4 years ago

Thanks @LukasPaczos for helping out. I was finding difficulty to implement custom icons to the map that goes with our algorithm. It worked like a charm.