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

Add color gradient support to polygon in google_maps_flutter #47232

Open
abhijithvijayan opened this issue Dec 17, 2019 · 12 comments
Open

Add color gradient support to polygon in google_maps_flutter #47232

abhijithvijayan opened this issue Dec 17, 2019 · 12 comments
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter p: maps Google Maps plugin P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team

Comments

@abhijithvijayan
Copy link

Use case

Gradient Support?

I was thinking of this between 3 points A, B & C

From A(Red) to B(green) to C(blue)

Screenshot from 2019-12-17 22-21-07
Screenshot from 2019-12-17 22-23-58

Proposal

If the polygon function could take colors as prop, it would be better isn't it?

Like the support in react-native-maps/react-native-maps#1911 ?

@iapicca iapicca added p: first party p: maps Google Maps plugin c: proposal A detailed proposal for a change to Flutter c: new feature Nothing broken; request for a new capability labels Dec 18, 2019
@timsneath timsneath added this to the Future milestone Jan 3, 2020
@timsneath timsneath changed the title [Feature_request] Color Gradient lines for Polygon in google_maps_flutter package Add color gradient support to polygon in google_maps_flutter Jan 3, 2020
@abhijithvijayan
Copy link
Author

abhijithvijayan commented Feb 27, 2020

I have to revert back to using React-Native as my app primarily depend on this feature and has to be in production soon.

Will this feature implemented anytime soon?

Another package called flutter_maps implements this feature as requested in fleaflet/flutter_map#452 .

Is there some way to implement that PR to this package as well?

@iapicca @timsneath

@kf6gpe kf6gpe added the P6 label May 29, 2020
@kf6gpe kf6gpe removed this from the Future milestone Jun 1, 2020
@fvisticot
Copy link

Any news on this important feature ? Any app using map to display sport or driving data need this feature. I really would like to use google_maps_flutter instead of moving to flutter_map

@sc-ot
Copy link

sc-ot commented Jun 11, 2021

Any updates on this? I couldn't find any working example. It would be really nice if someone can link me some example projects or code snippets.

@renanborgez
Copy link

@sc-ot for a temporary solution check what I've done:

I approached this problem by drawing various small elements with differents colors based on the position of each.
Then I used a dart library to generate the gradient colors for me and I applied those colors to each shape.

The drawback of this approach is that I'm creating quite a lot of elements in the map and the initial rendering is slow, but in this way I can have the end result as I wanted as this is not yet supported in google maps library.

(you can increase the performance by reducing the amount of elements to render the fake gradient, then your gradient will automatically have a lower "resolution")

Bellow you can check the result of this in my application:

image

@AliEasy
Copy link

AliEasy commented Aug 23, 2021

@renanborgez could you share the code?

@renanborgez
Copy link

renanborgez commented Aug 23, 2021

@AliEasy

I am basically making use of the polygons feature, I am calculating the polygon based on the shape that I want. I can not just place my plain code here due some privacy restrictions that I have, however I can show you the approach until the part where you have to draw your own polygons.

// I am generating a list of colors based on the amount of polygons that I want to draw
// 'Softer' you want your gradient, more colors you have to generate
// I am using the following library to generate all colors for me
// https://pub.dev/packages/kandinsky
List<Color> getPalette(int colorsInBetween) {

  var colors = multiGradient(colorsInBetween, [
    getRGBArrayFromColor(Colors.blue[100]),
    getRGBArrayFromColor(Colors.blue[900]),
  ]);
  
  // You have to return a list of Material Colors as it is used by Google Maps library
  return colors.map((List<num> color) => 
      Color.fromRGBO( color[0].round(), color[1].round(), color[2].round(), 1)
  ).toList();
}

var polygons = <Polygon>[];
var colors = getPalette();

// Then you have to create a loop for your polygons
polygons.add(Polygon(
  fillColor: colors[i]
  visible: true,
  strokeWidth: 0,
  points: [...previousPoints, ...nextPoints], // The magic goes here, you have to draw your polygon next to the previous polygon
))

// If I'm not mistaken, points is a list of `LatLng`s

// And finally you pass your polygons to google maps
GoogleMap(polygons: polygons)

If you draw rectangles you should have something like this:
image

Remember that each color is a separate polygon, this is why I mentioned above that softer you want your gradient more polygons you will have to create and as consequence your component might get slower to be loaded (but that wasn't an issue for me with that level of color granularity)

I used the following lib to generate my gradient
https://pub.dev/packages/kandinsky

@SriRam-Macha
Copy link

Any updates on this feature?

@1cedsoda
Copy link

It has been nearly 3 years... Can't be that hard

@ElMehdijebbour
Copy link

ElMehdijebbour commented Oct 11, 2022

It is really an important feature why is it taking too long?

@renanzdm
Copy link

renanzdm commented Jan 3, 2023

Did anyone get over this? I'm using the above approach but the map is extremely heavy

@mahirozdin
Copy link

mahirozdin commented Feb 22, 2023

any updates?

@phobosbag
Copy link

will there be an update?

@flutter-triage-bot flutter-triage-bot bot added P3 Issues that are less important to the Flutter project and removed P6 labels Jun 28, 2023
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
@Hixie Hixie removed the plugin label Jul 6, 2023
@flutter-triage-bot flutter-triage-bot bot added team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter p: maps Google Maps plugin P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team
Projects
None yet
Development

No branches or pull requests