Mapbox-gl-js: Support gradient-colored shapes

Created on 1 Feb 2017  路  20Comments  路  Source: mapbox/mapbox-gl-js

_From @lucaswoj on August 21, 2015 19:8_

It would be useful to support gradient-colored lines, fills, and backgrounds. What would the stylesheet syntax look like? How would this work with data-driven styling?

ref https://github.com/mapbox/mapbox-gl-native/issues/2142

cc @webventil

_Copied from original issue: mapbox/mapbox-gl-style-spec#349_

cross-platform feature

Most helpful comment

Any progress?

All 20 comments

_From @jfirebaugh on August 21, 2015 19:14_

See also https://github.com/mapbox/mapbox-gl-js/issues/748.

_From @tmcw on August 21, 2015 19:14_

I think the style spec side here is totally doable but the hard part is going to be data representation: GeoJSON and lots of other formats are derived at a basic level from the Simple Features Spec, which, in its definition of 'simple' does not include the concept of values differing _along_ lines, which is how I'd assume you would want to control the color of the line.

The GPX and OSM formats do support this, and I have a proposal for an add-on spec for GeoJSON. Vector tiles, as far as I know, don't support values along lines.

_From @tomtaylor on August 24, 2015 12:58_

While this is being considered, it would also be useful to be able to have polylines where the dashing varies along the line too. So you can make certain sections as dotted, for example.

_From @jordi-adame on August 29, 2015 17:30_

+1

_From @cowgp on February 2, 2016 22:26_

+1

_From @isimonescu on September 7, 2016 11:0_

Any progress on this?

Any progress?

Any progress??

I think the style spec side here is totally doable but the hard part is going to be data representation: GeoJSON and lots of other formats are derived at a basic level from the Simple Features Spec, which, in its definition of 'simple' does not include the concept of values differing along lines, which is how I'd assume you would want to control the color of the line.

The GPX and OSM formats do support this, and I have a proposal for an add-on spec for GeoJSON. Vector tiles, as far as I know, don't support values along lines.

I wonder if using Turf's LineSegment or something like that based on your values along the line, and assigning each segment a start/end value would suffice, seems much easier than getting proper support for linear referenced feature properties into MVT?

@espy1122 Have you tried segmenting http://turfjs.org/docs/#linesegment the line and using data driven styles for an approximation of a smooth gradient? I know this is a poor workaround of this issue, but would be worth trying. I wonder if you can segment enough that it appears to be a smooth gradient without much performance impact...

https://github.com/mapbox/vector-tile-spec/issues/93 is related to this, as it could unlock data driven styling where the style value is evaluated per node along the LineString instead of per feature, with an interpolation between nodes in the LineString.

One potential use case could be a line-offset which varies along the line for doing transit network maps.

@andrewharvey I like this idea. The GeoJSON spec for a LineString (and any GeoJSON feature in general) supports an abstract properties object. It already seems like much of mapbox supports styling via templating ({icon}-15) based upon values stored in the properties object, perhaps this could also follow that pattern.

Example design pattern (based upon the same way heatmaps have already been done:
1.) Define color stops on the gradient
2.) Store some colorValue property (can be custom) in the properties object for each node in the LineString. This value should be normalized between 0 and 1.
3.) Create a LineString with the following paint option:

"colorGradient": {
  "property": "colorValue",
  "type": "interpolate",
  "stops": [
    [ 0, #248216 ],
    [ 0.5, #843099 ],
    [ 1, #9e243a ]
  ]
}

2.) Store some colorValue property (can be custom) in the properties object for each node in the LineString.

@kylehovey I think the problem is that the GeoJSON spec doesn't support assigning properties for each vertex of the LineString. There is https://github.com/mapbox/geojson-coordinate-properties but isn't not standardised and it probably needs https://github.com/mapbox/vector-tile-spec/issues/75 addressed to work in GL JS

@andrewharvey Isn't this sort of functionality already supported in the Heatmap specification? That feature in the gl-JS API utilizes a mag value in the properties object of each feature in the feature collection of the data source. I know that a FeatureMap is not a LineString, but it seems to be an equivalent use case/relaxation of strict GeoJSON formatting.

@lbud should we close this now #6303 is merged?

馃 I'm inclined to leave it open as a placeholder ticket for other shapes (OP also mentions gradient fills and backgrounds) 鈥斅爐hese are not under active development or prioritized at all but could feasibly be useful to people.

mapbox/mapbox-gl-native#11718 tracks porting #6303 to the native SDKs.

馃憤

Is this going to be available on Mapbox GL JS?

Please provide linesofar as absolute distance instead of percentage so we can create custom shaders or provide the total length of the line to the shader. See #3883

@kaligrafy Support for gradient colored lines was implemented in https://github.com/mapbox/mapbox-gl-js/pull/6303, and is now available with GeoJSON data sources.

It looks like linesofar does use high prevision floats in the line shader now:
https://github.com/mapbox/mapbox-gl-js/blob/b0a37a059af486e3577fad432904bc1341b17f58/src/shaders/line.vertex.glsl#L20

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aderaaij picture aderaaij  路  3Comments

foundryspatial-duncan picture foundryspatial-duncan  路  3Comments

bgentry picture bgentry  路  3Comments

samanpwbb picture samanpwbb  路  3Comments

aendrew picture aendrew  路  3Comments