Skip to content

Commit

Permalink
inital code gen
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-ht committed Nov 30, 2021
1 parent 323afd2 commit 29758f0
Show file tree
Hide file tree
Showing 14 changed files with 1,113 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,48 @@ static PropertyValue[] interpretFillLayerProperties(Object o) {
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();
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 "raster-opacity":
properties.add(PropertyFactory.rasterOpacity(expression));
break;
case "raster-hue-rotate":
properties.add(PropertyFactory.rasterHueRotate(expression));
break;
case "raster-brightness-min":
properties.add(PropertyFactory.rasterBrightnessMin(expression));
break;
case "raster-brightness-max":
properties.add(PropertyFactory.rasterBrightnessMax(expression));
break;
case "raster-saturation":
properties.add(PropertyFactory.rasterSaturation(expression));
break;
case "raster-contrast":
properties.add(PropertyFactory.rasterContrast(expression));
break;
case "raster-resampling":
properties.add(PropertyFactory.rasterResampling(expression));
break;
case "raster-fade-duration":
properties.add(PropertyFactory.rasterFadeDuration(expression));
break;
case "visibility":
properties.add(PropertyFactory.visibility(entry.getValue()));
break;
default:
break;
}
}

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

}
38 changes: 38 additions & 0 deletions ios/Classes/LayerPropertyConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,44 @@ class LayerPropertyConverter {
}
}

class func addRasterProperties(rasterLayer: MGLRasterStyleLayer, properties: [String: String]) {
for (propertyName, propertyValue) in properties {
let expression = interpretExpression(propertyName: propertyName, expression: propertyValue)
switch propertyName {
case "raster-opacity":
rasterLayer.rasterOpacity = expression;
break;
case "raster-hue-rotate":
rasterLayer.rasterHueRotation = expression;
break;
case "raster-brightness-min":
rasterLayer.rasterBrightnessMin = expression;
break;
case "raster-brightness-max":
rasterLayer.rasterBrightnessMax = expression;
break;
case "raster-saturation":
rasterLayer.rasterSaturation = expression;
break;
case "raster-contrast":
rasterLayer.rasterContrast = expression;
break;
case "raster-resampling":
rasterLayer.rasterResamplingMode = expression;
break;
case "raster-fade-duration":
rasterLayer.rasterFadeDuration = expression;
break;
case "visibility":
rasterLayer.isVisible = propertyValue == "visible";
break;

default:
break
}
}
}

private class func interpretExpression(propertyName: String, expression: String) -> NSExpression? {
let isColor = propertyName.contains("color");

Expand Down
8 changes: 8 additions & 0 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,14 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
addSource(sourceId: sourceId, geojson: geojson)
result(nil)

case "style#addSource":
guard let arguments = methodCall.arguments as? [String: Any] else { return }
guard let sourceId = arguments["sourceId"] as? String else { return }
guard let geojson = arguments["geojson"] as? String else { return }
addSource(sourceId: sourceId, geojson: geojson)
result(nil)


case "source#setGeoJson":
guard let arguments = methodCall.arguments as? [String: Any] else { return }
guard let sourceId = arguments["sourceId"] as? String else { return }
Expand Down
9 changes: 8 additions & 1 deletion lib/mapbox_gl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ export 'package:mapbox_gl_platform_interface/mapbox_gl_platform_interface.dart'
Line,
LineOptions,
Fill,
FillOptions;
FillOptions,
Source,
RasterSource,
VectorSource,
RasterDemSource,
GeojsonSource,
VideoSource,
ImageSource;

part 'src/controller.dart';
part 'src/mapbox_map.dart';
Expand Down
174 changes: 174 additions & 0 deletions lib/src/layer_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1750,3 +1750,177 @@ class FillLayerProperties implements LayerProperties {
);
}
}

