Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Add runtime styling APIs on MapSnapshotter (#268)
Browse files Browse the repository at this point in the history
* Add styleable snapshotter.

* Add style API for snapshotter

* Add observer interface to snapshotter

* WIP Add styling to snapshotter activity

* Update interface and implement addlayer functions.

* Deprecate methods instead of removing

* Implement addSource functions.

* Implement addImage function

* Still use the previous callback interface.

* Expose onStyleDidloaded interface

* Add setStyle method

* Start native snapshotter from start method

* Fix snapshotter test.

* Fix check style

* Keep the original interface

* Update gl-native

* Add demo for snapshotter heatmap layer

* bump gl-native

Co-authored-by: Alexander Shalamov <alexander.shalamov@mapbox.com>
(cherry picked from commit da6d8a2)
  • Loading branch information
Kevin Li committed Mar 26, 2020
1 parent 14eb8f0 commit 08d1398
Show file tree
Hide file tree
Showing 19 changed files with 565 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import androidx.annotation.Keep;

@Keep
class Image {
public class Image {
private final byte[] buffer;
private final float pixelRatio;
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Bundle;
import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import androidx.annotation.UiThread;
import android.text.TextUtils;
import android.view.View;

Expand Down Expand Up @@ -44,6 +38,13 @@
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import androidx.annotation.UiThread;

/**
* The general class to interact with in the Android Mapbox SDK. It exposes the entry point for all
* methods related to the MapView. You cannot instantiate {@link MapboxMap} object directly, rather,
Expand Down Expand Up @@ -93,6 +94,13 @@ public final class MapboxMap {
this.developerAnimationStartedListeners = developerAnimationStartedListeners;
}

/**
* Trigger the mapview to repaint.
*/
public void triggerRepaint() {
nativeMapView.triggerRepaint();
}

void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
transform.initialise(this, options);
uiSettings.initialise(context, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,

float getPixelRatio();

void triggerRepaint();

//
// Deprecated Annotations API
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,11 @@ public float getPixelRatio() {
return pixelRatio;
}

@Override
public void triggerRepaint() {
nativeTriggerRepaint();
}

@NonNull
@Override
public RectF getDensityDependantRectangle(final RectF rectangle) {
Expand Down Expand Up @@ -1476,6 +1481,9 @@ public long getNativePtr() {
return nativePtr;
}

@Keep
private native void nativeTriggerRepaint();

//
// Snapshot
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void addImage(@NonNull String name, @NonNull Drawable drawable) {
*/
public void addImage(@NonNull final String name, @NonNull Bitmap bitmap, boolean sdf) {
validateState("addImage");
nativeMap.addImages(new Image[]{toImage(new Builder.ImageWrapper(name, bitmap, sdf))});
nativeMap.addImages(new Image[] {toImage(new Builder.ImageWrapper(name, bitmap, sdf))});
}

/**
Expand Down Expand Up @@ -932,23 +932,23 @@ public Builder withBitmapImages(boolean sdf, @NonNull Pair<String, Bitmap>... va
return this;
}

String getUri() {
public String getUri() {
return styleUri;
}

String getJson() {
public String getJson() {
return styleJson;
}

List<Source> getSources() {
public List<Source> getSources() {
return sources;
}

List<LayerWrapper> getLayers() {
public List<LayerWrapper> getLayers() {
return layers;
}

List<ImageWrapper> getImages() {
public List<ImageWrapper> getImages() {
return images;
}

Expand All @@ -963,18 +963,30 @@ Style build(@NonNull NativeMap nativeMap) {
return new Style(this, nativeMap);
}

static class ImageWrapper {
public static class ImageWrapper {
Bitmap bitmap;
String id;
boolean sdf;

ImageWrapper(String id, Bitmap bitmap, boolean sdf) {
public ImageWrapper(String id, Bitmap bitmap, boolean sdf) {
this.id = id;
this.bitmap = bitmap;
this.sdf = sdf;
}

static ImageWrapper[] convertToImageArray(HashMap<String, Bitmap> bitmapHashMap, boolean sdf) {
public Bitmap getBitmap() {
return bitmap;
}

public String getId() {
return id;
}

public boolean isSdf() {
return sdf;
}

public static ImageWrapper[] convertToImageArray(HashMap<String, Bitmap> bitmapHashMap, boolean sdf) {
ImageWrapper[] images = new ImageWrapper[bitmapHashMap.size()];
List<String> keyList = new ArrayList<>(bitmapHashMap.keySet());
for (int i = 0; i < bitmapHashMap.size(); i++) {
Expand All @@ -985,43 +997,59 @@ static ImageWrapper[] convertToImageArray(HashMap<String, Bitmap> bitmapHashMap,
}
}

class LayerWrapper {
public class LayerWrapper {
Layer layer;

LayerWrapper(Layer layer) {
this.layer = layer;
}

public Layer getLayer() {
return layer;
}
}

class LayerAboveWrapper extends LayerWrapper {
public class LayerAboveWrapper extends LayerWrapper {
String aboveLayer;

LayerAboveWrapper(Layer layer, String aboveLayer) {
super(layer);
this.aboveLayer = aboveLayer;
}

public String getAboveLayer() {
return aboveLayer;
}
}

class LayerBelowWrapper extends LayerWrapper {
public class LayerBelowWrapper extends LayerWrapper {
String belowLayer;

LayerBelowWrapper(Layer layer, String belowLayer) {
super(layer);
this.belowLayer = belowLayer;
}

public String getBelowLayer() {
return belowLayer;
}
}

class LayerAtWrapper extends LayerWrapper {
public class LayerAtWrapper extends LayerWrapper {
int index;

LayerAtWrapper(Layer layer, int index) {
super(layer);
this.index = index;
}

public int getIndex() {
return index;
}
}
}

private static Image toImage(Builder.ImageWrapper imageWrapper) {
public static Image toImage(Builder.ImageWrapper imageWrapper) {
Bitmap bitmap = imageWrapper.bitmap;
if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
Expand Down
Loading

0 comments on commit 08d1398

Please sign in to comment.