Skip to content

Commit 2cbdce3

Browse files
committed
Fix color parsing in model_extension
1 parent e13c052 commit 2cbdce3

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

arcgis_map_sdk_method_channel/lib/src/model_extension.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ Map<String, Object?>? _colorToJson(Color? color) {
174174
if (color == null) return null;
175175

176176
return {
177-
'red': color.r,
178-
'green': color.g,
179-
'blue': color.b,
180-
'opacity': color.a / 255,
177+
'red': (color.r * 255).round(),
178+
'green': (color.g * 255).round(),
179+
'blue': (color.b * 255).round(),
180+
'opacity': color.a,
181181
};
182182
}
183183

arcgis_map_sdk_web/lib/src/model_extension.dart

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:ui';
2+
13
import 'package:arcgis_map_sdk_platform_interface/arcgis_map_sdk_platform_interface.dart';
24

35
extension AnimationOptionsJsonExtension on AnimationOptions {
@@ -103,7 +105,12 @@ extension on MeshSymbol3D {
103105
{
104106
'type': 'fill',
105107
'material': {
106-
'color': [color.r, color.g, color.b, colorOpacity],
108+
'color': [
109+
color.red255,
110+
color.green255,
111+
color.blue255,
112+
colorOpacity
113+
],
107114
},
108115
},
109116
],
@@ -113,13 +120,13 @@ extension on MeshSymbol3D {
113120
extension on SimpleMarkerSymbol {
114121
Map<String, dynamic> convertToJson() => <String, dynamic>{
115122
'type': 'simple-marker',
116-
'color': [color.r, color.g, color.b, colorOpacity],
123+
'color': [color.red255, color.green255, color.blue255, colorOpacity],
117124
'size': radius,
118125
'outline': <String, dynamic>{
119126
'color': [
120-
outlineColor.r,
121-
outlineColor.g,
122-
outlineColor.b,
127+
outlineColor.red255,
128+
outlineColor.green255,
129+
outlineColor.blue255,
123130
outlineColorOpacity,
124131
],
125132
'width': outlineWidth,
@@ -141,12 +148,17 @@ extension on PictureMarkerSymbol {
141148
extension on SimpleFillSymbol {
142149
Map<String, dynamic> convertToJson() => <String, dynamic>{
143150
'type': 'simple-fill',
144-
'color': [fillColor.r, fillColor.g, fillColor.b, opacity],
151+
'color': [
152+
fillColor.red255,
153+
fillColor.green255,
154+
fillColor.blue255,
155+
opacity
156+
],
145157
'outline': {
146158
'color': [
147-
outlineColor.r,
148-
outlineColor.g,
149-
outlineColor.b,
159+
outlineColor.red255,
160+
outlineColor.green255,
161+
outlineColor.blue255,
150162
], // White
151163
'width': outlineWidth,
152164
},
@@ -156,7 +168,7 @@ extension on SimpleFillSymbol {
156168
extension on SimpleLineSymbol {
157169
Map<String, dynamic> convertToJson() => <String, dynamic>{
158170
'cap': cap.value,
159-
'color': [color?.r, color?.g, color?.b, colorOpacity],
171+
'color': [color?.red255, color?.green255, color?.blue255, colorOpacity],
160172
'declaredClass': declaredClass,
161173
'join': join.value,
162174
'marker': marker?.convertToJson(),
@@ -169,7 +181,7 @@ extension on SimpleLineSymbol {
169181

170182
extension on LineSymbolMarker {
171183
Map<String, dynamic> convertToJson() => <String, dynamic>{
172-
'color': [color?.r, color?.g, color?.b, colorOpacity],
184+
'color': [color?.red255, color?.green255, color?.blue255, colorOpacity],
173185
'declaredClass': declaredClass,
174186
'placement': placement.value,
175187
'style': style.value,
@@ -238,4 +250,12 @@ extension GroundExt on Ground {
238250
String get value => values[this]!;
239251
}
240252

253+
extension ColorExt on Color {
254+
int get red255 => (r * 255).round();
255+
256+
int get blue255 => (b * 255).round();
257+
258+
int get green255 => (g * 255).round();
259+
}
260+
241261
// endregion

0 commit comments

Comments
 (0)