class RasterLayerProperties implements LayerProperties {
// Paint Properties
/// The opacity at which the image will be drawn.
///
/// Type: number
/// default: 1
/// minimum: 0
/// maximum: 1
///
/// Sdk Support:
/// basic functionality with js, android, ios, macos
final dynamic rasterOpacity;

/// Rotates hues around the color wheel.
///
/// Type: number
/// default: 0
///
/// Sdk Support:
/// basic functionality with js, android, ios, macos
final dynamic rasterHueRotate;

/// Increase or reduce the brightness of the image. The value is the
/// minimum brightness.
///
/// Type: number
/// default: 0
/// minimum: 0
/// maximum: 1
///
/// Sdk Support:
/// basic functionality with js, android, ios, macos
final dynamic rasterBrightnessMin;

/// Increase or reduce the brightness of the image. The value is the
/// maximum brightness.
///
/// Type: number
/// default: 1
/// minimum: 0
/// maximum: 1
///
/// Sdk Support:
/// basic functionality with js, android, ios, macos
final dynamic rasterBrightnessMax;

/// Increase or reduce the saturation of the image.
///
/// Type: number
/// default: 0
/// minimum: -1
/// maximum: 1
///
/// Sdk Support:
/// basic functionality with js, android, ios, macos
final dynamic rasterSaturation;

/// Increase or reduce the contrast of the image.
///
/// Type: number
/// default: 0
/// minimum: -1
/// maximum: 1
///
/// Sdk Support:
/// basic functionality with js, android, ios, macos
final dynamic rasterContrast;

/// The resampling/interpolation method to use for overscaling, also known
/// as texture magnification filter
///
/// Type: enum
/// default: linear
/// Options:
/// "linear"
/// (Bi)linear filtering interpolates pixel values using the weighted
/// average of the four closest original source pixels creating a
/// smooth but blurry look when overscaled
/// "nearest"
/// Nearest neighbor filtering interpolates pixel values using the
/// nearest original source pixel creating a sharp but pixelated look
/// when overscaled
///
/// Sdk Support:
/// basic functionality with js, android, ios, macos
final dynamic rasterResampling;

/// Fade duration when a new tile is added.
///
/// Type: number
/// default: 300
/// minimum: 0
///
/// Sdk Support:
/// basic functionality with js, android, ios, macos
final dynamic rasterFadeDuration;

// Layout Properties
/// Whether this layer is displayed.
///
/// Type: enum
/// default: visible
/// Options:
/// "visible"
/// The layer is shown.
/// "none"
/// The layer is not shown.
///
/// Sdk Support:
/// basic functionality with js, android, ios, macos
final dynamic visibility;

const RasterLayerProperties({
this.rasterOpacity,
this.rasterHueRotate,
this.rasterBrightnessMin,
this.rasterBrightnessMax,
this.rasterSaturation,
this.rasterContrast,
this.rasterResampling,
this.rasterFadeDuration,
this.visibility,
});

RasterLayerProperties copyWith(RasterLayerProperties changes) {
return RasterLayerProperties(
rasterOpacity: changes.rasterOpacity ?? rasterOpacity,
rasterHueRotate: changes.rasterHueRotate ?? rasterHueRotate,
rasterBrightnessMin: changes.rasterBrightnessMin ?? rasterBrightnessMin,
rasterBrightnessMax: changes.rasterBrightnessMax ?? rasterBrightnessMax,
rasterSaturation: changes.rasterSaturation ?? rasterSaturation,
rasterContrast: changes.rasterContrast ?? rasterContrast,
rasterResampling: changes.rasterResampling ?? rasterResampling,
rasterFadeDuration: changes.rasterFadeDuration ?? rasterFadeDuration,
visibility: changes.visibility ?? visibility,
);
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> json = <String, dynamic>{};

void addIfPresent(String fieldName, dynamic value) {
if (value != null) {
json[fieldName] = value;
}
}

addIfPresent('raster-opacity', rasterOpacity);
addIfPresent('raster-hue-rotate', rasterHueRotate);
addIfPresent('raster-brightness-min', rasterBrightnessMin);
addIfPresent('raster-brightness-max', rasterBrightnessMax);
addIfPresent('raster-saturation', rasterSaturation);
addIfPresent('raster-contrast', rasterContrast);
addIfPresent('raster-resampling', rasterResampling);
addIfPresent('raster-fade-duration', rasterFadeDuration);
addIfPresent('visibility', visibility);
return json;
}

factory RasterLayerProperties.fromJson(Map<String, dynamic> json) {
return RasterLayerProperties(
rasterOpacity: json['raster-opacity'],
rasterHueRotate: json['raster-hue-rotate'],
rasterBrightnessMin: json['raster-brightness-min'],
rasterBrightnessMax: json['raster-brightness-max'],
rasterSaturation: json['raster-saturation'],
rasterContrast: json['raster-contrast'],
rasterResampling: json['raster-resampling'],
rasterFadeDuration: json['raster-fade-duration'],
visibility: json['visibility'],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ part 'src/symbol.dart';
part 'src/fill.dart';
part 'src/ui.dart';
part 'src/mapbox_gl_platform_interface.dart';
part 'src/sources.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -315,5 +315,7 @@ abstract class MapboxGlPlatform {
throw UnimplementedError('addFillLayer() has not been implemented.');
}

Future<void> addSource(String sourceId, Source source);

void dispose() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -803,4 +803,12 @@ class MethodChannelMapboxGl extends MapboxGlPlatform {
super.dispose();
_channel.setMethodCallHandler(null);
}

@override
Future<void> addSource(String sourceId, Source source) async {
await _channel.invokeMethod('source#add', <String, dynamic>{
'sourceId': sourceId,
'source': source.toJson(),
});
}
}
Loading

0 comments on commit 29758f0

Please sign in to comment.