Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
m0nac0 committed Dec 18, 2023
2 parents 570ff95 + 1fd4001 commit 33969e9
Show file tree
Hide file tree
Showing 21 changed files with 597 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter_beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Build iOS package
run: flutter build ios --simulator
- name: Upload Runner.app as artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Runner.app
path: example/build/ios/iphonesimulator
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/flutter_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
- name: Build iOS package
run: flutter build ios --simulator
- name: Upload Runner.app as artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Runner.app
path: example/build/ios/iphonesimulator
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Include the following JavaScript and CSS files in the `<head>` of the `web/index
| Circle | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Line | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Fill | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Fill Extrusion | :white_check_mark: | :white_check_mark: | :white_check_mark: |


## Map Styles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;


import static com.mapbox.mapboxgl.Convert.toMap;

class LayerPropertyConverter {
Expand Down Expand Up @@ -106,9 +107,9 @@ static PropertyValue[] interpretSymbolLayerProperties(Object o) {
properties.add(PropertyFactory.iconTextFitPadding(expression));
break;
case "icon-image":
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()) {
if(jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()){
properties.add(PropertyFactory.iconImage(jsonElement.getAsString()));
} else {
}else{
properties.add(PropertyFactory.iconImage(expression));
}
break;
Expand Down Expand Up @@ -375,6 +376,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().substring(1, entry.getValue().length() - 1)));
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
65 changes: 65 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,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 @@ -1037,6 +1071,37 @@ public void onError(@NonNull String message) {
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;
}
case "circleLayer#add":
{
final String sourceId = call.argument("sourceId");
Expand Down
1 change: 1 addition & 0 deletions example/lib/custom_marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class CustomMarkerState extends State<CustomMarker> {
onStyleLoadedCallback: _onStyleLoadedCallback,
initialCameraPosition:
const CameraPosition(target: LatLng(35.0, 135.0), zoom: 5),
iosLongClickDuration: const Duration(milliseconds: 200),
),
IgnorePointer(
ignoring: true,
Expand Down
36 changes: 36 additions & 0 deletions example/lib/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ class LayerState extends State {
filter: ['==', 'id', filteredId],
);

await controller.addFillExtrusionLayer(
"fills",
"fills-extrusion",
const FillExtrusionLayerProperties(
fillExtrusionHeight: 300,
fillExtrusionColor: [
Expressions.interpolate,
['exponential', 0.5],
[Expressions.zoom],
11,
'red',
18,
'blue'
],
),
belowLayerId: "water",
filter: ['==', 'id', 2],
);

await controller.addLineLayer(
"fills",
"lines",
Expand Down Expand Up @@ -314,6 +333,23 @@ final _fills = {
]
}
},
{
"type": "Feature",
"id": 2,
"properties": <String, dynamic>{'id': 2},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[151.121824791363, -33.885947459842846],
[151.121824791363, -33.89768020458625],
[151.13561641336742, -33.89768020458625],
[151.13561641336742, -33.885947459842846],
[151.121824791363, -33.885947459842846]
]
],
}
},
{
"type": "Feature",
"id": 1,
Expand Down
30 changes: 30 additions & 0 deletions ios/Classes/LayerPropertyConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,36 @@ class LayerPropertyConverter {
}
}

class func addFillExtrusionProperties(fillExtrusionLayer: MGLFillExtrusionStyleLayer, properties: [String: String]) {
for (propertyName, propertyValue) in properties {
let expression = interpretExpression(propertyName: propertyName, expression: propertyValue)
switch propertyName {
case "fill-extrusion-opacity":
fillExtrusionLayer.fillExtrusionOpacity = expression
case "fill-extrusion-color":
fillExtrusionLayer.fillExtrusionColor = expression
case "fill-extrusion-translate":
fillExtrusionLayer.fillExtrusionTranslation = expression
case "fill-extrusion-translate-anchor":
fillExtrusionLayer.fillExtrusionTranslationAnchor = expression
case "fill-extrusion-pattern":
fillExtrusionLayer.fillExtrusionPattern = expression
case "fill-extrusion-height":
fillExtrusionLayer.fillExtrusionHeight = expression
case "fill-extrusion-base":
fillExtrusionLayer.fillExtrusionBase = expression
case "fill-extrusion-vertical-gradient":
fillExtrusionLayer.fillExtrusionHasVerticalGradient = expression
case "visibility":
let trimmedPropertyValue = propertyValue.trimmingCharacters(in: .init(charactersIn: "\""))
fillExtrusionLayer.isVisible = trimmedPropertyValue == "visible"

default:
break
}
}
}

class func addRasterProperties(rasterLayer: MGLRasterStyleLayer, properties: [String: String]) {
for (propertyName, propertyValue) in properties {
let expression = interpretExpression(propertyName: propertyName, expression: propertyValue)
Expand Down
Loading

0 comments on commit 33969e9

Please sign in to comment.