mapbox / mapbox-gl-js

Interactive, thoroughly customizable maps in the browser, powered by vector tiles and WebGL
https://docs.mapbox.com/mapbox-gl-js/
Other
11.06k stars 2.21k forks source link

fill-extrusion-flat-ceilings style spec property #10355

Open andrewharvey opened 3 years ago

andrewharvey commented 3 years ago

Motivation

When using fill-extrusions on a map with terrain enabled, since #10347 the extrusion ceiling will be flat. This is good for buildings, but per https://github.com/mapbox/mapbox-gl-js/issues/10170#issuecomment-770496123 sometimes you might want these extrusions to follow the terrain.

One example is for vegetation extrusions to show forest areas of a fixed height above the terrain.

Design Alternatives

The user could split the polygons but they still would be flat, just stepped. A smoother extrusion which follows the terrain could only be achieved my unlocking it with a style spec property.

Design

Using a style spec property which defaults to flat allows backwards compatibility, but still supporting curved extrusion ceilings.

It's fine if this is not something you're keen on implementing, but thought I'd raise this ticket for further discussion since the existing ones were closed out.

astojilj commented 3 years ago

@karimnaaji started work on scoping the mechanism.

@andrewharvey ,

One example is for vegetation extrusions to show forest areas of a fixed height above the terrain.

Do you see that it would be beneficial to style it differently? E.g.

cc @karimnaaji @asheemmamoowala

andrewharvey commented 3 years ago

Do you see that it would be beneficial to style it differently?

For the vegetation use case, I don't think that's too important.

karimnaaji commented 3 years ago

Some other interesting use cases for such a property: https://cameronwkruse.com/home/projects/glacslide/.

Some considerations to properly support the non-flat case:

andrewharvey commented 3 years ago

Another use case for non-flat ceilings of extrusions which follow the terrain is visualising land zoning restrictions of maximum building height. Source data might have large polygons covering several blocks together, so using a fixed height of extrusion would result in a wrong visualisation.

Confusedfish commented 3 years ago

Thanks for looking into this. My use case is to mark areas of turbulence behind hills in different wind directions. The turbulence isn't flat, nor exactly follows the ground elevation but having the ability to follow the ground elevation would be preferable.

Adding some form of tilt setting would also help immensely as the turbulence tapers off by distance from the top of the hill but I appreciate that is just adding further complexity. My planned approach was to use a series of stepped polygons which would be visually inferior.

searoutefinder commented 3 years ago

Hello all! I am writing in this issue thread to report a behavior in GL JS v2.2 that I think is a bug unless I am missing something. I am working on a project where we deploy flight regulations based on height above mean sea level. I am using grid cells from our system and display them on a GL JS map using a fill-extrusion layer. The problem I am reporting happens only when 3D terrain view is enabled. Eventually I'd like to display the grid on a fixed vertical position relative to the earth and NOT the terrain. After doing some research I found that for the time being I can not do such a thing which is a petty, because without the 3D terrain it's completely possible to do. Do you have any ideas? Is there something I am missing? Thanks a million for all your answers!

2

This is basically what I want to achieve but with 3D terrain enabled. I don't have any issues if some of the tiles intersect or get hidden by the terrain on lower elevations.

3

astojilj commented 3 years ago

@searoutefinder I understand that what I'm about to propose is not convenient, but it might be a viable workaround until we design the property. So, flat roofs are enabled only if the feature has properties:

https://github.com/mapbox/mapbox-gl-js/blob/e9ee222c5ec4670b420c9bfe9a2aa830604177cc/src/data/bucket/fill_extrusion_bucket.js#L305-L306

If the feature has no properties tag, e.g. render test opacity-terrain includes geojson source where features define polygons but have no properties tag, fill extrusion roof would follow terrain slope.

image

In opposite case, e.g. opacity-terrain-flat, features have properties:

