Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support heatmap layer & fill extrusion layer & update image source #1187

Merged
merged 20 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.buildlog/
.history
.svn/
.fvm/

# IntelliJ related
*.iml
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ format:

install_formatting:
./install_formatting_tools.sh

codegen:
dart scripts/lib/generate.dart
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ MapboxMap(
| Circle Layer | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Line Layer | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Fill Layer | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Fill Extrusion Layer | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Hillshade Layer | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Heatmap Layer | :x: | :x: | :x: |
| Heatmap Layer | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Vector Source | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Raster Source | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| GeoJson Source | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,50 @@ static PropertyValue[] interpretFillLayerProperties(Object o) {
return properties.toArray(new PropertyValue[properties.size()]);
}

static PropertyValue[] interpretFillExtrusionLayerProperties(Object o) {
final Map<String, String> data = (Map<String, String>) toMap(o);
final List<PropertyValue> properties = new LinkedList();
final JsonParser parser = new JsonParser();

for (Map.Entry<String, String> entry : data.entrySet()) {
final JsonElement jsonElement = parser.parse(entry.getValue());
Expression expression = Expression.Converter.convert(jsonElement);
switch (entry.getKey()) {
case "fill-extrusion-opacity":
properties.add(PropertyFactory.fillExtrusionOpacity(expression));
break;
case "fill-extrusion-color":
properties.add(PropertyFactory.fillExtrusionColor(expression));
break;
case "fill-extrusion-translate":
properties.add(PropertyFactory.fillExtrusionTranslate(expression));
break;
case "fill-extrusion-translate-anchor":
properties.add(PropertyFactory.fillExtrusionTranslateAnchor(expression));
break;
case "fill-extrusion-pattern":
properties.add(PropertyFactory.fillExtrusionPattern(expression));
break;
case "fill-extrusion-height":
properties.add(PropertyFactory.fillExtrusionHeight(expression));
break;
case "fill-extrusion-base":
properties.add(PropertyFactory.fillExtrusionBase(expression));
break;
case "fill-extrusion-vertical-gradient":
properties.add(PropertyFactory.fillExtrusionVerticalGradient(expression));
break;
case "visibility":
properties.add(PropertyFactory.visibility(entry.getValue()));
break;
default:
break;
}
}

return properties.toArray(new PropertyValue[properties.size()]);
}

static PropertyValue[] interpretRasterLayerProperties(Object o) {
final Map<String, String> data = (Map<String, String>) toMap(o);
final List<PropertyValue> properties = new LinkedList();
Expand Down Expand Up @@ -453,4 +497,39 @@ static PropertyValue[] interpretHillshadeLayerProperties(Object o) {

return properties.toArray(new PropertyValue[properties.size()]);
}

static PropertyValue[] interpretHeatmapLayerProperties(Object o) {
final Map<String, String> data = (Map<String, String>) toMap(o);
final List<PropertyValue> properties = new LinkedList();
final JsonParser parser = new JsonParser();

for (Map.Entry<String, String> entry : data.entrySet()) {
final JsonElement jsonElement = parser.parse(entry.getValue());
Expression expression = Expression.Converter.convert(jsonElement);
switch (entry.getKey()) {
case "heatmap-radius":
properties.add(PropertyFactory.heatmapRadius(expression));
break;
case "heatmap-weight":
properties.add(PropertyFactory.heatmapWeight(expression));
break;
case "heatmap-intensity":
properties.add(PropertyFactory.heatmapIntensity(expression));
break;
case "heatmap-color":
properties.add(PropertyFactory.heatmapColor(expression));
break;
case "heatmap-opacity":
properties.add(PropertyFactory.heatmapOpacity(expression));
break;
case "visibility":
properties.add(PropertyFactory.visibility(entry.getValue()));
break;
default:
break;
}
}

return properties.toArray(new PropertyValue[properties.size()]);
}
}
143 changes: 142 additions & 1 deletion android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ final class MapboxMapController
OnMapReadyCallback,
OnCameraTrackingChangedListener,
PlatformView {

private static final String TAG = "MapboxMapController";
private final int id;
private final MethodChannel methodChannel;
Expand Down Expand Up @@ -395,6 +396,7 @@ private void addSymbolLayer(
PropertyValue[] properties,
boolean enableInteraction,
Expression filter) {

SymbolLayer symbolLayer = new SymbolLayer(layerName, sourceName);
symbolLayer.setProperties(properties);
if (sourceLayer != null) {
Expand Down Expand Up @@ -487,6 +489,40 @@ private void addFillLayer(
}
}

private void addFillExtrusionLayer(
String layerName,
String sourceName,
String belowLayerId,
String sourceLayer,
Float minZoom,
Float maxZoom,
PropertyValue[] properties,
boolean enableInteraction,
Expression filter) {
FillExtrusionLayer fillLayer = new FillExtrusionLayer(layerName, sourceName);
fillLayer.setProperties(properties);
if (sourceLayer != null) {
fillLayer.setSourceLayer(sourceLayer);
}
if (minZoom != null) {
fillLayer.setMinZoom(minZoom);
}
if (maxZoom != null) {
fillLayer.setMaxZoom(maxZoom);
}
if (filter != null) {
fillLayer.setFilter(filter);
}
if (belowLayerId != null) {
style.addLayerBelow(fillLayer, belowLayerId);
} else {
style.addLayer(fillLayer);
}
if (enableInteraction) {
interactiveFeatureLayerIds.add(layerName);
}
}

private void addCircleLayer(
String layerName,
String sourceName,
Expand Down Expand Up @@ -573,13 +609,38 @@ private void addHillshadeLayer(
}
}

private void addHeatmapLayer(
String layerName,
String sourceName,
Float minZoom,
Float maxZoom,
String belowLayerId,
PropertyValue[] properties,
Expression filter) {
HeatmapLayer layer = new HeatmapLayer(layerName, sourceName);
layer.setProperties(properties);
if (minZoom != null) {
layer.setMinZoom(minZoom);
}
if (maxZoom != null) {
layer.setMaxZoom(maxZoom);
}
if (belowLayerId != null) {
style.addLayerBelow(layer, belowLayerId);
} else {
style.addLayer(layer);
}
}

private Feature firstFeatureOnLayers(RectF in) {
if (style != null) {
final List<Layer> layers = style.getLayers();
final List<String> layersInOrder = new ArrayList<String>();
for (Layer layer : layers) {
String id = layer.getId();
if (interactiveFeatureLayerIds.contains(id)) layersInOrder.add(id);
if (interactiveFeatureLayerIds.contains(id)) {
layersInOrder.add(id);
}
}
Collections.reverse(layersInOrder);

Expand Down Expand Up @@ -923,6 +984,37 @@ public void onError(@NonNull String message) {
filterExpression);
updateLocationComponentLayer();

result.success(null);
break;
}
case "fillExtrusionLayer#add":
{
final String sourceId = call.argument("sourceId");
final String layerId = call.argument("layerId");
final String belowLayerId = call.argument("belowLayerId");
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final String filter = call.argument("filter");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretFillExtrusionLayerProperties(
call.argument("properties"));

Expression filterExpression = parseFilter(filter);

addFillExtrusionLayer(
layerId,
sourceId,
belowLayerId,
sourceLayer,
minzoom != null ? minzoom.floatValue() : null,
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
filterExpression);
updateLocationComponentLayer();

result.success(null);
break;
}
Expand Down Expand Up @@ -997,6 +1089,28 @@ public void onError(@NonNull String message) {
null);
updateLocationComponentLayer();

result.success(null);
break;
}
case "heatmapLayer#add":
{
final String sourceId = call.argument("sourceId");
final String layerId = call.argument("layerId");
final String belowLayerId = call.argument("belowLayerId");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final PropertyValue[] properties =
LayerPropertyConverter.interpretHeatmapLayerProperties(call.argument("properties"));
addHeatmapLayer(
layerId,
sourceId,
minzoom != null ? minzoom.floatValue() : null,
maxzoom != null ? maxzoom.floatValue() : null,
belowLayerId,
properties,
null);
updateLocationComponentLayer();

result.success(null);
break;
}
Expand Down Expand Up @@ -1065,6 +1179,32 @@ public void onFailure(@NonNull Exception exception) {
result.success(null);
break;
}
case "style#updateImageSource":
{
if (style == null) {
result.error(
"STYLE IS NULL",
"The style is null. Has onStyleLoaded() already been invoked?",
null);
}
ImageSource imageSource = style.getSourceAs(call.argument("imageSourceId"));
List<LatLng> coordinates = Convert.toLatLngList(call.argument("coordinates"), false);
if (coordinates != null) {
// https://github.com/mapbox/mapbox-maps-android/issues/302
imageSource.setCoordinates(
new LatLngQuad(
coordinates.get(0),
coordinates.get(1),
coordinates.get(2),
coordinates.get(3)));
}
byte[] bytes = call.argument("bytes");
if (bytes != null) {
imageSource.setImage(BitmapFactory.decodeByteArray(bytes, 0, call.argument("length")));
}
result.success(null);
break;
}
case "style#addSource":
{
final String id = Convert.toString(call.argument("sourceId"));
Expand Down Expand Up @@ -1844,6 +1984,7 @@ void stopDragging() {

/** Simple Listener to listen for the status of camera movements. */
public class OnCameraMoveFinishedListener implements MapboxMap.CancelableCallback {

@Override
public void onFinish() {}

Expand Down
Loading