diff --git a/lib/src/annotation.dart b/lib/src/annotation.dart index 33dfd2d40..7abc5d276 100644 --- a/lib/src/annotation.dart +++ b/lib/src/annotation.dart @@ -87,3 +87,64 @@ class LineManager extends _AnnotationManager { lineBlur: [Expressions.get, 'lineBlur'], ); } + +class FillManager extends _AnnotationManager { + 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 { + 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 { + 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'], + ); +} diff --git a/mapbox_gl_platform_interface/lib/src/annotation.dart b/mapbox_gl_platform_interface/lib/src/annotation.dart index 9f2d4d614..99c2c5c76 100644 --- a/mapbox_gl_platform_interface/lib/src/annotation.dart +++ b/mapbox_gl_platform_interface/lib/src/annotation.dart @@ -5,5 +5,4 @@ abstract class Annotation { Map toGeoJson(); Annotation translate(LatLng delta); - bool get draggable; } diff --git a/mapbox_gl_platform_interface/lib/src/circle.dart b/mapbox_gl_platform_interface/lib/src/circle.dart index a75a0217e..47fc71755 100644 --- a/mapbox_gl_platform_interface/lib/src/circle.dart +++ b/mapbox_gl_platform_interface/lib/src/circle.dart @@ -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. @@ -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 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. @@ -73,7 +98,7 @@ class CircleOptions { ); } - dynamic toJson() { + dynamic toJson([bool addGeometry = true]) { final Map json = {}; void addIfPresent(String fieldName, dynamic value) { @@ -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 toGeoJson() { + return { + "type": "Feature", + "properties": toJson(false), + "geometry": { + "type": "LineString", + if (geometry != null) "coordinates": geometry!.toJson() + } + }; + } } diff --git a/mapbox_gl_platform_interface/lib/src/fill.dart b/mapbox_gl_platform_interface/lib/src/fill.dart index 15c966551..15570e790 100644 --- a/mapbox_gl_platform_interface/lib/src/fill.dart +++ b/mapbox_gl_platform_interface/lib/src/fill.dart @@ -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. @@ -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 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. @@ -78,7 +104,7 @@ class FillOptions { ); } - dynamic toJson() { + dynamic toJson([bool addGeometry = true]) { final Map json = {}; void addIfPresent(String fieldName, dynamic value) { @@ -91,13 +117,30 @@ class FillOptions { addIfPresent('fillColor', fillColor); addIfPresent('fillOutlineColor', fillOutlineColor); addIfPresent('fillPattern', fillPattern); - addIfPresent( - 'geometry', - geometry - ?.map((List latLngList) => - latLngList.map((LatLng latLng) => latLng.toJson()).toList()) - .toList()); + if (addGeometry) { + addIfPresent( + 'geometry', + geometry + ?.map((List latLngList) => + latLngList.map((LatLng latLng) => latLng.toJson()).toList()) + .toList()); + } addIfPresent('draggable', draggable); return json; } + + Map toGeoJson() { + return { + "type": "Feature", + "properties": toJson(false), + "geometry": { + "type": "LineString", + if (geometry != null) + "coordinates": geometry + ?.map((List latLngList) => + latLngList.map((LatLng latLng) => latLng.toJson()).toList()) + .toList() + } + }; + } } diff --git a/mapbox_gl_platform_interface/lib/src/line.dart b/mapbox_gl_platform_interface/lib/src/line.dart index 583ed79f3..958e286cc 100644 --- a/mapbox_gl_platform_interface/lib/src/line.dart +++ b/mapbox_gl_platform_interface/lib/src/line.dart @@ -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. @@ -104,7 +101,7 @@ class LineOptions { ); } - dynamic toJson() { + dynamic toJson([bool addGeometry = true]) { final Map json = {}; void addIfPresent(String fieldName, dynamic value) { @@ -121,8 +118,10 @@ 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; } @@ -130,17 +129,7 @@ class LineOptions { Map 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)