{
            "type": "Feature",
            "properties": {
              "type": "building",
              "height": 20
            },
            "geometry": {

and roof is flat:

image

searoutefinder commented 3 years ago

@searoutefinder I understand that what I'm about to propose is not convenient, but it might be a viable workaround until we design the property. So, flat roofs are enabled only if the feature has properties:

https://github.com/mapbox/mapbox-gl-js/blob/e9ee222c5ec4670b420c9bfe9a2aa830604177cc/src/data/bucket/fill_extrusion_bucket.js#L305-L306

If the feature has no properties tag, e.g. render test opacity-terrain includes geojson source where features define polygons but have no properties tag, fill extrusion roof would follow terrain slope.

image

In opposite case, e.g. opacity-terrain-flat, features have properties:

{
            "type": "Feature",
            "properties": {
              "type": "building",
              "height": 20
            },
            "geometry": {

and roof is flat:

image

Hey astojilj,

First of all, let me thank you for your quick response! I fear that I was expressing myself in a wrong way, and therefore my problem didn't come through. So if you take a look at the first screenshot of my original post, you can see that the "roofs" are level. I have no issues with that, and my grid cell polygons do have a properties object literal, which contains a number of attributes on each cell. However, I'd like to have these grid cells to constitute a 3D pane, that I can move up and down by setting the fill-extrusion-base and fill-extrusion-height properties. So imagine a place where only 300m something high hills there are. I'd like to ble able to visualize a grid that can lift up and down based on the elevation I tell it. Let's say 700m. In that case, I expect the grid cells to be flat rectangles placed 700m away from mean sea level vertically. Do you get my point?

Thanks again!

Tamas

runshotgun commented 3 years ago

Can we get this for -floor as well? I'm trying to set the -base of an object and bring it up in the air but the base follows the geometry of the terrain while in the air instead of being flat... That seems to correlate with the issue described above.

2021-06-23_17-21-35

astojilj commented 3 years ago

@searoutefinder @TheMapleSyrupCan

Thank you for clarifying this.

This is the same issue as with custom roof approach, when additional fill extrusion layer is used only for roof (base == height), enabling different paint for roofs, e.g.:

Screen Shot 2021-06-24 at 8 25 33

astojilj commented 3 years ago

I'm happy with the output we got from the thread here. Thanks.

One way to address this would be by adding properties: "fill-extrusion-height-terrain-alignment" and "fill-extrusion-base-terrain-alignment", e.g.:

    "fill-extrusion-base-terrain-alignment": {
      "type": "enum",
      "values": {
        "terrain": {
          "doc": "The fill extrusion base follows terrain slope."
        },
        "flat": {
          "doc": "The fill extrusion base is flat over terrain."
        }
      },
      "doc": "Controls the behavior of fill extrusion base over terrain",
      "default": "terrain",
      "property-type": "data-constant"
    }

@karimnaaji, this would extend previous approach by supporting base, too. WDYT?

markcarroll commented 2 years ago

did this every get resolved? We are hitting this issue too and would like to be able to decide whether the extrusions should be relative to the 3D terrain or flat (i.e. mean sea level).

thibaultclem commented 11 months ago

Hi @astojilj, I think your idea of having "fill-extrusion-height-terrain-alignment" and "fill-extrusion-base-terrain-alignment" would be a good idea. We are stuck on our side when trying to render different floor of a building on terrain:

Screenshot 2023-10-03 at 11 13 22 AM

With a fill-extrusion-base-terrain-alignment equal to flat, this would solve our problem for upper floor.

Do you know if there is any update about it ?

Thanks a lot

Adraesh commented 8 months ago

Hello,

Interesting topic here.

We also would like to be able to decide whether the base and/or ceiling should be relative to the 3D terrain or flat (AMSL or ASFC)

Thanks.

Adraesh commented 8 months ago

Hello!

Any news on this feature?

Thank you!

astojilj commented 7 months ago

Thanks for your patience on this - we were busy with other 3D features! We'll take a look.