[android] add plural style builder methods

This commit is contained in:
Łukasz Paczos
2019-02-28 11:13:22 +01:00
committed by Łukasz Paczos
parent 405e20e3c8
commit 638b91afc4
2 changed files with 200 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;
import android.util.DisplayMetrics;
import android.util.Pair;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.style.layers.Layer;
@@ -21,6 +22,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -607,6 +609,18 @@ public class Style {
return this;
}
/**
* Will add the sources when map style has loaded.
*
* @param sources the sources to add
* @return this
*/
@NonNull
public Builder withSources(@NonNull Source... sources) {
this.sources.addAll(Arrays.asList(sources));
return this;
}
/**
* Will add the layer when the style has loaded.
*
@@ -619,6 +633,20 @@ public class Style {
return this;
}
/**
* Will add the layers when the style has loaded.
*
* @param layers the layers to be added
* @return this
*/
@NonNull
public Builder withLayers(@NonNull Layer... layers) {
for (Layer layer : layers) {
this.layers.add(new LayerWrapper(layer));
}
return this;
}
/**
* Will add the layer when the style has loaded at a specified index.
*
@@ -683,6 +711,17 @@ public class Style {
return this.withImage(id, bitmap, false);
}
/**
* Will add the drawables as images when the map style has loaded.
*
* @param values pairs, where first is the id for te image and second is the drawable
* @return this
*/
@NonNull
public Builder withDrawableImages(@NonNull Pair<String, Drawable>... values) {
return this.withDrawableImages(false, values);
}
/**
* Will add the image when the map style has loaded.
*
@@ -695,6 +734,20 @@ public class Style {
return this.withImage(id, image, false);
}
/**
* Will add the images when the map style has loaded.
*
* @param values pairs, where first is the id for te image and second is the bitmap
* @return this
*/
@NonNull
public Builder withBitmapImages(@NonNull Pair<String, Bitmap>... values) {
for (Pair<String, Bitmap> value : values) {
this.withImage(value.first, value.second, false);
}
return this;
}
/**
* Will add the drawable as image when the map style has loaded.
*
@@ -712,6 +765,25 @@ public class Style {
return this.withImage(id, bitmap, sdf);
}
/**
* Will add the drawables as images when the map style has loaded.
*
* @param sdf the flag indicating image is an SDF or template image
* @param values pairs, where first is the id for te image and second is the drawable
* @return this
*/
@NonNull
public Builder withDrawableImages(boolean sdf, @NonNull Pair<String, Drawable>... values) {
for (Pair<String, Drawable> value : values) {
Bitmap bitmap = BitmapUtils.getBitmapFromDrawable(value.second);
if (bitmap == null) {
throw new IllegalArgumentException("Provided drawable couldn't be converted to a Bitmap.");
}
this.withImage(value.first, bitmap, sdf);
}
return this;
}
/**
* Will add the image when the map style has loaded.
*
@@ -726,6 +798,21 @@ public class Style {
return this;
}
/**
* Will add the images when the map style has loaded.
*
* @param sdf the flag indicating image is an SDF or template image
* @param values pairs, where first is the id for te image and second is the bitmap
* @return this
*/
@NonNull
public Builder withBitmapImages(boolean sdf, @NonNull Pair<String, Bitmap>... values) {
for (Pair<String, Bitmap> value : values) {
this.withImage(value.first, value.second, sdf);
}
return this;
}
String getUrl() {
return styleUrl;
}