ol-mapbox-style icon indicating copy to clipboard operation
ol-mapbox-style copied to clipboard

line-offset not supported

Open pakb opened this issue 7 years ago • 10 comments

As seen in this codepen : https://codepen.io/pakb/full/KErzNo

The style says highway features should have some offset so the two lanes don't merge :

  {
      "id": "roadtraffic_highway",
      ...
      "paint": {
        "line-offset": {
          "base": 1.99,
          "stops": [[ 12, 1 ], [ 15, 5 ], [ 17, 9 ], [ 18, 13 ], [ 20, 10 ]]
        }
      }
    },

pakb avatar Mar 21 '19 13:03 pakb

This can be solved by giving the styles for the line an offset geometry (using the ol/Style's geometry option). The interesting part is how to create the offset geometry. There is a turf package (https://www.npmjs.com/package/@turf/line-offset) which could be used to start with.

For good performance something custom without going through GeoJSON and units conversion would be better.

I'd say starting with turf is fine, we'd only have to keep an eye on package size.

@pakb, would this be something you'd be able and willing to work on?

ahocevar avatar Mar 21 '19 16:03 ahocevar

You mean by setting a geometry to a ol/Style, that would act like a drawing zone where other styles would't write?

pakb avatar Mar 22 '19 06:03 pakb

The geometry option of ol/style/Style allows you to render a geometry different from the geometry of the feature.

ahocevar avatar Mar 22 '19 07:03 ahocevar

The geometry option of ol/style/Style allows you to render a geometry different from the geometry of the feature.

ol-mapbox-style makes use of this feature already for rendering the midpoint of a polygon. That, by the way, does not give nice results because polygons are cut into tiles, and the midpoints will be per tile.

One other thought: rendering highways with line-offset is not a very good idea, because it puts a lot of work on the client (i.e. calculating a new geometry for every rendered resolution). Performance wise, it would be better to have the offset lane geometries in the tiles already, like it is the case with OpenStreetMap data.

ahocevar avatar Mar 22 '19 07:03 ahocevar

I wouldn't be against an optimisation on the data instead of at rendering. This is a NTH feature IMHO, and maybe I should look with the team generating our data to do that straight into the tiles as you said. I'll get in touch with @danduk82 on Monday and let you know what we decide on this.

pakb avatar Mar 22 '19 07:03 pakb

Hi, just stopping by to suggest adding an offset option in the OL style classes, as it would probably be quite simple to apply it right before drawing the features instead of manipulating the source geometry.

There is already an offset option on the Text and Icon styles, the main issue I see is that the one on the Icon style does not have the same meaning. Nothing infeasible though!

If it sounds good I can probably tackle it this week or the next.

jahow avatar Mar 25 '19 13:03 jahow

@jahow line-offset means that a different geometry needs to be rendered. See https://docs.mapbox.com/mapbox-gl-js/style-spec/#paint-line-line-offset.

Also note that the geometry property on ol/style/Style does not manipulate the source geometry, it just is a way to provide a geometry for rendering that is different from the source geometry.

ahocevar avatar Mar 25 '19 14:03 ahocevar

@jahow But I do see the benefit of having such an offset option for lines and polygons in OpenLayers, on the geom and geom/flat level. Style API wise, I'm not sure where this option should go. Can you please create an OpenLayers issue, so we can continue the discussion there?

ahocevar avatar Mar 25 '19 14:03 ahocevar

Done: https://github.com/openlayers/openlayers/issues/9377

jahow avatar Mar 25 '19 14:03 jahow

Our data holder will not accept to modify its data to accommodate for this feature. From our point of view, we should seek to resolve this with what is proposed in the issue https://github.com/openlayers/openlayers/issues/9377

pakb avatar Apr 15 '19 08:04 pakb