Skip to content

Commit

Permalink
added other annotation managers
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-ht committed Dec 16, 2021
1 parent 1b34a12 commit c50d89c
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 29 deletions.
61 changes: 61 additions & 0 deletions lib/src/annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,64 @@ class LineManager extends _AnnotationManager<Line> {
lineBlur: [Expressions.get, 'lineBlur'],
);
}

class FillManager extends _AnnotationManager<Fill> {
FillManager(MapboxMapController controller, {void Function(Fill)? onTap})
: super(controller, onTap: onTap);
@override
LayerProperties get properties => const FillLayerProperties(
fillOpacity: [Expressions.get, 'fillOpacity'],
fillColor: [Expressions.get, 'fillColor'],
fillOutlineColor: [Expressions.get, 'fillOutlineColor'],
fillPattern: [Expressions.get, 'fillPattern'],
);
}

class CircleManager extends _AnnotationManager<Circle> {
CircleManager(MapboxMapController controller, {void Function(Circle)? onTap})
: super(controller, onTap: onTap);
@override
LayerProperties get properties => const CircleLayerProperties(
circleRadius: [Expressions.get, 'circleRadius'],
circleColor: [Expressions.get, 'circleColor'],
circleBlur: [Expressions.get, 'circleBlur'],
circleOpacity: [Expressions.get, 'circleOpacity'],
circleStrokeWidth: [Expressions.get, 'circleStrokeWidth'],
circleStrokeColor: [Expressions.get, 'circleStrokeColor'],
circleStrokeOpacity: [Expressions.get, 'circleStrokeOpacity'],
);
}

class SymbolManager extends _AnnotationManager<Symbol> {
SymbolManager(MapboxMapController controller, {void Function(Symbol)? onTap})
: super(controller, onTap: onTap);
@override
LayerProperties get properties => const SymbolLayerProperties(
iconSize: [Expressions.get, 'iconSize'],
iconImage: [Expressions.get, 'iconImage'],
iconRotate: [Expressions.get, 'iconRotate'],
iconOffset: [Expressions.get, 'iconOffset'],
iconAnchor: [Expressions.get, 'iconAnchor'],
textFont: [Expressions.get, 'fontNames'],
textField: [Expressions.get, 'textField'],
textSize: [Expressions.get, 'textSize'],
textMaxWidth: [Expressions.get, 'textMaxWidth'],
textLetterSpacing: [Expressions.get, 'textLetterSpacing'],
textJustify: [Expressions.get, 'textJustify'],
textAnchor: [Expressions.get, 'textAnchor'],
textRotate: [Expressions.get, 'textRotate'],
textTransform: [Expressions.get, 'textTransform'],
textOffset: [Expressions.get, 'textOffset'],
iconOpacity: [Expressions.get, 'iconOpacity'],
iconColor: [Expressions.get, 'iconColor'],
iconHaloColor: [Expressions.get, 'iconHaloColor'],
iconHaloWidth: [Expressions.get, 'iconHaloWidth'],
iconHaloBlur: [Expressions.get, 'iconHaloBlur'],
textOpacity: [Expressions.get, 'textOpacity'],
textColor: [Expressions.get, 'textColor'],
textHaloColor: [Expressions.get, 'textHaloColor'],
textHaloWidth: [Expressions.get, 'textHaloWidth'],
textHaloBlur: [Expressions.get, 'textHaloBlur'],
symbolZOrder: [Expressions.get, 'zIndex'],
);
}
1 change: 0 additions & 1 deletion mapbox_gl_platform_interface/lib/src/annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ abstract class Annotation {
Map<String, dynamic> toGeoJson();

Annotation translate(LatLng delta);
bool get draggable;
}
44 changes: 41 additions & 3 deletions mapbox_gl_platform_interface/lib/src/circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

part of mapbox_gl_platform_interface;

