Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when updating lines with a new color #448

Closed
antonovttm opened this issue Nov 2, 2020 · 9 comments
Closed

Bug when updating lines with a new color #448

antonovttm opened this issue Nov 2, 2020 · 9 comments
Labels

Comments

@antonovttm
Copy link

Hi there.

I believe this is a bug. When I create a line with addLine on my first state, everything works fine, but after I try to edit it with updateLine and try to give it a new color or even the same color, I get the following error and the map stops drawing lines:

E/Convert (28412): setLineOpacity0.5
E/Convert (28412): setLineColor#000000
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): Failed to handle method call
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): com.mapbox.mapboxsdk.exceptions.ConversionException: Not a valid rgb/rgba value
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at com.mapbox.mapboxsdk.utils.ColorUtils.rgbaToColor(ColorUtils.java:138)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at com.mapbox.mapboxgl.LineController.setLineColor(LineController.java:58)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at com.mapbox.mapboxgl.Convert.interpretLineOptions(Convert.java:470)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at com.mapbox.mapboxgl.MapboxMapController.onMethodCall(MapboxMapController.java:736)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
E/MethodChannel#plugins.flutter.io/mapbox_maps_0(28412): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:940)

@AAverin
Copy link
Contributor

AAverin commented Apr 23, 2021

This happens because https://github.com/tobrun/flutter-mapbox-gl/blob/9ee6d315b6154ad507cad6e20d7efb437feb8889/android/src/main/java/com/mapbox/mapboxgl/LineController.java#L61
LineController works different to LineBuilder and tries to parse color in a format of rgba(1,2,3,4) which doesn't match the initial Color that we pass into line

vberthet referenced this issue in MdnAgency/flutter-maplibre-gl Jul 7, 2021
vberthet referenced this issue in MdnAgency/flutter-maplibre-gl Oct 6, 2021
m0nac0 referenced this issue in maplibre/flutter-maplibre-gl Oct 14, 2021
* Fix bug when changing line color (see #448)

* Use Color.parseColor in LineController.setLineColor

Co-authored-by: Vincent Berthet <vincent@web-74.com>
@lomza
Copy link

lomza commented Nov 15, 2021

I have converted hex color string to rgba(r,g,b,a) one and it worked in 0.13.0 and in the last version of the library (0.14.0) it doesn't work anymore, with com.mapbox.mapboxsdk.exceptions.ConversionException: Not a valid rgb/rgba value error showing again. So, what is the correct format now?

@AAverin
Copy link
Contributor

AAverin commented Nov 16, 2021

@lomza I don't see any changes related to how colors work.
Both LineController in this repo and ColorUtils in original Android Mapbox SDK didn't change, you can see implementation here, maybe it will give you some ideas?

https://github.com/mapbox/mapbox-gl-native-android/blob/545884af52baa2d36f866a596741d5af7abdc9d5/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java#L126

@lomza
Copy link

lomza commented Nov 16, 2021

You're right, @AAverin , for Android I still need to provide rgba color string, doesn't matter if 0.13.0 or 0.14.0 version. They only changed line.setLineColor(ColorUtils.rgbaToColor(lineColor)); to line.setLineColor(Color.parseColor(lineColor));

FYI, for iOS hex is enough.

If somebody seeks a solution, this is my working code:

var color;
if (Platform.isAndroid) {
          color = ColorParser('#858AEE').toRgbaString();
        } else {
          color = '#858AEE';
        }
        await controller.updateLine(
          element,
          LineOptions(lineColor: color),
        );

I use ColorParser from fff library

@AAverin
Copy link
Contributor

AAverin commented Nov 17, 2021

@lomza
Copy link

lomza commented Nov 17, 2021

I though that this merge was done maplibre/flutter-maplibre-gl#15 , but seems it didn't.

@AAverin
Copy link
Contributor

AAverin commented Nov 17, 2021

@m0nac0 Should we bring that fix into main repo?

@m0nac0
Copy link
Collaborator

m0nac0 commented Nov 17, 2021

@vberthet Would you like to bring your fix over to this repo?

(Should be straightforward by cherry-picking)

AAverin added a commit to AAverin/flutter-mapbox-gl that referenced this issue Nov 18, 2021
…upport hex color strings for lines

Solves flutter-mapbox-gl#762 by interpreting and setting geometry on the line, allowing to programmatically move lines
tobrun pushed a commit that referenced this issue Nov 20, 2021
* Solves #448 by using Color.parseColor to correctly support hex color strings for lines
Solves #762 by interpreting and setting geometry on the line, allowing to programmatically move lines

* Remove unused import

* Unify geometry handling for line add, addAll and update

* Unify how geometry is handled for line add, addAll and update
@stale
Copy link

stale bot commented Jan 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 16, 2022
@AAverin AAverin closed this as completed Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants