Skip to content

polyline with gradient#452

Merged
johnpryan merged 4 commits into
fleaflet:masterfrom
SebWojd:polyline_gradient
Jan 7, 2020
Merged

polyline with gradient#452
johnpryan merged 4 commits into
fleaflet:masterfrom
SebWojd:polyline_gradient

Conversation

@SebWojd

@SebWojd SebWojd commented Oct 21, 2019

Copy link
Copy Markdown
Contributor

Add possibility to create polyline with gradient color.

closes #486

..strokeJoin = StrokeJoin.round
..blendMode = BlendMode.src;

if (polylineOpt.gradientColors == null) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to also handle the isEmpty case

@johnpryan johnpryan merged commit f2377e2 into fleaflet:master Jan 7, 2020
ziuyung pushed a commit to SXTSOFT/flutter_map that referenced this pull request Mar 27, 2020
* master: (73 commits)
  去掉不要的
  Update CHANGELOG.md (fleaflet#511)
  Proj4dart update (fleaflet#541)
  Support custom CRS (fleaflet#529)
  docs(readme): add details about open street map provider (fleaflet#495)
  Wms support. (fleaflet#500)
  0.8.2 release
  polyline with gradient (fleaflet#452)
  clean up from fleaflet#487
  0.8.1 release
  Zoombutton plugin (fleaflet#487)
  dartfmt
  0.8.0 release (Flutter 1.12)
  Use Wrap for marker_anchor sample
  Polygon culling (fleaflet#449)
  Tidyup (fleaflet#469)
  Update build files from fleaflet#478
  upgrade flutter version, support Flutter 1.12
  Update README.md (fleaflet#465)
  add opacity option to tile layers (fleaflet#453)
  ...

# Conflicts:
#	example/android/app/build.gradle
#	example/android/app/src/debug/AndroidManifest.xml
#	example/android/app/src/main/AndroidManifest.xml
#	example/android/app/src/profile/AndroidManifest.xml
#	example/android/build.gradle
#	example/android/gradle.properties
#	example/ios/Runner.xcodeproj/project.pbxproj
#	example/lib/pages/home.dart
#	example/web/index.html
#	lib/flutter_map.dart
#	lib/src/geo/crs/crs.dart
#	lib/src/layer/overlay_image_layer.dart
#	lib/src/layer/tile_layer.dart
#	lib/src/layer/tile_provider/mbtiles_image_provider.dart
#	lib/src/map/flutter_map_state.dart
#	pubspec.yaml
@filipevl

Copy link
Copy Markdown

@SebWojd Does this pr support using a gradient of only two colors over the whole line, instead of defining a color for every point? What does stop colors do? It is undocumented and not used in the example.

@SebWojd

SebWojd commented Jun 21, 2020

Copy link
Copy Markdown
Contributor Author

@FilipeLarga This feature support as many colors as you wish. You have to play with gradientColors and colorsStop. I implemented here the standard way how Dart use linear gradient.

Here you have a snippet:

PolylineLayerOptions(
                    polylines: [
                      Polyline(
                        points: pointsGradient,
                        strokeWidth: 4.0,
                        gradientColors: [
                          Color(0xffE40203),
                          Color(0xffFEED00),
                          Color(0xff007E2D),
                          Color(0xff0000FF),
                        ],
                        colorsStop: [
                          0.1,
                          0.3,
                          0.5,
                          0.95,
                        ],
                      ),
                    ],
                  ),

and the result is:

Zrzut ekranu 2020-06-21 o 13 08 18

@moovida

moovida commented Nov 10, 2020

Copy link
Copy Markdown
Contributor

Hi @SebWojd , sorry for resurrecting this here. I have an issue I am describing on issue #772
Is it possible that this works properly only for straight lines? Or is it supposed to work also for complex polylines?

@Vincent7140

Copy link
Copy Markdown

Hi @moovida , sorry for resurrecting this here. I have the same issue you had describing on issue #772

Did you manage to correct the issue since then ? thank you

@PooruTorie

Copy link
Copy Markdown

Hi, i have the same error like in #772
In a line with more than 5 points

@Jamesm-98

Copy link
Copy Markdown

I'm also facing a similar issue here - suffering from the gradient being referenced to a straight line from first to last points. This makes colouring polylines by arbitrary variable difficult/innacurate when the polyline is not a straight line (or close to one). If the polyline curves back towards the first point it's colour goes "backwards" up the colour gradient.

@Vincent7140

Copy link
Copy Markdown

Hi, I've done this a while ago and I have never coded in dart again but looking into my code it seems I had replace this :

gradientColors: _generateGradientColors(colors),

by this :

  List<Color> gradient = _generateGradientColors(colors);
  List<dynamic> result = _generateColorStops(gradient);
  List<Color> newColors = result[0];
  List<double> colorStops = result[1];

and then this :

return Polyline(
points: points,
strokeWidth: 6,
gradientColors: _generateGradientColors(colors),
);
}).toList();

by this

return Polyline(
points: points,
strokeWidth: 6,
gradientColors: newColors,
colorsStop : colorStops,
);
}).toList();

Maybe it will help good luck !

@JaffaKetchup

Copy link
Copy Markdown
Member

From what I can tell, only workarounds of splitting up the line into smaller lines will work. Maybe a shader could work but I don't think so with the basic shader support Flutter has (it would need flutter_gpu).

I've looked into this quite a bit, and actually it doesn't seem to be implemented in many places except in editing software. Even on the web it's not possible. See for example https://github.com/cereallarceny/gradient-path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does this package support gradient lines for polygons

8 participants