class Circle {
class Circle implements Annotation {
Circle(this._id, this.options, [this._data]);

/// A unique identifier for this circle.
Expand All @@ -24,6 +24,31 @@ class Circle {
/// The returned value does not reflect any changes made to the circle through
/// touch events. Add listeners to the owning map controller to track those.
CircleOptions options;

Circle copyWith({String? id, Map? data, CircleOptions? options}) {
return Circle(
id ?? this.id,
options ?? this.options,
data ?? this.data,
);
}

@override
Map<String, dynamic> toGeoJson() {
final geojson = options.toGeoJson();
geojson["id"] = id;
geojson["properties"]["id"] = id;

return geojson;
}

@override
Annotation translate(LatLng delta) {
final options = this
.options
.copyWith(CircleOptions(geometry: this.options.geometry! + delta));
return copyWith(options: options);
}
}

/// Configuration options for [Circle] instances.
Expand Down Expand Up @@ -73,7 +98,7 @@ class CircleOptions {
);
}

dynamic toJson() {
dynamic toJson([bool addGeometry = true]) {
final Map<String, dynamic> json = <String, dynamic>{};

void addIfPresent(String fieldName, dynamic value) {
Expand All @@ -89,8 +114,21 @@ class CircleOptions {
addIfPresent('circleStrokeWidth', circleStrokeWidth);
addIfPresent('circleStrokeColor', circleStrokeColor);
addIfPresent('circleStrokeOpacity', circleStrokeOpacity);
addIfPresent('geometry', geometry?.toJson());
if (addGeometry) {
addIfPresent('geometry', geometry?.toJson());
}
addIfPresent('draggable', draggable);
return json;
}

Map<String, dynamic> toGeoJson() {
return {
"type": "Feature",
"properties": toJson(false),
"geometry": {
"type": "LineString",
if (geometry != null) "coordinates": geometry!.toJson()
}
};
}
}
59 changes: 51 additions & 8 deletions mapbox_gl_platform_interface/lib/src/fill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ FillOptions translateFillOptions(FillOptions options, LatLng delta) {
return options;
}

class Fill {
class Fill implements Annotation {
Fill(this._id, this.options, [this._data]);

/// A unique identifier for this fill.
Expand All @@ -39,6 +39,32 @@ class Fill {
/// The returned value does not reflect any changes made to the fill through
/// touch events. Add listeners to the owning map controller to track those.
FillOptions options;

Fill copyWith({String? id, Map? data, FillOptions? options}) {
return Fill(
id ?? this.id,
options ?? this.options,
data ?? this.data,
);
}

@override
// TODO: implement draggable
bool get draggable => throw UnimplementedError();

@override
Map<String, dynamic> toGeoJson() {
final geojson = options.toGeoJson();
geojson["id"] = id;
geojson["properties"]["id"] = id;

return geojson;
}

@override
Annotation translate(LatLng delta) {
return copyWith(options: translateFillOptions(options, delta));
}
}

/// Configuration options for [Fill] instances.
Expand Down Expand Up @@ -78,7 +104,7 @@ class FillOptions {
);
}

dynamic toJson() {
dynamic toJson([bool addGeometry = true]) {
final Map<String, dynamic> json = <String, dynamic>{};

void addIfPresent(String fieldName, dynamic value) {
Expand All @@ -91,13 +117,30 @@ class FillOptions {
addIfPresent('fillColor', fillColor);
addIfPresent('fillOutlineColor', fillOutlineColor);
addIfPresent('fillPattern', fillPattern);
addIfPresent(
'geometry',
geometry
?.map((List<LatLng> latLngList) =>
latLngList.map((LatLng latLng) => latLng.toJson()).toList())
.toList());
if (addGeometry) {
addIfPresent(
'geometry',
geometry
?.map((List<LatLng> latLngList) =>
latLngList.map((LatLng latLng) => latLng.toJson()).toList())
.toList());
}
addIfPresent('draggable', draggable);
return json;
}

Map<String, dynamic> toGeoJson() {
return {
"type": "Feature",
"properties": toJson(false),
"geometry": {
"type": "LineString",
if (geometry != null)
"coordinates": geometry
?.map((List<LatLng> latLngList) =>
latLngList.map((LatLng latLng) => latLng.toJson()).toList())
.toList()
}
};
}
}
23 changes: 6 additions & 17 deletions mapbox_gl_platform_interface/lib/src/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ class Line implements Annotation {
geometry: this.options.geometry?.map((e) => e + delta).toList()));
return copyWith(options: options);
}

@override
bool get draggable => options.draggable ?? false;
}

/// Configuration options for [Line] instances.
Expand Down Expand Up @@ -104,7 +101,7 @@ class LineOptions {
);
}

dynamic toJson() {
dynamic toJson([bool addGeometry = true]) {
final Map<String, dynamic> json = <String, dynamic>{};

void addIfPresent(String fieldName, dynamic value) {
Expand All @@ -121,26 +118,18 @@ class LineOptions {
addIfPresent('lineOffset', lineOffset);
addIfPresent('lineBlur', lineBlur);
addIfPresent('linePattern', linePattern);
addIfPresent(
'geometry', geometry?.map((LatLng latLng) => latLng.toJson()).toList());
if (addGeometry) {
addIfPresent('geometry',
geometry?.map((LatLng latLng) => latLng.toJson()).toList());
}
addIfPresent('draggable', draggable);
return json;
}

Map<String, dynamic> toGeoJson() {
return {
"type": "Feature",
"properties": {
if (lineJoin != null) "lineJoin": lineJoin,
if (lineOpacity != null) "lineOpacity": lineOpacity,
if (lineColor != null) "lineColor": lineColor,
if (lineWidth != null) "lineWidth": lineWidth,
if (lineGapWidth != null) "lineGapWidth": lineGapWidth,
if (lineOffset != null) "lineOffset": lineOffset,
if (lineBlur != null) "lineBlur": lineBlur,
if (linePattern != null) "linePattern": linePattern,
"draggable": draggable ?? false,
},
"properties": toJson(false),
"geometry": {
"type": "LineString",
if (geometry != null)
Expand Down

0 comments on commit c50d89c

Please sign in to comment.