Haerul Muttaqin :
I have specified the colors of object2.addProperty("marker-colors", "#ffbf00");
in json to then retrieve the value. withImage(ICON_ID, createBitMap(get("marker-color")))
I will use color value in createBitmap(...)
here my code
List<Feature> features = new ArrayList<>();
JsonObject object1 = new JsonObject();
object1.addProperty("title", "TEST1");
object1.addProperty("marker-color", "#c70024");
features.add(Feature.fromGeometry(
Point.fromLngLat(106.535033, -6.323488), object1));
JsonObject object2 = new JsonObject();
object2.addProperty("title", "TEST2");
object2.addProperty("marker-color", "#ffbf00");
features.add(Feature.fromGeometry(
Point.fromLngLat(106.897423, -6.277078), object2));
JsonObject object3 = new JsonObject();
object3.addProperty("title", "TEST3");
object3.addProperty("marker-color", "#00c753");
features.add(Feature.fromGeometry(
Point.fromLngLat(106.797217, -6.171958), object3));
then
mapboxMap.setStyle(new Style.Builder().fromUri(CPN_STYLE)
.withSource(new GeoJsonSource(SOURCE_ID,
FeatureCollection.fromFeatures(features)))
.withImage(ICON_ID, createBitMap(get("marker-color")))
.withLayer(new SymbolLayer(LAYER_ID, SOURCE_ID)
.withProperties(
textField(get("title")),
iconImage(ICON_ID),
textSize(14f),
iconAllowOverlap(true),
iconIgnorePlacement(true),
textColor(get("marker-color")),
textJustify(TEXT_JUSTIFY_AUTO),
iconOffset(new Float[]{0f, -9f}))
), style -> {
mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(-6.323488, 106.535033))
.zoom(7)
.build()), 1000);
});
The answer will be very useful. Thank you
langsmith :
You could do the following instead of using JsonObject
s
Feature singleFeature = Feature.fromGeometry(Point.fromLngLat(LONG,LAT));
singleFeature.addStringProperty("title", "TEST1");
singleFeature.addStringProperty("marker-color", "#c70024");
features.add(singleFeature);
What's the createBitmap()
method look like under the hood?
You'll probably want to use the Maps SDK's MapView.OnStyleImageMissingListener
and closely follow what's done in https://docs.mapbox.com/android/maps/examples/missing-icon/.
Don't use
.withImage()
as you set up the SymbolLayer.It'll be
.iconImage(get("marker-color")),
for your SymbolLayer.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=319237&siteId=1